diff --git a/l10n_it_fatturapa_out_triple_discount/__manifest__.py b/l10n_it_fatturapa_out_triple_discount/__manifest__.py
index f3fdda82ccc6..29a681bba2fd 100644
--- a/l10n_it_fatturapa_out_triple_discount/__manifest__.py
+++ b/l10n_it_fatturapa_out_triple_discount/__manifest__.py
@@ -1,14 +1,15 @@
# Copyright 2019 Simone Rubino - Agile Business Group
+# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "ITA - Fattura elettronica - Integrazione sconto triplo",
"summary": "Modulo ponte tra emissione " "fatture elettroniche e sconto triplo",
- "version": "12.0.2.0.1",
+ "version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Hidden",
"website": "https://github.com/OCA/l10n-italy"
- "/tree/12.0/l10n_it_fatturapa_out_triple_discount",
+ "/tree/16.0/l10n_it_fatturapa_out_triple_discount",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "AGPL-3",
"auto_install": True,
@@ -16,4 +17,7 @@
"l10n_it_fatturapa_out",
"account_invoice_triple_discount",
],
+ "data": [
+ "data/invoice_it_template.xml",
+ ],
}
diff --git a/l10n_it_fatturapa_out_triple_discount/data/invoice_it_template.xml b/l10n_it_fatturapa_out_triple_discount/data/invoice_it_template.xml
new file mode 100644
index 000000000000..0208510218c9
--- /dev/null
+++ b/l10n_it_fatturapa_out_triple_discount/data/invoice_it_template.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/l10n_it_fatturapa_out_triple_discount/tests/__init__.py b/l10n_it_fatturapa_out_triple_discount/tests/__init__.py
index b94706388956..9b21821eb8ee 100644
--- a/l10n_it_fatturapa_out_triple_discount/tests/__init__.py
+++ b/l10n_it_fatturapa_out_triple_discount/tests/__init__.py
@@ -1,6 +1,3 @@
-# Copyright 2019 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-# tests disabled because unstable
-# TODO https://github.com/OCA/l10n-italy/issues/1588
-# from . import test_fatturapa_triple_discount
+from . import test_fatturapa_triple_discount
diff --git a/l10n_it_fatturapa_out_triple_discount/tests/data/IT06363391001_00001.xml b/l10n_it_fatturapa_out_triple_discount/tests/data/IT06363391001_00001.xml
index f8c8ead0c09f..c87616712c12 100644
--- a/l10n_it_fatturapa_out_triple_discount/tests/data/IT06363391001_00001.xml
+++ b/l10n_it_fatturapa_out_triple_discount/tests/data/IT06363391001_00001.xml
@@ -66,7 +66,7 @@
TD01
EUR
2016-01-07
- INV/2016/0013
+ INV/2016/00001
1.53
SI
diff --git a/l10n_it_fatturapa_out_triple_discount/tests/fatturapa_common.py b/l10n_it_fatturapa_out_triple_discount/tests/fatturapa_common.py
new file mode 100644
index 000000000000..f29fa63acb2e
--- /dev/null
+++ b/l10n_it_fatturapa_out_triple_discount/tests/fatturapa_common.py
@@ -0,0 +1,39 @@
+# Copyright 2023 Simone Rubino - Aion Tech
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+
+from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon
+
+
+class Common(FatturaPACommon):
+ def setUp(self):
+ super().setUp()
+
+ # XXX - a company named "YourCompany" alread exists
+ # we move it out of the way but we should do better here
+ self.env.company.sudo().search([("name", "=", "YourCompany")]).write(
+ {"name": "YourCompany_"}
+ )
+
+ self.env.company.name = "YourCompany"
+ self.env.company.vat = "IT06363391001"
+ self.env.company.fatturapa_art73 = True
+ self.env.company.partner_id.street = "Via Milano, 1"
+ self.env.company.partner_id.city = "Roma"
+ self.env.company.partner_id.state_id = self.env.ref("base.state_us_2").id
+ self.env.company.partner_id.zip = "00100"
+ self.env.company.partner_id.phone = "06543534343"
+ self.env.company.email = "info@yourcompany.example.com"
+ self.env.company.partner_id.country_id = self.env.ref("base.it").id
+ self.env.company.fatturapa_fiscal_position_id = self.env.ref(
+ "l10n_it_fatturapa.fatturapa_RF01"
+ ).id
+
+ self.env["decimal.precision"].search(
+ [("name", "=", "Product Unit of Measure")]
+ ).digits = 3
+ self.env["uom.uom"].search([("name", "=", "Units")]).name = "Unit(s)"
+
+ def getFile(self, filename, module_name=None):
+ if module_name is None:
+ module_name = "l10n_it_fatturapa_out_triple_discount"
+ return super().getFile(filename, module_name=module_name)
diff --git a/l10n_it_fatturapa_out_triple_discount/tests/test_fatturapa_triple_discount.py b/l10n_it_fatturapa_out_triple_discount/tests/test_fatturapa_triple_discount.py
index fa981de83676..8680393791be 100644
--- a/l10n_it_fatturapa_out_triple_discount/tests/test_fatturapa_triple_discount.py
+++ b/l10n_it_fatturapa_out_triple_discount/tests/test_fatturapa_triple_discount.py
@@ -1,48 +1,37 @@
# Copyright 2019 Simone Rubino - Agile Business Group
+# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-import codecs
+import base64
-from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon
+from odoo.tests import Form, tagged
+from .fatturapa_common import Common
-class TestInvoiceTripleDiscount(FatturaPACommon):
- def setUp(self):
- super(TestInvoiceTripleDiscount, self).setUp()
+@tagged("post_install", "-at_install")
+class TestEInvoiceTripleDiscount(Common):
def test_xml_export_triple_discount(self):
- self.set_sequences(13, "2016-01-07")
- invoice = self.invoice_model.create(
- {
- "date_invoice": "2016-01-07",
- "partner_id": self.res_partner_fatturapa_0.id,
- "journal_id": self.sales_journal.id,
- "account_id": self.a_recv.id,
- "payment_term_id": self.account_payment_term.id,
- "user_id": self.user_demo.id,
- "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,
- "uom_id": self.product_uom_unit.id,
- "price_unit": 10,
- "discount": 50,
- "discount2": 50,
- "discount3": 50,
- "invoice_line_tax_ids": [(6, 0, {self.tax_22.id})],
- },
- )
- ],
- }
+ partner = self.res_partner_fatturapa_0
+ partner.vat = "IT00146089990"
+ partner.fiscalcode = "00146089990"
+ invoice = self.init_invoice(
+ "out_invoice",
+ invoice_date="2016-01-07",
+ partner=partner,
+ products=self.product_product_10,
+ taxes=self.tax_22,
)
- invoice.action_invoice_open()
+ invoice_form = Form(invoice)
+ invoice_form.invoice_payment_term_id = self.account_payment_term
+ with invoice_form.invoice_line_ids.edit(0) as line:
+ line.name = "Mouse\nOptical"
+ line.price_unit = 10
+ line.discount = 50
+ line.discount2 = 50
+ line.discount3 = 50
+ invoice = invoice_form.save()
+ invoice.action_post()
res = self.run_wizard(invoice.id)
self.assertTrue(res)
@@ -50,9 +39,12 @@ def test_xml_export_triple_discount(self):
self.set_e_invoice_file_id(attachment, "IT06363391001_00001.xml")
# XML doc to be validated
- xml_content = codecs.decode(attachment.datas, "base64")
- self.check_content(
- xml_content,
- "IT06363391001_00001.xml",
- module_name="l10n_it_fatturapa_out_triple_discount",
+ xml_content = base64.decodebytes(attachment.datas)
+ xml_tree = self.get_xml_tree_from_string(xml_content)
+ expected_xml = self.getFile("IT06363391001_00001.xml")[1]
+ expected_xml_content = base64.decodebytes(expected_xml)
+ expected_xml_tree = self.get_xml_tree_from_string(expected_xml_content)
+ self.assertXmlTreeEqual(
+ xml_tree,
+ expected_xml_tree,
)
diff --git a/l10n_it_fatturapa_out_triple_discount/wizards/__init__.py b/l10n_it_fatturapa_out_triple_discount/wizards/__init__.py
index 5196bb6ea240..9c06eb6b370d 100644
--- a/l10n_it_fatturapa_out_triple_discount/wizards/__init__.py
+++ b/l10n_it_fatturapa_out_triple_discount/wizards/__init__.py
@@ -1 +1,3 @@
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+
from . import wizard_export_fatturapa
diff --git a/l10n_it_fatturapa_out_triple_discount/wizards/wizard_export_fatturapa.py b/l10n_it_fatturapa_out_triple_discount/wizards/wizard_export_fatturapa.py
index ec4f991fb438..26d0ccc3b21c 100644
--- a/l10n_it_fatturapa_out_triple_discount/wizards/wizard_export_fatturapa.py
+++ b/l10n_it_fatturapa_out_triple_discount/wizards/wizard_export_fatturapa.py
@@ -1,31 +1,56 @@
# Copyright 2019 Simone Rubino - Agile Business Group
+# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
-from odoo.tools.float_utils import float_round
+from odoo.tools import float_is_zero
-from odoo.addons.l10n_it_fatturapa.bindings.fatturapa import ScontoMaggiorazioneType
-
-class WizardExportFatturapa(models.TransientModel):
+class WizardExportFatturaPA(models.TransientModel):
_inherit = "wizard.export.fatturapa"
- def setDettaglioLinea(self, line_no, line, body, price_precision, uom_precision):
- res = super(WizardExportFatturapa, self).setDettaglioLinea(
- line_no, line, body, price_precision, uom_precision
- )
- if line.discount2 or line.discount3:
- DettaglioLinea = body.DatiBeniServizi.DettaglioLinee[-1]
- if line.discount2:
- DettaglioLinea.ScontoMaggiorazione.append(
- ScontoMaggiorazioneType(
- Tipo="SC", Percentuale="%.2f" % float_round(line.discount2, 8)
- )
- )
- if line.discount3:
- DettaglioLinea.ScontoMaggiorazione.append(
- ScontoMaggiorazioneType(
- Tipo="SC", Percentuale="%.2f" % float_round(line.discount3, 8)
+ def _get_efattura_class(self):
+ efattura_class = super()._get_efattura_class()
+
+ class EInvoiceOutTripleDiscount(efattura_class):
+ def get_template_values(self):
+ template_values = super().get_template_values()
+
+ format_numbers_two = template_values["format_numbers_two"]
+
+ def get_triple_ScontoMaggiorazione_values_list(line):
+ ScontoMaggiorazione_values_list = []
+
+ discount_fields = line._get_multiple_discount_field_names()
+
+ discounts_digits = line.fields_get(
+ allfields=discount_fields,
+ attributes=[
+ "digits",
+ ],
)
- )
- return res
+ for discount_field in discount_fields:
+ discount_perc = line[discount_field]
+ all_digits, precision_digits = discounts_digits[discount_field][
+ "digits"
+ ]
+ is_discount_zero = float_is_zero(
+ discount_perc,
+ precision_digits=precision_digits,
+ )
+ if not is_discount_zero:
+ ScontoMaggiorazione_values = {
+ "Tipo": "SC",
+ "Percentuale": format_numbers_two(discount_perc),
+ }
+ ScontoMaggiorazione_values_list.append(
+ ScontoMaggiorazione_values
+ )
+ return ScontoMaggiorazione_values_list
+
+ template_values[
+ "get_triple_ScontoMaggiorazione_values_list"
+ ] = get_triple_ScontoMaggiorazione_values_list
+ return template_values
+
+ return EInvoiceOutTripleDiscount