Skip to content

Commit

Permalink
[FIX] l10n_it_edi: use customer country for Nazione field
Browse files Browse the repository at this point in the history
Steps to reproduce:
- Install Accounting, l10n_it_edi and Contacts
- Switch to an Italian company (e.g. IT Company)
- Go to Contacts
- Create an EU contact with "/" or "NA" as VAT
(e.g. a Germnan contact with a full address)
- Create an invoice:
  * Customer: [the created contact]
  * Product: [any]
- Confirm the invoice
- Process the electronic invoice
- Check the generated electronic invoice

Issue:
1) The country of customer is first computed from his VAT number and
a fallback is made on his country.
It should be the opposite.
2) In the XML, the "IdFiscaleIVA" section is set for customer with "/" (or "NA")
as "IdPaese", but it should not because customer doesn't have a VAT number.
If the XML is sent for validation, it is rejected because of that.

Solution:
1) Backport of odoo#164950
2) Add a condition on "IdFiscaleIVA" node as it is done from saas-16.4

opw-3889051

closes odoo#165253

Signed-off-by: Wala Gauthier (gawa) <gawa@odoo.com>
  • Loading branch information
kitan191 committed May 14, 2024
1 parent d33d8c3 commit a34019c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion addons/l10n_it_edi/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</RappresentanteFiscale>
<CessionarioCommittente>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdFiscaleIVA t-if="buyer_info['vat']">
<IdPaese t-out="buyer_info['country_code']"/>
<IdCodice t-out="buyer_info['vat']"/>
</IdFiscaleIVA>
Expand Down
24 changes: 7 additions & 17 deletions addons/l10n_it_edi/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,45 +221,35 @@ def get_vat_values(partner):
If there is no VAT and no Codice Fiscale, the invoice is not even exported, so this case is not handled.
Country:
First, try and deduct the country from the VAT number.
If not, take the country directly from the partner.
If there's a codice fiscale, the country is 'IT'.
First, take the country configured on the partner.
If there's a codice fiscale and no country, the country is 'IT'.
"""
europe = self.env.ref('base.europe', raise_if_not_found=False)
in_eu = europe and partner.country_id and partner.country_id in europe.country_ids
is_sm = partner.country_code == 'SM'

normalized_vat = partner.vat
normalized_country = False
normalized_country = partner.country_code
if partner.vat:
normalized_vat = partner.vat.replace(' ', '')
if in_eu:
# If there is no country-code prefix, it's domestic to Italy
if normalized_vat[:2].isdecimal():
normalized_country = 'IT'
# If the partner is from the EU, the country-code prefix of the VAT must be taken away
else:
normalized_country = normalized_vat[:2].upper()
if not normalized_vat[:2].isdecimal():
normalized_vat = normalized_vat[2:]
# If customer is from San Marino
elif is_sm:
normalized_country = 'SM'
normalized_vat = normalized_vat if normalized_vat[:2].isdecimal() else normalized_vat[2:]
# The Tax Agency arbitrarily decided that non-EU VAT are not interesting,
# so this default code is used instead
# Detect the country code from the partner country instead
else:
normalized_vat = 'OO99999999999'

if not normalized_country:
if partner.country_id:
normalized_country = partner.country_id.code
# If it has a codice fiscale (and no country), it's an Italian partner
elif partner.l10n_it_codice_fiscale:
normalized_country = 'IT'
# If it has a codice fiscale (and no country), it's an Italian partner
if not normalized_country and partner.l10n_it_codice_fiscale:
normalized_country = 'IT'
elif not partner.vat and partner.country_id and partner.country_id.code != 'IT':
normalized_vat = '0000000'
normalized_country = partner.country_id.code

return {
'vat': normalized_vat,
Expand Down

0 comments on commit a34019c

Please sign in to comment.