From 2e0a72e545df9b29e5377615c7c6994e6afdb513 Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Fri, 29 Oct 2021 11:58:49 +0200 Subject: [PATCH] [FIX] l10n_it_fatturapa_in: allow use of our account in payment info --- .../tests/test_import_fatturapa_xml.py | 54 +++++++++++++++++-- .../wizard/wizard_import_fatturapa.py | 20 ++++--- 2 files changed, 65 insertions(+), 9 deletions(-) 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 8011d12dd3c2..7cd353593604 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -839,13 +839,27 @@ def test_47_xml_import(self): # IT01234567890_FPR14.xml should be tested manually def test_48_xml_import(self): - # my company bank account is the same as the one in XML: + # bank account already exists for another partner # invoice creation must not be blocked + to_unlink = [] + bank = self.env["res.bank"].create( + { + "bic": "BCITITMM", + "name": "Other Bank", + } + ) + to_unlink.append(bank) + partner = self.env["res.partner"].create( + { + "name": "Some Other Company", + } + ) + to_unlink.append(partner) self.env["res.partner.bank"].create( { "acc_number": "IT59R0100003228000000000622", - "company_id": self.env.company.id, - "partner_id": self.env.company.partner_id.id, + "company_id": self.env.user.company_id.id, + "partner_id": partner.id, } ) res = self.run_wizard("test48", "IT01234567890_FPR15.xml") @@ -855,6 +869,8 @@ def test_48_xml_import(self): "Bank account IT59R0100003228000000000622 already exists" in invoice.inconsistencies ) + for model in to_unlink: + model.unlink() def test_49_xml_import(self): # this method name is used in 12.0 @@ -1003,6 +1019,38 @@ def test_54_xml_import(self): self.assertEqual(invoice.invoice_line_ids[0].price_subtotal, 1.5) self.assertEqual(invoice.move_type, "in_refund") + def test_55_xml_import(self): + # Payments may refer to our own bank account (SEPA) + to_unlink = [] + bank = self.env["res.bank"].create( + { + "bic": "BCITITMM", + "name": "Other Bank", + } + ) + to_unlink.append(bank) + bank_account = 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, + } + ) + to_unlink.append(bank_account) + res = self.run_wizard("test55", "IT01234567890_FPR15.xml") + invoice_id = res.get("domain")[0][2][0] + invoice = self.invoice_model.browse(invoice_id) + self.assertIn( + invoice.fatturapa_payments[0].payment_methods[0].payment_bank_iban, + invoice.company_id.partner_id.bank_ids.mapped("acc_number"), + ) + self.assertFalse( + "Bank account IT59R0100003228000000000622 already exists" + in invoice.inconsistencies + ) + for model in to_unlink: + model.unlink() + 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 582ea21c54da..bad3b4a7fccb 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -823,7 +823,8 @@ def _addGlobalDiscount(self, invoice_id, DatiGeneraliDocumento): ).create(line_vals) return True - def _createPaymentsLine(self, payment_id, line, partner_id, invoice): + def _createPaymentsLine(self, payment, line, partner_id, invoice_id): + invoice = self.env["account.move"].browse(invoice_id) details = line.DettaglioPagamento or False if details: PaymentModel = self.env["fatturapa.payment.detail"] @@ -865,7 +866,7 @@ def _createPaymentsLine(self, payment_id, line, partner_id, invoice): "penalty_amount": dline.PenalitaPagamentiRitardati or 0.0, "penalty_date": dline.DataDecorrenzaPenale or False, "payment_code": dline.CodicePagamento or "", - "payment_data_id": payment_id, + "payment_data_id": payment.id, } bank = False payment_bank_id = False @@ -893,7 +894,14 @@ def _createPaymentsLine(self, payment_id, line, partner_id, invoice): iban = dline.IBAN.strip() SearchDom = [ ("acc_number", "=", pretty_iban(iban)), - ("partner_id", "=", partner_id), + ( + "partner_id", + "in", + ( + partner_id, + invoice.company_id.partner_id.id, + ), + ), ] payment_bank_id = False payment_banks = PartnerBankModel.search(SearchDom) @@ -913,7 +921,7 @@ def _createPaymentsLine(self, payment_id, line, partner_id, invoice): elif not payment_banks and bank: existing_account = PartnerBankModel.search( [ - ("acc_number", "=", iban), + ("acc_number", "=", pretty_iban(iban)), ("company_id", "=", invoice.company_id.id), ] ) @@ -1539,8 +1547,8 @@ def set_payments_data(self, FatturaBody, invoice, partner_id): term_id = terms[0].id PayDataId = PaymentDataModel.create( {"payment_terms": term_id, "invoice_id": invoice_id} - ).id - self._createPaymentsLine(PayDataId, PaymentLine, partner_id, invoice) + ) + self._createPaymentsLine(PayDataId, PaymentLine, partner_id, invoice_id) def set_withholding_tax(self, FatturaBody, invoice_data): Withholdings = FatturaBody.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta