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][FIX] l10n_it_fatturapa_out: use parent codice_destinatario #4595

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 @@ -165,6 +165,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.4",
"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 @@
# 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 @@
)

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 @@
% 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(

Check warning on line 196 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L196

Added line #L196 was not covered by tests
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

Check warning on line 221 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L221

Added line #L221 was not covered by tests

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

Check warning on line 230 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L230

Added line #L230 was not covered by tests
elif parent.parent_id:
return self._recursive_parent_codice_destinatario(parent.parent_id)
return None

Check warning on line 233 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L232-L233

Added lines #L232 - L233 were not covered by tests

@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()

Check warning on line 241 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L241

Added line #L241 was not covered by tests
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()

Check warning on line 247 in l10n_it_fatturapa/models/partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L247

Added line #L247 was not covered by tests
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 @@ -10,6 +10,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 @@ -503,6 +503,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
12 changes: 8 additions & 4 deletions l10n_it_fatturapa_out/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,26 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
<Indirizzo t-esc="encode_for_export(indirizzo, 60)" />
<!-- <NumeroCivico t-esc=""/>-->
<!-- XXX da controllare, if vecchio codice fa diversamente
<CAP><t t-if="partner_id.country_id.code == 'IT'" t-esc="partner_id.zip" /><t t-if="partner_id.country_id.code != 'IT'" t-esc="'00000'" /></CAP>
<CAP><t t-if="partner_id.country_id.code == 'IT'"
t-esc="partner_id.zip" />
<t t-if="partner_id.country_id.code != 'IT'" t-esc="'00000'" /></CAP>
-->
<CAP
<CAP
t-if="partner_id.codice_destinatario == 'XXXXXXX' or not partner_id.zip"
t-esc="'00000'"
/>
<CAP
t-if="partner_id.codice_destinatario != 'XXXXXXX' and partner_id.zip"
t-elif="partner_id.codice_destinatario != 'XXXXXXX' and partner_id.zip"
t-esc="partner_id.zip"
/>


<Comune t-esc="encode_for_export(partner_id.city, 60)" />
<Provincia
t-if="partner_id.country_id.code == 'IT'"
t-esc="partner_id.state_id.code"
/>
<Provincia t-if="partner_id.codice_destinatario == 'XXXXXXX'" t-esc="'EE'" />
<Provincia t-elif="partner_id.codice_destinatario == 'XXXXXXX'" t-esc="'EE'" />
<Nazione t-esc="partner_id.country_id.code" />
</t>
</template>
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_out/tests/data/CHE114993395IVA_00007.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
</DatiAnagrafici>
<Sede>
<Indirizzo>Via Milano, 1</Indirizzo>
<CAP>00100</CAP>
<CAP>00000</CAP>
<Comune>Lugano</Comune>
<Provincia>EE</Provincia>
<Nazione>CH</Nazione>
</Sede>
<StabileOrganizzazione>
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
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
</DatiAnagrafici>
<Sede>
<Indirizzo>Street</Indirizzo>
<CAP>12345</CAP>
<CAP>00000</CAP>
<Comune>city</Comune>
<Provincia>EE</Provincia>
<Nazione>BE</Nazione>
</Sede>
</CedentePrestatore>
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
</DatiAnagrafici>
<Sede>
<Indirizzo>Street</Indirizzo>
<CAP>12345</CAP>
<CAP>00000</CAP>
<Comune>city</Comune>
<Provincia>EE</Provincia>
<Nazione>BE</Nazione>
</Sede>
</CedentePrestatore>
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
</DatiAnagrafici>
<Sede>
<Indirizzo>Street</Indirizzo>
<CAP>12345</CAP>
<CAP>00000</CAP>
<Comune>city</Comune>
<Provincia>EE</Provincia>
<Nazione>US</Nazione>
</Sede>
</CedentePrestatore>
Expand Down