From f80b8f0f6baa0870029ee76e6d27faeaa083c1a4 Mon Sep 17 00:00:00 2001 From: "Daniel Kosky (dako)" Date: Mon, 13 Mar 2023 15:29:19 +0000 Subject: [PATCH] [FIX] l10n_ke_edi_tremol: fix price and quantity negative scenario When both the price and quantity are negative, this creates a few problems that the serialisation code does not handle appropriately. Firstly, the device does not accept negative values for price or quantity. Price and quantity should therefore always be positive. In the case where both the price and the quantity are negative, the line is positive, and we must therefore processes it in the same manner as positive lines. A line with both negative and price and quantity should qualify as a line that, when negative lines are present, can be subtracted from in order to represent a discount. This commit adapts the serialisation function in order to correctly represent a negative price and quantity line as positive (by using the absolute values of each). It also adapts the discount line code in order to recognize these lines as candidate lines for discount. X-original-commit: db774ac144e760e23d4a032971c64e2010486325 Part-of: odoo/odoo#116615 --- addons/l10n_ke_edi_tremol/models/account_move.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/l10n_ke_edi_tremol/models/account_move.py b/addons/l10n_ke_edi_tremol/models/account_move.py index 7325ef87d67..59e64b23f58 100644 --- a/addons/l10n_ke_edi_tremol/models/account_move.py +++ b/addons/l10n_ke_edi_tremol/models/account_move.py @@ -129,7 +129,7 @@ class AccountMove(models.Model): in order to add a line to the opened invoice. """ def is_discount_line(line): - return line.price_unit < 0.0 + return line.price_subtotal < 0.0 def is_candidate(discount_line, other_line): """ If the of one line match those of the discount line, the discount can be distributed accross that line """ @@ -166,7 +166,7 @@ class AccountMove(models.Model): msgs = [] for line in self.invoice_line_ids.filtered(lambda l: l.display_type == 'product' and l.quantity and l.price_total > 0 and not discount_dict.get(l.id) >= 100): # Here we use the original discount of the line, since it the distributed discount has not been applied in the price_total - price = round(line.price_total / line.quantity * 100 / (100 - line.discount), 2) * currency_rate + price = round(line.price_total / abs(line.quantity) * 100 / (100 - line.discount), 2) * currency_rate percentage = line.tax_ids[0].amount # Letter to classify tax, 0% taxes are handled conditionally, as the tax can be zero-rated or exempt @@ -194,7 +194,7 @@ class AccountMove(models.Model): str(percentage).encode('cp1251')[:5] # up to 5 symbols for vat rate ]) # 1 to 10 symbols for quantity - line_data += b'*' + str(line.quantity).encode('cp1251')[:10] + line_data += b'*' + str(abs(line.quantity)).encode('cp1251')[:10] if discount_dict.get(line.id): # 1 to 7 symbols for percentage of discount/addition discount_sign = b'-' if discount_dict[line.id] > 0 else b'+'