diff --git a/l10n_it_fatturapa/README.rst b/l10n_it_fatturapa/README.rst index ede8dbeb5829..a4002cece93e 100644 --- a/l10n_it_fatturapa/README.rst +++ b/l10n_it_fatturapa/README.rst @@ -164,6 +164,7 @@ Contributors * `Ooops `_: * Giovanni Serra + * Eduard Brahas * `Aion Tech `_: diff --git a/l10n_it_fatturapa/__manifest__.py b/l10n_it_fatturapa/__manifest__.py index 891251f361c1..ec72bac46186 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.2", + "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 c622931e391f..5344c5008c8b 100644 --- a/l10n_it_fatturapa/models/partner.py +++ b/l10n_it_fatturapa/models/partner.py @@ -35,6 +35,13 @@ class ResPartner(models.Model): "the standard value ('%s')." % STANDARD_ADDRESSEE_CODE, default=STANDARD_ADDRESSEE_CODE, ) + l10n_it_use_parent_codice_destinatario = fields.Boolean( + string="Use parent Codice Destinatario", + 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 +61,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 +175,33 @@ def _check_ftpa_partner_data(self): % partner.name ) - @api.onchange("country_id") + @api.onchange("country_id", "parent_id", "electronic_invoice_subjected") def onchange_country_id_e_inv(self): - if self.country_id.code == "IT": - self.codice_destinatario = STANDARD_ADDRESSEE_CODE - else: + if self.country_id.code != "IT": self.codice_destinatario = "XXXXXXX" + elif ( + not self.is_company + and not self.electronic_invoice_use_this_address + and self.parent_id.l10n_it_use_parent_codice_destinatario + ): + self.codice_destinatario = ( + self._recursive_parent_codice_destinatario(self.parent_id) + or STANDARD_ADDRESSEE_CODE + ) + else: + self.codice_destinatario = STANDARD_ADDRESSEE_CODE + + def _recursive_parent_codice_destinatario(self, parent): + """ + Recursively finds the codice_destinatario from the first company ancestor + that has it set. Returns None if no codice_destinatario is found. + """ + if parent and parent.is_company: + if 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): diff --git a/l10n_it_fatturapa/readme/CONTRIBUTORS.rst b/l10n_it_fatturapa/readme/CONTRIBUTORS.rst index c8af4792ccc1..283749e8d3ec 100644 --- a/l10n_it_fatturapa/readme/CONTRIBUTORS.rst +++ b/l10n_it_fatturapa/readme/CONTRIBUTORS.rst @@ -9,6 +9,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 944438dcab1b..475cb47c20c2 100644 --- a/l10n_it_fatturapa/static/description/index.html +++ b/l10n_it_fatturapa/static/description/index.html @@ -501,6 +501,7 @@

Contributors

diff --git a/l10n_it_fatturapa/views/partner_view.xml b/l10n_it_fatturapa/views/partner_view.xml index 1a0bd8a10d13..06a631d40404 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)]}" /> +