[FIX] account_edi_ubl_cii: check validaty of taxes
Invalid taxes could lead to invalid results from the `_prepare_edi_tax_details` fonction. For instance: a tax without tax repartition lines will be disregarded, which in turns leads to an invalid xml being generated. opw-3175701 closes odoo/odoo#116855 X-original-commit: 22b18a17348be6bd3982cbffd31da383442a6433 Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com> Signed-off-by: Julien Van Roy <juvr@odoo.com>
This commit is contained in:
@@ -255,6 +255,12 @@ msgstr ""
|
||||
msgid "Report Action"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_edi_ubl_cii
|
||||
#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0
|
||||
#, python-format
|
||||
msgid "Tax '%s' is invalid: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_edi_ubl_cii
|
||||
#: model:ir.model,name:account_edi_ubl_cii.model_account_edi_xml_ubl_nl
|
||||
msgid "SI-UBL 2.0 (NLCIUS)"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from odoo import _, models, Command
|
||||
from odoo.tools import float_repr
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tools.float_utils import float_round
|
||||
|
||||
from zeep import Client
|
||||
@@ -113,6 +113,16 @@ class AccountEdiCommon(models.AbstractModel):
|
||||
# TAXES
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
def _validate_taxes(self, invoice):
|
||||
""" Validate the structure of the tax repartition lines (invalid structure could lead to unexpected results)
|
||||
"""
|
||||
for tax in invoice.invoice_line_ids.tax_ids:
|
||||
try:
|
||||
tax._validate_repartition_lines()
|
||||
except ValidationError as e:
|
||||
error_msg = _("Tax '%s' is invalid: %s", tax.name, e.args[0]) # args[0] gives the error message
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
def _get_tax_unece_codes(self, invoice, tax):
|
||||
"""
|
||||
Source: doc of Peppol (but the CEF norm is also used by factur-x, yet not detailed)
|
||||
|
||||
@@ -131,6 +131,9 @@ class AccountEdiXmlCII(models.AbstractModel):
|
||||
'amount_type': tax.amount_type,
|
||||
}
|
||||
|
||||
# Validate the structure of the taxes
|
||||
self._validate_taxes(invoice)
|
||||
|
||||
# Create file content.
|
||||
tax_details = invoice._prepare_edi_tax_details(grouping_key_generator=grouping_key_generator)
|
||||
|
||||
|
||||
@@ -345,6 +345,9 @@ class AccountEdiXmlUBL20(models.AbstractModel):
|
||||
'_tax_category_vals_': tax_category_vals,
|
||||
}
|
||||
|
||||
# Validate the structure of the taxes
|
||||
self._validate_taxes(invoice)
|
||||
|
||||
# Compute the tax details for the whole invoice and each invoice line separately.
|
||||
taxes_vals = invoice._prepare_edi_tax_details(grouping_key_generator=grouping_key_generator)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user