From ac2507d387ad943c6ee219f0b1d17929131ab0b1 Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Fri, 7 May 2021 18:30:43 +0200 Subject: [PATCH] [FIX] forward port of #2272 --- .../tests/data/IT01234567890_FPR15.xml | 108 ++++++++++++++++++ .../tests/test_import_fatturapa_xml.py | 18 +++ .../wizard/wizard_import_fatturapa.py | 38 +++--- 3 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 l10n_it_fatturapa_in/tests/data/IT01234567890_FPR15.xml diff --git a/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR15.xml b/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR15.xml new file mode 100644 index 000000000000..095b0976697e --- /dev/null +++ b/l10n_it_fatturapa_in/tests/data/IT01234567890_FPR15.xml @@ -0,0 +1,108 @@ + + + + + + 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 + FPR 17/20 + 54313.50 + + + + + 10 + Benzina S.Pb 10PPM + 4000.00000000 + L + 1.35580114 + 5423.20456 + 22.00 + + + 20 + Gasolio Autotrazione 10PPM + 32000.00000000 + L + 1.22175180 + 39096.05760 + 22.00 + + + 22.00 + 44519.26 + 9794.24 + I + + + + TP01 + + MP01 + 2021-04-21 + 54313.50 + IT59R0100003228000000000622 + BCITITMM + + + + 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 b856d8fa999d..7d0e5cb7d9e3 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -672,6 +672,24 @@ def test_45_xml_many_zeros(self): self.assertEqual(invoice.invoice_line_ids[1].quantity, 1.0) self.assertEqual(invoice.invoice_line_ids[1].price_subtotal, 0.0) + def test_48_xml_import(self): + # my company bank account is the same as the one in XML: + # invoice creation must not be blocked + self.env["res.partner.bank"].create( + { + "acc_number": "IT59R0100003228000000000622", + "company_id": self.env.user.company_id.id, + "partner_id": self.env.user.company_id.partner_id.id, + } + ) + res = self.run_wizard("test48", "IT01234567890_FPR15.xml") + invoice_id = res.get("domain")[0][2][0] + invoice = self.invoice_model.browse(invoice_id) + self.assertTrue( + "Bank account IT59R0100003228000000000622 already exists" + in invoice.e_invoice_validation_message + ) + def test_01_xml_link(self): """ E-invoice lines are created. diff --git a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py index 778003c4313b..a2a26de20cfd 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -664,7 +664,7 @@ def _addGlobalDiscount(self, invoice_id, DatiGeneraliDocumento): ).create(line_vals) return True - def _createPaymentsLine(self, payment_id, line, partner_id): + def _createPaymentsLine(self, payment_id, line, partner_id, invoice): details = line.DettaglioPagamento or False if details: PaymentModel = self.env["fatturapa.payment.detail"] @@ -731,8 +731,9 @@ def _createPaymentsLine(self, payment_id, line, partner_id): else: bank = banks[0] if dline.IBAN: + iban = dline.IBAN.strip() SearchDom = [ - ("acc_number", "=", pretty_iban(dline.IBAN.strip())), + ("acc_number", "=", pretty_iban(iban)), ("partner_id", "=", partner_id), ] payment_bank_id = False @@ -746,20 +747,31 @@ def _createPaymentsLine(self, payment_id, line, partner_id): "Bank Name: %s\n" ) % ( - dline.IBAN.strip() or "", + iban or "", dline.IstitutoFinanziario or "", ) ) elif not payment_banks and bank: - payment_bank_id = PartnerBankModel.create( - { - "acc_number": dline.IBAN.strip(), - "partner_id": partner_id, - "bank_id": bank.id, - "bank_name": dline.IstitutoFinanziario or bank.name, - "bank_bic": dline.BIC or bank.bic, - } - ).id + existing_account = PartnerBankModel.search( + [ + ("acc_number", "=", iban), + ("company_id", "=", invoice.company_id.id), + ] + ) + if existing_account: + self.log_inconsistency( + _("Bank account %s already exists") % iban + ) + else: + payment_bank_id = PartnerBankModel.create( + { + "acc_number": iban, + "partner_id": partner_id, + "bank_id": bank.id, + "bank_name": dline.IstitutoFinanziario or bank.name, + "bank_bic": dline.BIC or bank.bic, + } + ).id if payment_banks: payment_bank_id = payment_banks[0].id @@ -1265,7 +1277,7 @@ def set_payments_data(self, FatturaBody, invoice, partner_id): PayDataId = PaymentDataModel.create( {"payment_terms": term_id, "invoice_id": invoice_id} ).id - self._createPaymentsLine(PayDataId, PaymentLine, partner_id) + self._createPaymentsLine(PayDataId, PaymentLine, partner_id, invoice) def set_withholding_tax(self, FatturaBody, invoice_data): Withholdings = FatturaBody.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta