|
8 | 8 | import re
|
9 | 9 | from unittest.mock import Mock
|
10 | 10 |
|
| 11 | +from lxml import etree |
11 | 12 | from psycopg2 import IntegrityError
|
12 | 13 |
|
13 | 14 | import odoo
|
@@ -1237,3 +1238,69 @@ def test_max_invoice_number_company(self):
|
1237 | 1238 | # Check that two attachments are created
|
1238 | 1239 | attachments_nbr = len(invoices.mapped("fatturapa_attachment_out_id"))
|
1239 | 1240 | self.assertEqual(attachments_nbr, 2)
|
| 1241 | + |
| 1242 | + def test_foreign_customer_with_italian_piva_xml_export(self): |
| 1243 | + # creo un'azienda estera con sede in una nazione straniera, |
| 1244 | + # ma partita iva italiana |
| 1245 | + vals = { |
| 1246 | + "name": "Azienda Estera", |
| 1247 | + "is_company": "1", |
| 1248 | + "street": "Mžaja ŠtraÇÃ 14", |
| 1249 | + "is_pa": False, |
| 1250 | + "city": "Šofıa", |
| 1251 | + "zip": "49715", |
| 1252 | + "country_id": self.env.ref("base.si").id, |
| 1253 | + "vat": "IT03297040366", |
| 1254 | + } |
| 1255 | + partner = self.env["res.partner"].create(vals) |
| 1256 | + invoice = self.invoice_model.create( |
| 1257 | + { |
| 1258 | + "name": "INV/2024/0014", |
| 1259 | + "invoice_date": "2024-01-07", |
| 1260 | + "partner_id": partner.id, |
| 1261 | + "journal_id": self.sales_journal.id, |
| 1262 | + "invoice_payment_term_id": self.account_payment_term.id, |
| 1263 | + "user_id": self.user_demo.id, |
| 1264 | + "move_type": "out_invoice", |
| 1265 | + "currency_id": self.EUR.id, |
| 1266 | + "invoice_line_ids": [ |
| 1267 | + ( |
| 1268 | + 0, |
| 1269 | + 0, |
| 1270 | + { |
| 1271 | + "account_id": self.a_sale.id, |
| 1272 | + "product_id": self.product_product_10.id, |
| 1273 | + "name": "Mouse Optical", |
| 1274 | + "quantity": 1, |
| 1275 | + "product_uom_id": self.product_uom_unit.id, |
| 1276 | + "price_unit": 10, |
| 1277 | + "tax_ids": [(6, 0, {self.tax_22.id})], |
| 1278 | + }, |
| 1279 | + ), |
| 1280 | + ], |
| 1281 | + } |
| 1282 | + ) |
| 1283 | + invoice._post() |
| 1284 | + res = self.run_wizard(invoice.id) |
| 1285 | + self.assertTrue(res) |
| 1286 | + |
| 1287 | + attachment = self.attach_model.browse(res["res_id"]) |
| 1288 | + xml_content = base64.decodebytes(attachment.datas) |
| 1289 | + |
| 1290 | + parser = etree.XMLParser(remove_blank_text=True) |
| 1291 | + xml = etree.fromstring(xml_content, parser) |
| 1292 | + cessionario_committente_idiva = xml.findall( |
| 1293 | + ".//CessionarioCommittente/DatiAnagrafici/IdFiscaleIVA" |
| 1294 | + ) |
| 1295 | + # verifica che ci sia solo un tag |
| 1296 | + # CessionarioCommittente/DatiAnagrafici/IdFiscaleIVA |
| 1297 | + self.assertEqual(len(cessionario_committente_idiva), 1) |
| 1298 | + # verifica che ci siano sia IdPaese che IdCodice |
| 1299 | + self.assertEqual(len(cessionario_committente_idiva[0]), 2) |
| 1300 | + # verifica che ci siano sia IdPaese sia IT e non sia stato aggiunto il codice |
| 1301 | + # nazione come prima del commit: |
| 1302 | + # [FIX] l10n_it_fatturapa_out: avoid to add country code to PIVA for foreign |
| 1303 | + # customers with italian PIVA |
| 1304 | + self.assertEqual(cessionario_committente_idiva[0][0].text, "IT") |
| 1305 | + # verifica che ci siano sia IdPaese sia corretto |
| 1306 | + self.assertEqual(cessionario_committente_idiva[0][1].text, "03297040366") |
0 commit comments