diff --git a/README.rst b/README.rst index 2af1f47..15cf365 100644 --- a/README.rst +++ b/README.rst @@ -15,6 +15,10 @@ Requires Changes ======= +*7.0.4 - 29.01.2025* + +- add: Round unit_price + quantity to match the decimal places of the fields. + *7.0.3 - 27.01.2025* - filter product-categories in configuration diff --git a/document.py b/document.py index 75a2003..a3bf0c9 100644 --- a/document.py +++ b/document.py @@ -20,6 +20,7 @@ from trytond.i18n import gettext from trytond.model import fields from trytond.pyson import Eval from trytond.protocols.jsonrpc import JSONEncoder +from trytond.modules.product import round_price xml_types = [ @@ -732,12 +733,15 @@ class Incoming(metaclass=PoolMeta): if units: xml_uom = units[0] + unitprice = line_data.get('unit_net_price', {}).pop('amount', None) line = Line( invoice=invoice, type='line', unit=xml_uom, - quantity=line_data.get('quantity', {}).pop('billed', None), - unit_price=line_data.get('unit_net_price', {}).pop('amount', None)) + quantity=xml_uom.round( + line_data.get('quantity', {}).pop('billed', None)), + unit_price=round_price(unitprice) + if unitprice is not None else Decimal('0.0')) line_no = line_data.pop('line_no', None) # description @@ -976,9 +980,9 @@ class Incoming(metaclass=PoolMeta): result['quantity'] = self._readxml_read_listdata( xmldata, xpath_line, [ 'ram:SpecifiedLineTradeDelivery'], [ - ('ram:BilledQuantity', 'billed', Decimal), - ('ram:ChargeFreeQuantity', 'chargefree', Decimal), - ('ram:PackageQuantity', 'package', Decimal), + ('ram:BilledQuantity', 'billed', float), + ('ram:ChargeFreeQuantity', 'chargefree', float), + ('ram:PackageQuantity', 'package', float), ])[0] result['quantity']['unit_code'] = self._readxml_getattrib( xmldata, xpath_quantity + ['ram:BilledQuantity'], 'unitCode') diff --git a/tests/parsed_data.py b/tests/parsed_data.py index 0e5315f..351052d 100644 --- a/tests/parsed_data.py +++ b/tests/parsed_data.py @@ -23,7 +23,7 @@ parsed_data_ci_invoice = { 'total': {'amount': Decimal('1350.00')}, 'line_no': '1', 'quantity': { - 'billed': Decimal('1.0'), + 'billed': 1.0, 'unit_code': 'KGM'}, 'unit_net_price': {'amount': Decimal('1350.00')}, }, { @@ -34,7 +34,7 @@ parsed_data_ci_invoice = { 'total': {'amount': Decimal('1200.00')}, 'line_no': '2', 'quantity': { - 'billed': Decimal('1.5'), + 'billed': 1.5, 'unit_code': 'KGM'}, 'unit_net_price': {'amount': Decimal('800.00')}, }, { @@ -42,7 +42,7 @@ parsed_data_ci_invoice = { 'total': {'amount': Decimal('300.00')}, 'line_no': '3', 'quantity': { - 'billed': Decimal('2.0'), + 'billed': 2.0, 'unit_code': 'MTR'}, 'unit_net_price': {'amount': Decimal('150.00')}}], 'note_list': [{ @@ -101,7 +101,7 @@ parsed_data_facturx_en16931 = { 'description': 'Description of Product 1', 'unit_net_price': {'amount': Decimal('1350.00')}, 'quantity': { - 'billed': Decimal('1.0'), 'unit_code': 'KGM'}, + 'billed': 1.0, 'unit_code': 'KGM'}, 'taxes': [{ 'type': 'VAT', 'category_code': 'S', @@ -127,7 +127,7 @@ parsed_data_facturx_en16931 = { 'amount': Decimal('950.00'), 'basequantity': Decimal('1.0')}, 'quantity': { - 'billed': Decimal('1.5'), + 'billed': 1.5, 'unit_code': 'KGM'}, 'taxes': [{ 'type': 'VAT', @@ -141,7 +141,7 @@ parsed_data_facturx_en16931 = { 'description': 'Description of Product 3', 'unit_net_price': {'amount': Decimal('150.00')}, 'quantity': { - 'billed': Decimal('2.0'), + 'billed': 2.0, 'unit_code': 'MTR'}, 'taxes': [{ 'type': 'VAT', @@ -213,7 +213,7 @@ parsed_data_facturx_basic = { 'line_no': '1', 'name': 'Name of Product 1', 'unit_net_price': {'amount': Decimal('1350.00')}, - 'quantity': {'billed': Decimal('1.0'), 'unit_code': 'KGM'}, + 'quantity': {'billed': 1.0, 'unit_code': 'KGM'}, 'taxes': [{ 'type': 'VAT', 'category_code': 'S', @@ -231,7 +231,7 @@ parsed_data_facturx_basic = { 'amount': Decimal('950.00'), 'basequantity': Decimal('1.0')}, 'quantity': { - 'billed': Decimal('1.5'), + 'billed': 1.5, 'unit_code': 'KGM'}, 'taxes': [{ 'type': 'VAT', @@ -243,7 +243,7 @@ parsed_data_facturx_basic = { 'name': 'Name of Product 3', 'unit_net_price': {'amount': Decimal('150.00')}, 'quantity': { - 'billed': Decimal('2.0'), + 'billed': 2.0, 'unit_code': 'MTR'}, 'taxes': [{ 'type': 'VAT', @@ -328,7 +328,7 @@ parsed_data_facturx_extended = { 'name': 'Name of Product 1', 'description': 'Description of Product 1', 'unit_net_price': {'amount': Decimal('1350.00')}, - 'quantity': {'billed': Decimal('1.0'), 'unit_code': 'KGM'}, + 'quantity': {'billed': 1.0, 'unit_code': 'KGM'}, 'taxes': [{ 'type': 'VAT', 'category_code': 'S', @@ -379,7 +379,7 @@ parsed_data_facturx_extended = { 'amount': Decimal('950.00'), 'basequantity': Decimal('1.0')}, 'quantity': { - 'billed': Decimal('1.5'), + 'billed': 1.5, 'unit_code': 'KGM', 'package': Decimal('1.5')}, 'taxes': [{ @@ -392,7 +392,7 @@ parsed_data_facturx_extended = { 'name': 'Name of Product 3', 'description': 'Description of Product 3', 'unit_net_price': {'amount': Decimal('150.00')}, - 'quantity': {'billed': Decimal('2.0'), 'unit_code': 'MTR'}, + 'quantity': {'billed': 2.0, 'unit_code': 'MTR'}, 'taxes': [{ 'type': 'VAT', 'category_code': 'S', diff --git a/tryton.cfg b/tryton.cfg index 8dd8cc3..2d37146 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=7.0.3 +version=7.0.4 depends: document_incoming_invoice edocument_unece