From 4a522be2c138102480e3e7808b86d10fa915410e Mon Sep 17 00:00:00 2001 From: "Daniel Kosky (dako)" Date: Fri, 12 Apr 2024 12:10:00 +0000 Subject: [PATCH] [FIX] l10n_ke_edi_tremol: price decimal length An update made to the tremol device has changed the expected content of the price field. It now expects up to 15 characters in this position, with a maximum of 5 decimal places. At present we can send prices with a decimal position greater than 5, doing so will result in an error from the fiscal device. This commit adapts the content that gets serialised in order to ensure that the decimal provided is no longer than 5 decimal places. closes odoo/odoo#161804 Task-id: none X-original-commit: 3373ac3a7945d25fee70d114816ce23a16d6e0ef Signed-off-by: Josse Colpaert Signed-off-by: Daniel Kosky (dako) --- addons/l10n_ke_edi_tremol/models/account_move.py | 3 ++- addons/l10n_ke_edi_tremol/tests/test_move_export.py | 4 ++-- 2 files changed, 4 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 f57aec21601..5878139c3c9 100644 --- a/addons/l10n_ke_edi_tremol/models/account_move.py +++ b/addons/l10n_ke_edi_tremol/models/account_move.py @@ -186,12 +186,13 @@ class AccountMove(models.Model): price_total = abs(line_tax_details['base_amount_currency']) + abs(line_tax_details['tax_amount_currency']) percentage = tax['tax'].amount price = round(price_total / abs(line.quantity) * 100 / (100 - line.discount), 2) * currency_rate + price = ('%.5f' % price).rstrip('0').rstrip('.') uom = line.product_uom_id and line.product_uom_id.name or '' line_data = b';'.join([ self._l10n_ke_fmt(line.name, 36), # 36 symbols for the article's name self._l10n_ke_fmt(item_code.tax_rate or 'A', 1), # 1 symbol for article's vat class ('A', 'B', 'C', 'D', or 'E') - str(price)[:13].encode('cp1251'), # 1 to 13 symbols for article's price + price[:15].encode('cp1251'), # 1 to 15 symbols for article's price with up to 5 digits after decimal point self._l10n_ke_fmt(uom, 3), # 3 symbols for unit of measure (item_code.code or '').ljust(10).encode('cp1251'), # 10 symbols for KRA item code in the format xxxx.xx.xx (can be empty) self._l10n_ke_fmt(item_code.description or '', 20), # 20 symbols for KRA item code description (can be empty) diff --git a/addons/l10n_ke_edi_tremol/tests/test_move_export.py b/addons/l10n_ke_edi_tremol/tests/test_move_export.py index 3b4612f065f..b098431a1cc 100644 --- a/addons/l10n_ke_edi_tremol/tests/test_move_export.py +++ b/addons/l10n_ke_edi_tremol/tests/test_move_export.py @@ -39,7 +39,7 @@ class TestKeMoveExport(AccountTestInvoicingCommon): msg = b'1' + b';'.join([ # 0x31, command to add a line line_dict.get('name', b''.ljust(36)), # 36 characters for the name line_dict.get('vat_class', b'A'), # 1 symbol for vat class (a because the tax is 16.0%) - line_dict.get('price', b'1'), # up to 13 symbols for the unit price, tax included + line_dict.get('price', b'1'), # up to 15 symbols for the unit price, tax included (up to 5 decimal places) line_dict.get('uom', b'Uni'), # 3 symbols for uom line_dict.get('item_code', b''.ljust(10)), # 10 symbols for item code (only reported when the tax is not 16.0%) line_dict.get('item_desc', b''.ljust(20)), # item description (only reported when the tex is not 16.0%) @@ -221,7 +221,7 @@ class TestKeMoveExport(AccountTestInvoicingCommon): generated_messages = multi_tax_line_invoice._l10n_ke_cu_lines_messages() expected_sale_line = self.line_dict_to_bytes({ 'name': b'Infinite Improbability Drive ', - 'price': b'1160.0', # This is the unit price, tax included, but only the 16% VAT + 'price': b'1160', # This is the unit price, tax included, but only the 16% VAT 'quantity': b'10.0', 'discount': b'-25.0%', })