From 6afbfb831b88705fd9e30b83dc0f1d1c306732a9 Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Fri, 5 Apr 2024 11:02:06 +0200 Subject: [PATCH] [16.0][FIX] l10n_it_fatturapa_out: invoices for San Marino --- .../tests/data/IT06363391001_00018.xml | 107 ++++++++++++++++++ .../tests/test_fatturapa_xml_validation.py | 86 ++++++++++++++ l10n_it_fatturapa_out/wizard/efattura.py | 4 +- 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 l10n_it_fatturapa_out/tests/data/IT06363391001_00018.xml diff --git a/l10n_it_fatturapa_out/tests/data/IT06363391001_00018.xml b/l10n_it_fatturapa_out/tests/data/IT06363391001_00018.xml new file mode 100644 index 00000000000..dc0baed7ebb --- /dev/null +++ b/l10n_it_fatturapa_out/tests/data/IT06363391001_00018.xml @@ -0,0 +1,107 @@ + + + + + + IT + 06363391001 + + 00018 + FPR12 + 2R4GTO8 + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 06363391001 + + + YourCompany + + RF01 + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + 06543534343 + info@yourcompany.example.com + + F000000111 + + + + + SM + 00123 + + + Azienda Sanmarinese + + + + Piazza della Libertà + 47890 + Città di San Marino + SM + + + + + + + TD01 + EUR + 2016-01-07 + INV/2016/0013 + 14.00 + SI + + + + + 1 + Mouse Optical + 1.000 + Unit(s) + 10.00000 + 10.00 + 0.00 + N3.3 + + + 2 + Zed+ Antivirus + 1.000 + Unit(s) + 4.00000 + 4.00 + 0.00 + N3.3 + + + 0.00 + N3.3 + 14.00 + 0.00 + + + + TP02 + + MP05 + 2016-02-29 + 14.00 + + + + diff --git a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py index 00acfcde24a..66addab8a20 100644 --- a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py +++ b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py @@ -1027,3 +1027,89 @@ def test_validate_invoice(self): invoice.action_post() self.assertEqual(invoice.state, "posted") + + def test_18_xml_export(self): + vals = { + "name": "Azienda Sanmarinese", + "is_company": "1", + "street": "Piazza della Libertà", + "is_pa": False, + "city": "Città di San Marino", + "zip": "47890", + "country_id": self.env.ref("base.sm").id, + "email": "asm@example.com", + "vat": "SM00123", + "codice_destinatario": "2R4GTO8", + } + partner_sm = self.env["res.partner"].create(vals) + + tax_kind = self.env["account.tax.kind"].search([("code", "=", "N3.3")], limit=1) + self.assertTrue(tax_kind) + + vals = { + "name": "0% SM", + "amount": 0.0, + "amount_type": "percent", + "description": "Non Imponibile Art. 71", + "kind_id": tax_kind.id, + } + tax_id = self.env["account.tax"].create(vals) + + self.env.company.fatturapa_pub_administration_ref = "F000000111" + invoice = self.invoice_model.create( + { + "name": "INV/2016/0013", + "company_id": self.env.company.id, + "invoice_date": "2016-01-07", + "partner_id": partner_sm.id, + "journal_id": self.sales_journal.id, + # "account_id": self.a_recv.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\nOptical", + "quantity": 1, + "product_uom_id": self.product_uom_unit.id, + "price_unit": 10, + "tax_ids": [(6, 0, [tax_id.id])], + }, + ), + ( + 0, + 0, + { + "account_id": self.a_sale.id, + "product_id": self.product_order_01.id, + "name": "Zed+ Antivirus", + "quantity": 1, + "product_uom_id": self.product_uom_unit.id, + "price_unit": 4, + "tax_ids": [(6, 0, [tax_id.id])], + }, + ), + ], + } + ) + invoice._post() + self.assertFalse(self.attach_model.file_name_exists("00001")) + res = self.run_wizard(invoice.id) + + self.assertTrue(res) + attachment = self.attach_model.browse(res["res_id"]) + file_name_match = "^%s_[A-Za-z0-9]{5}.xml$" % self.env.company.vat + # Checking file name randomly generated + self.assertTrue(re.search(file_name_match, attachment.name)) + self.set_e_invoice_file_id(attachment, "IT06363391001_00018.xml") + self.assertTrue(self.attach_model.file_name_exists("00018")) + + # XML doc to be validated + xml_content = base64.decodebytes(attachment.datas) + self.check_content(xml_content, "IT06363391001_00018.xml") diff --git a/l10n_it_fatturapa_out/wizard/efattura.py b/l10n_it_fatturapa_out/wizard/efattura.py index a891db5f7e1..0abd44769cd 100644 --- a/l10n_it_fatturapa_out/wizard/efattura.py +++ b/l10n_it_fatturapa_out/wizard/efattura.py @@ -119,7 +119,9 @@ 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"): + if (id_paese == "IT" and partner.vat.startswith("IT")) or ( + id_paese == "SM" and partner.vat.startswith("SM") + ): id_codice = partner.vat[2:] else: id_codice = partner.vat