From aa96ed39bdfa9316fcde38f759af2d8e241f85b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 23 Apr 2020 21:44:00 +0200 Subject: [PATCH] Add round_price We add a common method to round prices that are stored using the price digits. It is useless to use the digits from the field because it can not be changed in any other way than by configuration. issue9146 review299521002 --- stock.py | 10 +++++----- tryton.cfg | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stock.py b/stock.py index e9c0ab84de..4e8c5e9a12 100644 --- a/stock.py +++ b/stock.py @@ -8,7 +8,7 @@ from trytond.pyson import Eval, Bool from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction -from trytond.modules.product import price_digits +from trytond.modules.product import price_digits, round_price class ShipmentIn(metaclass=PoolMeta): @@ -91,8 +91,8 @@ class ShipmentIn(metaclass=PoolMeta): move_cost = cost / Decimal(len(moves)) else: move_cost = cost * quantity * unit_prices[move.id] / sum_value - unit_shipment_cost = (move_cost / quantity).quantize(exp, - rounding=ROUND_DOWN) + unit_shipment_cost = round_price( + move_cost / quantity, rounding=ROUND_DOWN) costs.append({ 'unit_shipment_cost': unit_shipment_cost, 'difference': move_cost - (unit_shipment_cost * quantity), @@ -114,8 +114,8 @@ class ShipmentIn(metaclass=PoolMeta): unit_shipment_cost = Currency.compute( self.company.currency, cost['unit_shipment_cost'], move.currency, round=False) - unit_shipment_cost = unit_shipment_cost.quantize( - exp, rounding=ROUND_HALF_EVEN) + unit_shipment_cost = round_price( + unit_shipment_cost, rounding=ROUND_HALF_EVEN) move.unit_price += unit_shipment_cost move.unit_shipment_cost = unit_shipment_cost Move.save(moves) diff --git a/tryton.cfg b/tryton.cfg index b726015a73..a6b0bba391 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -4,6 +4,7 @@ depends: carrier currency ir + product res stock extras_depend: