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

[FIX] l10n_it_fatturapa_out: avoid to add country code to PIVA for foreign customers with italian PIVA #4470

Open
wants to merge 1 commit into
base: 16.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
67 changes: 67 additions & 0 deletions l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
from unittest.mock import Mock

from lxml import etree
from psycopg2 import IntegrityError

import odoo
Expand Down Expand Up @@ -1237,3 +1238,69 @@ def test_max_invoice_number_company(self):
# Check that two attachments are created
attachments_nbr = len(invoices.mapped("fatturapa_attachment_out_id"))
self.assertEqual(attachments_nbr, 2)

def test_foreign_customer_with_italian_piva_xml_export(self):
# creo un'azienda estera con sede in una nazione straniera,
# ma partita iva italiana
vals = {
"name": "Azienda Estera",
"is_company": "1",
"street": "Mžaja ŠtraÇÃ 14",
"is_pa": False,
"city": "Šofıa",
"zip": "49715",
"country_id": self.env.ref("base.si").id,
"vat": "IT03297040366",
}
partner = self.env["res.partner"].create(vals)
invoice = self.invoice_model.create(
{
"name": "INV/2024/0014",
"invoice_date": "2024-01-07",
"partner_id": partner.id,
"journal_id": self.sales_journal.id,
"invoice_payment_term_id": self.account_payment_term.id,
"user_id": self.user_demo.id,
"move_type": "out_invoice",
"currency_id": self.EUR.id,
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.a_sale.id,
"product_id": self.product_product_10.id,
"name": "Mouse Optical",
"quantity": 1,
"product_uom_id": self.product_uom_unit.id,
"price_unit": 10,
"tax_ids": [(6, 0, {self.tax_22.id})],
},
),
],
}
)
invoice._post()
res = self.run_wizard(invoice.id)
self.assertTrue(res)

attachment = self.attach_model.browse(res["res_id"])
xml_content = base64.decodebytes(attachment.datas)

parser = etree.XMLParser(remove_blank_text=True)
xml = etree.fromstring(xml_content, parser)
cessionario_committente_idiva = xml.findall(
".//CessionarioCommittente/DatiAnagrafici/IdFiscaleIVA"
)
# verifica che ci sia solo un tag
# CessionarioCommittente/DatiAnagrafici/IdFiscaleIVA
self.assertEqual(len(cessionario_committente_idiva), 1)
# verifica che ci siano sia IdPaese che IdCodice
self.assertEqual(len(cessionario_committente_idiva[0]), 2)
# verifica che ci siano sia IdPaese sia IT e non sia stato aggiunto il codice
# nazione come prima del commit:
# [FIX] l10n_it_fatturapa_out: avoid to add country code to PIVA for foreign
# customers with italian PIVA
self.assertEqual(cessionario_committente_idiva[0][0].text, "IT")
# verifica che ci siano sia IdPaese sia corretto
self.assertEqual(cessionario_committente_idiva[0][1].text, "03297040366")
8 changes: 6 additions & 2 deletions l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ def format_quantity(line):
def get_id_fiscale_iva(partner, prefer_fiscalcode=False):
id_paese = partner.country_id.code
if partner.vat:
if (id_paese == "IT" and partner.vat.startswith("IT")) or (
id_paese == "SM" and partner.vat.startswith("SM")
id_paese_from_vat = partner.vat[:2]
if (id_paese == "IT" and id_paese_from_vat == "IT") or (
id_paese == "SM" and id_paese_from_vat == "SM"
):
id_codice = partner.vat[2:]
elif id_paese_from_vat.isalpha() and id_paese != id_paese_from_vat:
id_codice = partner.vat[2:]
id_paese = partner.vat[:2]
else:
id_codice = partner.vat
elif partner.fiscalcode or id_paese == "IT":
Expand Down
Loading