Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] l10n_it_fatturapa_out: use parent codice_destinatario if not set in partner #4436

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l10n_it_fatturapa/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Contributors
* `Ooops <https://www.ooops404.com>`_:

* Giovanni Serra <[email protected]>
* Eduard Brahas <[email protected]>

* `Aion Tech <https://aiontech.company/>`_:

Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
75 changes: 66 additions & 9 deletions l10n_it_fatturapa/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)

Expand Down Expand Up @@ -168,25 +178,72 @@ 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):
if not self.electronic_invoice_subjected:
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 = ""
1 change: 1 addition & 0 deletions l10n_it_fatturapa/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* `Ooops <https://www.ooops404.com>`_:

* Giovanni Serra <[email protected]>
* Eduard Brahas <[email protected]>

* `Aion Tech <https://aiontech.company/>`_:

Expand Down
1 change: 1 addition & 0 deletions l10n_it_fatturapa/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<blockquote>
<ul class="simple">
<li>Giovanni Serra &lt;<a class="reference external" href="mailto:giovanni&#64;gslab.it">giovanni&#64;gslab.it</a>&gt;</li>
<li>Eduard Brahas &lt;<a class="reference external" href="mailto:eduard&#64;ooops404.com">eduard&#64;ooops404.com</a>&gt;</li>
</ul>
</blockquote>
</li>
Expand Down
8 changes: 7 additions & 1 deletion l10n_it_fatturapa/views/partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
placeholder="IPA123"
attrs="{'invisible': [('is_pa','=', False)]}"
/>
<field
name="l10n_it_use_parent_codice_destinatario"
attrs="{'invisible': [('is_company', '=', False)]}"
/>
<field
name="codice_destinatario"
attrs="{'invisible': [('is_pa', '=', True)]}"
attrs="{'invisible': [('is_pa', '=', True)],
'readonly': [('l10n_it_use_parent_codice_destinatario', '=', False), ('is_company', '=', False)]
}"
/>
<field
name="pec_destinatario"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading