diff --git a/addons/l10n_it_edi/data/invoice_it_template.xml b/addons/l10n_it_edi/data/invoice_it_template.xml index 2a9de509497cd..b9f2820568b54 100644 --- a/addons/l10n_it_edi/data/invoice_it_template.xml +++ b/addons/l10n_it_edi/data/invoice_it_template.xml @@ -99,7 +99,7 @@ - + diff --git a/addons/l10n_it_edi/models/account_invoice.py b/addons/l10n_it_edi/models/account_invoice.py index 5df5600ed4f51..f600ee334c4f3 100644 --- a/addons/l10n_it_edi/models/account_invoice.py +++ b/addons/l10n_it_edi/models/account_invoice.py @@ -221,29 +221,23 @@ 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 @@ -251,15 +245,11 @@ def get_vat_values(partner): 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,