From d589651c116f876380d75d55294914ff2123ab3c 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_out: use parent codice_destinatario Uses the parent codice_destinatario if the partner has set the flag use_parent_codice_destinatario to do so. --- l10n_it_fatturapa_out/models/partner.py | 21 ++++++++++++++++++++ l10n_it_fatturapa_out/views/partner_view.xml | 10 ++++++++++ l10n_it_fatturapa_out/wizard/efattura.py | 8 +++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/l10n_it_fatturapa_out/models/partner.py b/l10n_it_fatturapa_out/models/partner.py index 804b3eedb3c2..762e01a639a6 100644 --- a/l10n_it_fatturapa_out/models/partner.py +++ b/l10n_it_fatturapa_out/models/partner.py @@ -13,6 +13,27 @@ class ResPartner(models.Model): default=lambda self: self.env.company.max_invoice_in_xml, help="Maximum number of invoices to group in a single " "XML file. 0=Unlimited", ) + use_parent_codice_destinatario = fields.Boolean( + string="Use parent Codice Destinatario", + compute="_compute_use_parent_codice_destinatario", + inverse="_inverse_use_parent_codice_destinatario", + store=True, + help="Instead of using the deafult 0000000 code uses the one set in the parent", + ) + + @api.depends("electronic_invoice_use_this_address") + def _compute_use_parent_codice_destinatario(self): + for record in self: + if record.electronic_invoice_use_this_address: + record.use_parent_codice_destinatario = False + + def _inverse_use_parent_codice_destinatario(self): + for record in self: + if ( + record.electronic_invoice_use_this_address + and record.use_parent_codice_destinatario + ): + record.use_parent_codice_destinatario = False @api.constrains("max_invoice_in_xml") def _validate_max_invoice_in_xml(self): diff --git a/l10n_it_fatturapa_out/views/partner_view.xml b/l10n_it_fatturapa_out/views/partner_view.xml index faab8e14dfdf..abe1d3b506c8 100644 --- a/l10n_it_fatturapa_out/views/partner_view.xml +++ b/l10n_it_fatturapa_out/views/partner_view.xml @@ -9,6 +9,16 @@ + + + + diff --git a/l10n_it_fatturapa_out/wizard/efattura.py b/l10n_it_fatturapa_out/wizard/efattura.py index 7da0768df501..f00dcf92d7ba 100644 --- a/l10n_it_fatturapa_out/wizard/efattura.py +++ b/l10n_it_fatturapa_out/wizard/efattura.py @@ -206,7 +206,13 @@ def fpa_to_eur(amount, invoice): # check value code code = self.partner_id.ipa_code else: - code = self.partner_id.codice_destinatario + if ( + self.partner_id.use_parent_codice_destinatario + and not self.partner_id.is_company + ): + code = self.partner_id.parent_id.codice_destinatario + else: + code = self.partner_id.codice_destinatario # Create file content. template_values = {