Skip to content

Commit

Permalink
[FIX] l10n_es_aeat_mod347: fix added for partner_record's states
Browse files Browse the repository at this point in the history
  • Loading branch information
ACheung-FactorLibre committed Jan 12, 2024
1 parent 74025f8 commit 570bcd7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 6 deletions.
3 changes: 2 additions & 1 deletion l10n_es_aeat_mod347/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AEAT modelo 347
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:81228fbd32728122f983b70f103aeec75e916fa931d483ea00e63f9b28353f36
!! source digest: sha256:4c3142bf94e5da0cd42ce6af1893ee5bc013612bae8f96a39ca1dab9aa7db393
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -198,6 +198,7 @@ Contributors
* `Sygel <https://www.sygel.es>`_:

* Manuel Regidor
* Alejandro Ji Cheung (https://factorlibre.com)

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions l10n_es_aeat_mod347/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
from . import wizard
from . import models
1 change: 1 addition & 0 deletions l10n_es_aeat_mod347/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Copyright 2016 Tecnativa - Angel Moya <[email protected]>
# Copyright 2018 PESOL - Angel Moya <[email protected]>
# Copyright 2014-2022 Tecnativa - Pedro M. Baeza
# Copyright 2023 FactorLibre - Alejandro Ji Cheung
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
Expand Down
12 changes: 8 additions & 4 deletions l10n_es_aeat_mod347/models/mod347.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Copyright 2018 PESOL - Angel Moya <[email protected]>
# Copyright 2019 Tecnativa - Carlos Dauden
# Copyright 2014-2022 Tecnativa - Pedro M. Baeza
# Copyright 2023 FactorLibre - Alejandro Ji Cheung
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import datetime
Expand Down Expand Up @@ -175,7 +176,7 @@ def button_confirm(self):

def button_send_mails(self):
self.partner_record_ids.filtered(
lambda x: x.state == "pending"
lambda x: x.state == "pending" and x.partner_id.email
).send_email_direct()

def btn_list_records(self):
Expand Down Expand Up @@ -585,7 +586,6 @@ def action_confirm(self):
self.write({"state": "confirmed"})

def action_send(self):
self.write({"state": "sent"})
self.ensure_one()
template = self.env.ref("l10n_es_aeat_mod347.email_template_347")
compose_form = self.env.ref("mail.email_compose_message_wizard_form")
Expand Down Expand Up @@ -625,9 +625,13 @@ def button_recompute(self):

def send_email_direct(self):
template = self.env.ref("l10n_es_aeat_mod347.email_template_347")
sent_records = self.env["l10n.es.aeat.mod347.partner_record"]
for record in self:
template.send_mail(record.id)
self.write({"state": "sent"})
mail_id = template.send_mail(record.id)
if mail_id:
sent_records |= record
if sent_records:
sent_records.write({"state": "sent"})

def action_pending(self):
self.write({"state": "pending"})
Expand Down
1 change: 1 addition & 0 deletions l10n_es_aeat_mod347/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
* `Sygel <https://www.sygel.es>`_:

* Manuel Regidor
* Alejandro Ji Cheung (https://factorlibre.com)
3 changes: 2 additions & 1 deletion l10n_es_aeat_mod347/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h1 class="title">AEAT modelo 347</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:81228fbd32728122f983b70f103aeec75e916fa931d483ea00e63f9b28353f36
!! source digest: sha256:4c3142bf94e5da0cd42ce6af1893ee5bc013612bae8f96a39ca1dab9aa7db393
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-spain/tree/16.0/l10n_es_aeat_mod347"><img alt="OCA/l10n-spain" src="https://img.shields.io/badge/github-OCA%2Fl10n--spain-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-spain-16-0/l10n-spain-16-0-l10n_es_aeat_mod347"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-spain&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>(Declaración Anual de Operaciones con Terceros)
Expand Down Expand Up @@ -544,6 +544,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
</li>
<li><a class="reference external" href="https://www.sygel.es">Sygel</a>:<ul>
<li>Manuel Regidor</li>
<li>Alejandro Ji Cheung (<a class="reference external" href="https://factorlibre.com">https://factorlibre.com</a>)</li>
</ul>
</li>
</ul>
Expand Down
21 changes: 21 additions & 0 deletions l10n_es_aeat_mod347/tests/test_l10n_es_aeat_mod347.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,24 @@ def test_model_347(self):
for xml_id in export_config_xml_ids:
export_config = self.env.ref(xml_id)
self.assertTrue(export_to_boe._export_config(self.model347, export_config))

def test_partner_record_ids_states(self):
self.model347.button_calculate()
first_partner_mod347_record = self.model347.partner_record_ids[0]
first_partner = first_partner_mod347_record.partner_id
self.assertFalse(first_partner.email)

second_partner_mod347_record = self.model347.partner_record_ids[1]
second_partner = second_partner_mod347_record.partner_id
second_partner.email = "[email protected]"

self.model347.button_send_mails()
self.assertTrue(first_partner_mod347_record.state, "pending")
self.assertTrue(second_partner_mod347_record.state, "sent")

first_partner_mod347_record.action_send()
self.assertTrue(first_partner_mod347_record.state, "pending")

first_partner.email = "[email protected]"
first_partner_mod347_record.action_send()
self.assertTrue(first_partner_mod347_record.state, "sent")
4 changes: 4 additions & 0 deletions l10n_es_aeat_mod347/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 FactorLibre - Alejandro Ji Cheung
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import mail_compose_message
18 changes: 18 additions & 0 deletions l10n_es_aeat_mod347/wizard/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 FactorLibre - Alejandro Ji Cheung
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


class MailComposer(models.TransientModel):
_inherit = "mail.compose.message"

def _action_send_mail(self, auto_commit=False):
res = super()._action_send_mail(auto_commit=auto_commit)
default_model = self._context.get("default_model", False)
if default_model == "l10n.es.aeat.mod347.partner_record":
result_message = res[1]
active_id = self._context.get("active_id")
record = self.env["l10n.es.aeat.mod347.partner_record"].browse(active_id)

Check warning on line 15 in l10n_es_aeat_mod347/wizard/mail_compose_message.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod347/wizard/mail_compose_message.py#L13-L15

Added lines #L13 - L15 were not covered by tests
if result_message.mail_ids:
record.write({"state": "sent"})

Check warning on line 17 in l10n_es_aeat_mod347/wizard/mail_compose_message.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod347/wizard/mail_compose_message.py#L17

Added line #L17 was not covered by tests
return res

0 comments on commit 570bcd7

Please sign in to comment.