From ab2ba10d463c720ec8fa3aad74cc6788355fd5d4 Mon Sep 17 00:00:00 2001 From: Julien Van Roy Date: Fri, 24 Nov 2023 12:06:03 +0100 Subject: [PATCH] [IMP] account_edi_ubl_cii: prevent negative unit prices for bis 3 The unit prices should always be positives in the Peppol Bis 3 xml, otherwise, a validator will raise "[BR-27]-The Item net price (BT-146) shall NOT be negative.". Add a constraint in the code to ensure this. task-3607341 closes odoo/odoo#143648 X-original-commit: db52055f72ce5d9b1667ee89c55301756a0fabab Signed-off-by: Laurent Smet (las) Signed-off-by: Julien Van Roy (juvr) --- addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot | 9 +++++++++ .../models/account_edi_xml_ubl_bis3.py | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot index 1cd4d6d075b..26724fbed85 100644 --- a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot +++ b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot @@ -837,6 +837,15 @@ msgid "" "The field 'Sanitized Account Number' is required on the Recipient Bank." msgstr "" +#. module: account_edi_ubl_cii +#. odoo-python +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py:0 +#, python-format +msgid "" +"The invoice contains line(s) with a negative unit price, which is not " +"allowed. You might need to set a negative quantity instead." +msgstr "" + #. module: account_edi_ubl_cii #. odoo-python #: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py index 4bce8d3248a..3ebd7ba6a9f 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py @@ -306,6 +306,11 @@ class AccountEdiXmlUBLBIS3(models.AbstractModel): } for line in invoice.invoice_line_ids.filtered(lambda x: x.display_type not in ('line_note', 'line_section')): + if invoice.currency_id.compare_amounts(line.price_unit, 0) == -1: + # [BR-27]-The Item net price (BT-146) shall NOT be negative. + constraints.update({'cen_en16931_positive_item_net_price': _( + "The invoice contains line(s) with a negative unit price, which is not allowed." + " You might need to set a negative quantity instead.")}) if len(line.tax_ids.flatten_taxes_hierarchy().filtered(lambda t: t.amount_type != 'fixed')) != 1: # [UBL-SR-48]-Invoice lines shall have one and only one classified tax category. # /!\ exception: possible to have any number of ecotaxes (fixed tax) with a regular percentage tax