Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa: use parent codice_destinatario
Browse files Browse the repository at this point in the history
Uses the parent codice_destinatario for each child
if the parent has set the flag l10n_it_use_parent_codice_destinatario.
  • Loading branch information
toita86 committed Nov 11, 2024
1 parent 54a3979 commit ab218ad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
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
38 changes: 33 additions & 5 deletions l10n_it_fatturapa/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)

Expand Down Expand Up @@ -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 = (

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L187

Added line #L187 was not covered by tests
self._recursive_parent_codice_destinatario(self.parent_id)
or STANDARD_ADDRESSEE_CODE
)
else:
self.codice_destinatario = STANDARD_ADDRESSEE_CODE

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L192

Added line #L192 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L201

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

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa/models/partner.py#L203-L204

Added lines #L203 - L204 were not covered by tests

@api.onchange("electronic_invoice_subjected")
def onchange_electronic_invoice_subjected(self):
Expand Down
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

0 comments on commit ab218ad

Please sign in to comment.