Skip to content

Commit

Permalink
[FIX] l10n_it_fatturapa_in: allow use of our account in payment info
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMule71 authored and matteoopenf committed Jun 20, 2024
1 parent 8bdb2e8 commit 0b7a45d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
57 changes: 52 additions & 5 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,27 @@ def test_47_xml_import(self):
# IT01234567890_FPR14.xml should be tested manually

def test_48_xml_import(self):
# depends on test_36_xml_import
# 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
partner_bank = self.env["res.partner.bank"].create(
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,
}
)
# 16.0: company_id gets reset right after creation
Expand All @@ -851,6 +864,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
Expand Down Expand Up @@ -992,6 +1007,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.
Expand Down
20 changes: 14 additions & 6 deletions l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,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"]
Expand Down Expand Up @@ -901,7 +902,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
Expand Down Expand Up @@ -929,7 +930,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)
Expand All @@ -949,7 +957,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),
]
)
Expand Down Expand Up @@ -1576,8 +1584,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
Expand Down

0 comments on commit 0b7a45d

Please sign in to comment.