Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] l10n_it_fatturapa_in: allow use of our account in payment info #4223

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,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
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)
partner_bank = 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 @@ -815,6 +828,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 @@ -972,6 +987,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
62 changes: 56 additions & 6 deletions l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,50 @@ def _computeDiscount(self, DettaglioLinea):
discount = (1 - (line_unit / float(DettaglioLinea.PrezzoUnitario))) * 100.0
return discount

def _createPaymentsLine(self, payment_id, line, partner_id, invoice):
def _addGlobalDiscount(self, invoice_id, DatiGeneraliDocumento):
discount = 0.0
if (
DatiGeneraliDocumento.ScontoMaggiorazione
and self.e_invoice_detail_level == "2"
):
invoice = self.env["account.move"].browse(invoice_id)
for DiscRise in DatiGeneraliDocumento.ScontoMaggiorazione:
if DiscRise.Percentuale:
amount = invoice.amount_total * (float(DiscRise.Percentuale) / 100)
if DiscRise.Tipo == "SC":
discount -= amount
elif DiscRise.Tipo == "MG":
discount += amount
elif DiscRise.Importo:
if DiscRise.Tipo == "SC":
discount -= float(DiscRise.Importo)
elif DiscRise.Tipo == "MG":
discount += float(DiscRise.Importo)
company = invoice.company_id
global_discount_product = company.sconto_maggiorazione_product_id
credit_account = self.get_credit_account(
product=global_discount_product,
)
line_vals = {
"move_id": invoice_id,
"name": _("Global bill discount from document general data"),
"account_id": credit_account.id,
"price_unit": discount,
"quantity": 1,
}
if global_discount_product:
line_vals["product_id"] = global_discount_product.id
line_vals["name"] = global_discount_product.name
self.adjust_accounting_data(global_discount_product, line_vals)
else:
line_vals["tax_ids"] = [fields.Command.clear()]
self.env["account.move.line"].with_context(
check_move_validity=False
).create(line_vals)
return True

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 @@ -858,7 +901,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 @@ -886,7 +929,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 @@ -906,7 +956,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 @@ -1536,8 +1586,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
Loading