From 89c5ed65f013da216361d41307effab48b0230af Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Wed, 20 Nov 2024 14:39:03 +0100 Subject: [PATCH] [IMP] l10n_it_fatturapa_in: Test price computation with many digits When price precision is increased during import, the price of the created lines should have been computed using the new precision --- .../tests/data/IT01234567890_FPR16.xml | 87 +++++++++++++++++++ .../tests/fatturapa_common.py | 4 + .../tests/test_import_fatturapa_xml.py | 61 +++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 l10n_it_fatturapa_in/tests/data/IT01234567890_FPR16.xml diff --git a/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR16.xml b/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR16.xml new file mode 100644 index 000000000000..55ca5dbe6b49 --- /dev/null +++ b/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR16.xml @@ -0,0 +1,87 @@ + + + + + + IT + 02780790107 + + FPR14 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + test@pec.it + + + + + IT + 02780790107 + + + YourCompany + + RF01 + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 07973780013 + + 07973780013 + + B2B Customer + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + EUR + 2020-09-30 + 14481 + 81.49 + + + + + 1 + Test precisione decimale + 69.00 + 0.968 + 66.792 + 22.00 + + + 22.00 + 66.79 + 14.69 + + + + diff --git a/l10n_it_fatturapa_in/tests/fatturapa_common.py b/l10n_it_fatturapa_in/tests/fatturapa_common.py index 197081db5e10..e7a52f45e235 100644 --- a/l10n_it_fatturapa_in/tests/fatturapa_common.py +++ b/l10n_it_fatturapa_in/tests/fatturapa_common.py @@ -288,6 +288,8 @@ def run_wizard( ): if module_name is None: module_name = "l10n_it_fatturapa_in" + if wiz_values is None: + wiz_values = dict() attach = self.create_attachment(name, file_name, module_name=module_name) attach.e_invoice_received_date = fields.Datetime.now() attach_id = attach.id @@ -297,6 +299,8 @@ def run_wizard( active_ids=[attach_id], active_model="fatturapa.attachment.in" ) ) + for wiz_field, wiz_value in wiz_values.items(): + setattr(wizard_form, wiz_field, wiz_value) wizard = wizard_form.save() return wizard.importFatturaPA() if mode == "link": diff --git a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py index be8f6ddc2ba7..9bf3e3e8a690 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -1150,6 +1150,67 @@ def test_ignore_global_discount(self): self.assertEqual(invoice.amount_tax, 5.12) self.assertEqual(invoice.amount_total, 28.39) + def test_increased_decimal_precision(self): + """ + Increase price decimal precision during import: + computation of line's price is more accurate. + """ + res = self.run_wizard( + "increased_decimal_precision", + "IT01234567890_FPR16.xml", + wiz_values={ + "price_decimal_digits": 3, + }, + ) + + # The new precision allows to compute the correct amount + invoice = self.invoice_model.search(res["domain"]) + self.assertRecordValues( + invoice, + [ + { + "amount_untaxed": 66.79, + "amount_tax": 14.69, + "amount_total": 81.48, + }, + ], + ) + invoice_line = invoice.invoice_line_ids + self.assertRecordValues( + invoice_line, + [ + { + "price_subtotal": 66.79, + "price_total": 81.48, + }, + ], + ) + + # Trigger amounts recomputation + with Form(invoice) as invoice_form: + invoice_form.date = fields.Date.today() + + # The correct amount is kept + self.assertRecordValues( + invoice, + [ + { + "amount_untaxed": 66.79, + "amount_tax": 14.69, + "amount_total": 81.48, + }, + ], + ) + self.assertRecordValues( + invoice_line, + [ + { + "price_subtotal": 66.79, + "price_total": 81.48, + }, + ], + ) + class TestFatturaPAEnasarco(FatturapaCommon): def setUp(self):