From 6d74e1ba0b2c3e989ed82df20b3ed8953620ba31 Mon Sep 17 00:00:00 2001 From: Eduard Brahas Date: Tue, 5 Nov 2024 17:07:56 +0100 Subject: [PATCH] [IMP] l10n_it_fatturapa: use parent codice_destinatario Uses the parent codice_destinatario for each child if the parent has set the flag l10n_it_use_parent_codice_destinatario. --- l10n_it_fatturapa/README.rst | 1 + l10n_it_fatturapa/__manifest__.py | 2 +- l10n_it_fatturapa/models/partner.py | 75 ++++++++++++++++--- l10n_it_fatturapa/readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 1 + l10n_it_fatturapa/views/partner_view.xml | 8 +- .../data/invoice_it_template.xml | 12 ++- .../tests/data/CHE114993395IVA_00007.xml | 3 +- .../tests/test_fatturapa_xml_validation.py | 2 +- .../tests/data/IT10538570960_00002.xml | 3 +- .../tests/data/IT10538570960_00003.xml | 3 +- .../tests/data/IT10538570960_00004.xml | 3 +- 12 files changed, 94 insertions(+), 20 deletions(-) diff --git a/l10n_it_fatturapa/README.rst b/l10n_it_fatturapa/README.rst index d4d42ae8e4f..ff9de774695 100644 --- a/l10n_it_fatturapa/README.rst +++ b/l10n_it_fatturapa/README.rst @@ -165,6 +165,7 @@ Contributors * `Ooops `_: * Giovanni Serra + * Eduard Brahas * `Aion Tech `_: diff --git a/l10n_it_fatturapa/__manifest__.py b/l10n_it_fatturapa/__manifest__.py index 571ed156842..ec72bac4618 100644 --- a/l10n_it_fatturapa/__manifest__.py +++ b/l10n_it_fatturapa/__manifest__.py @@ -6,7 +6,7 @@ { "name": "ITA - Fattura elettronica - Base", - "version": "14.0.2.3.4", + "version": "14.0.2.4.2", "category": "Localization/Italy", "summary": "Fatture elettroniche", "author": "Davide Corio, Agile Business Group, Innoviu, " diff --git a/l10n_it_fatturapa/models/partner.py b/l10n_it_fatturapa/models/partner.py index c622931e391..856892be55b 100644 --- a/l10n_it_fatturapa/models/partner.py +++ b/l10n_it_fatturapa/models/partner.py @@ -29,12 +29,22 @@ class ResPartner(models.Model): # 1.1.4 codice_destinatario = fields.Char( "Addressee Code", + compute="_compute_codice_destinatario", + inverse="_inverse_codice_destinatario", + store=True, help="The code, 7 characters long, assigned by ES to subjects with an " "accredited channel; if the addressee didn't accredit a channel " "to ES and invoices are received by PEC, the field must be " "the standard value ('%s')." % STANDARD_ADDRESSEE_CODE, default=STANDARD_ADDRESSEE_CODE, ) + l10n_it_use_parent_codice_destinatario = fields.Boolean( + string="Use addressee code for child contacts", + store=True, + default=False, + help="Instead of using the deafult 0000000 code" + " uses for the childs the one set in the parent", + ) # 1.1.6 pec_destinatario = fields.Char( "Addressee PEC", @@ -54,7 +64,7 @@ class ResPartner(models.Model): ) electronic_invoice_use_this_address = fields.Boolean( - "Use this e-invoicing data when invoicing to this address", + "Use different e-invoicing data when invoicing to this address", help="Set this when the main company has got several Addressee Codes or PEC", ) @@ -168,12 +178,59 @@ def _check_ftpa_partner_data(self): % partner.name ) - @api.onchange("country_id") - def onchange_country_id_e_inv(self): - if self.country_id.code == "IT": - self.codice_destinatario = STANDARD_ADDRESSEE_CODE - else: - self.codice_destinatario = "XXXXXXX" + @api.depends( + "country_id", + "parent_id", + "is_company", + "electronic_invoice_subjected", + "electronic_invoice_obliged_subject", + ) + def _compute_codice_destinatario(self): + for partner in self: + codice_destinatario = None + if ( + not partner.is_company + and not partner.electronic_invoice_use_this_address + and partner.parent_id.l10n_it_use_parent_codice_destinatario + ): + codice_destinatario = self._recursive_parent_codice_destinatario( + partner.parent_id + ) + if codice_destinatario is None: + if partner.country_id.code == "IT": + codice_destinatario = STANDARD_ADDRESSEE_CODE + else: + codice_destinatario = "XXXXXXX" + + partner.codice_destinatario = codice_destinatario + + def _inverse_codice_destinatario(self): + """ + Inverse method to propagate changes in codice_destinatario to child records. + """ + for record in self: + # Find child records that inherit codice_destinatario from this parent + child_records = self.search( + [ + ("parent_id", "=", record.id), + ("l10n_it_use_parent_codice_destinatario", "=", False), + ] + ) + # Update the codice_destinatario of each child record to match the parent + for child in child_records: + child.codice_destinatario = record.codice_destinatario + + def _recursive_parent_codice_destinatario(self, parent): + """ + Recursively finds the codice_destinatario from the first ancestor + that has set the flag l10n_it_use_parent_codice_destinatario. + Returns None if no codice_destinatario is found. + """ + if parent.l10n_it_use_parent_codice_destinatario: + return parent.codice_destinatario + elif parent.parent_id: + return self._recursive_parent_codice_destinatario(parent.parent_id) + return None @api.onchange("electronic_invoice_subjected") def onchange_electronic_invoice_subjected(self): @@ -181,12 +238,12 @@ def onchange_electronic_invoice_subjected(self): self.electronic_invoice_obliged_subject = False else: if self.supplier_rank > 0: - self.onchange_country_id_e_inv() + self._compute_codice_destinatario() self.electronic_invoice_obliged_subject = True @api.onchange("electronic_invoice_obliged_subject") def onchange_e_inv_obliged_subject(self): if not self.electronic_invoice_obliged_subject: - self.onchange_country_id_e_inv() + self._compute_codice_destinatario() self.pec_destinatario = "" self.eori_code = "" diff --git a/l10n_it_fatturapa/readme/CONTRIBUTORS.rst b/l10n_it_fatturapa/readme/CONTRIBUTORS.rst index fe9c46ee8a3..6cba82d6053 100644 --- a/l10n_it_fatturapa/readme/CONTRIBUTORS.rst +++ b/l10n_it_fatturapa/readme/CONTRIBUTORS.rst @@ -10,6 +10,7 @@ * `Ooops `_: * Giovanni Serra + * Eduard Brahas * `Aion Tech `_: diff --git a/l10n_it_fatturapa/static/description/index.html b/l10n_it_fatturapa/static/description/index.html index b2856919331..81bb50df7a5 100644 --- a/l10n_it_fatturapa/static/description/index.html +++ b/l10n_it_fatturapa/static/description/index.html @@ -503,6 +503,7 @@

Contributors

diff --git a/l10n_it_fatturapa/views/partner_view.xml b/l10n_it_fatturapa/views/partner_view.xml index 1a0bd8a10d1..06a631d4040 100644 --- a/l10n_it_fatturapa/views/partner_view.xml +++ b/l10n_it_fatturapa/views/partner_view.xml @@ -32,9 +32,15 @@ placeholder="IPA123" attrs="{'invisible': [('is_pa','=', False)]}" /> + - + + - + diff --git a/l10n_it_fatturapa_out/tests/data/CHE114993395IVA_00007.xml b/l10n_it_fatturapa_out/tests/data/CHE114993395IVA_00007.xml index 8ce0b5cf5fd..2fdde55a871 100644 --- a/l10n_it_fatturapa_out/tests/data/CHE114993395IVA_00007.xml +++ b/l10n_it_fatturapa_out/tests/data/CHE114993395IVA_00007.xml @@ -28,8 +28,9 @@ Via Milano, 1 - 00100 + 00000 Lugano + EE CH diff --git a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py index a75f2debfc6..c046e3ea815 100644 --- a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py +++ b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py @@ -518,7 +518,7 @@ def test_11_xml_export(self): partner.country_id = self.env.ref("base.si").id partner.vat = "SI12345679" partner.fiscalcode = False - partner.onchange_country_id_e_inv() + partner._compute_codice_destinatario() partner.write(partner._convert_to_write(partner._cache)) self.assertEqual(partner.codice_destinatario, "XXXXXXX") invoice = self.invoice_model.create( diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml index de298d1c83b..f8f0472ea5c 100644 --- a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml @@ -30,8 +30,9 @@ Street - 12345 + 00000 city + EE BE diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml index 1d8fe60d7ad..2ef7be49f82 100644 --- a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml @@ -30,8 +30,9 @@ Street - 12345 + 00000 city + EE BE diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml index c93ebed2cd1..b36f0720634 100644 --- a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml @@ -30,8 +30,9 @@ Street - 12345 + 00000 city + EE US