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 OCA-git-bot committed Oct 4, 2024
1 parent a186182 commit 2e0a72e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 9 deletions.
54 changes: 51 additions & 3 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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.
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 @@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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),
]
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e0a72e

Please sign in to comment.