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: errore importo fattura con arrotondamento #4561

Open
wants to merge 2 commits into
base: 14.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
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ITA - Fattura elettronica - Ricezione
=====================================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down
40 changes: 11 additions & 29 deletions l10n_it_fatturapa_in/models/account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import float_compare
Expand Down Expand Up @@ -40,28 +43,6 @@ class AccountInvoice(models.Model):

e_invoice_received_date = fields.Date(string="E-Bill Received Date")

@api.depends(
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual",
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency", # noqa: B950
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual",
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency", # noqa: B950
"line_ids.debit",
"line_ids.credit",
"line_ids.currency_id",
"line_ids.amount_currency",
"line_ids.amount_residual",
"line_ids.amount_residual_currency",
"line_ids.payment_id.state",
"line_ids.full_reconcile_id",
)
def _compute_amount(self):
super(AccountInvoice, self)._compute_amount()
for inv in self:
if inv.efatt_rounding != 0:
inv.amount_total += inv.efatt_rounding
sign = inv.move_type in ["in_refund", "out_refund"] and -1 or 1
inv.amount_total_signed = inv.amount_total * sign

def action_post(self):
for invoice in self:
if (
Expand Down Expand Up @@ -121,12 +102,13 @@ def e_inv_check_amount_tax(self):

def e_inv_check_amount_total(self):
error_message = ""
bill_total = self.amount_total
e_bill_total = self.e_invoice_amount_total or 0
if (
self.e_invoice_amount_total
and float_compare(
self.amount_total - self.efatt_rounding,
abs(self.e_invoice_amount_total),
precision_rounding=self.currency_id.rounding,
e_bill_total
and self.currency_id.compare_amounts(
bill_total,
abs(e_bill_total),
)
!= 0
):
Expand All @@ -135,8 +117,8 @@ def e_inv_check_amount_total(self):
"does not match with "
"e-bill total amount ({e_bill_amount_total})"
).format(
bill_amount_total=self.amount_total or 0,
e_bill_amount_total=self.e_invoice_amount_total,
bill_amount_total=bill_total or 0,
e_bill_amount_total=e_bill_total,
)
return error_message

Expand Down
13 changes: 10 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 @@ -592,10 +592,17 @@ def test_25_xml_import(self):
res = self.run_wizard("test25", "IT05979361218_013.xml")
invoice_id = res.get("domain")[0][2][0]
invoice = self.invoice_model.browse(invoice_id)
self.assertAlmostEqual(invoice.e_invoice_amount_untaxed, 34.67)
e_bill_total = 34.32
e_bill_rounding = -0.35
self.assertAlmostEqual(
invoice.e_invoice_amount_untaxed, e_bill_total - e_bill_rounding
)
self.assertEqual(invoice.e_invoice_amount_tax, 0.0)
self.assertEqual(invoice.e_invoice_amount_total, 34.32)
self.assertEqual(invoice.efatt_rounding, -0.35)
self.assertEqual(invoice.e_invoice_amount_total, e_bill_total)
self.assertEqual(invoice.efatt_rounding, e_bill_rounding)
self.assertEqual(invoice.amount_total, e_bill_total)
self.assertEqual(invoice.amount_total_signed, -e_bill_total)
self.assertEqual(invoice.amount_net_pay, e_bill_total)
invoice.action_post()
move_line = False
for line in invoice.line_ids:
Expand Down
Loading