From b68b4e4042cbcf8cf9eb1e03cb30de3d744322a0 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 | 13 ++++++------- tryton.cfg | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stock.py b/stock.py index 2909d2e423..dd852710a1 100644 --- a/stock.py +++ b/stock.py @@ -1,12 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from decimal import Decimal - from trytond.model import fields from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval -from trytond.modules.product import price_digits +from trytond.modules.product import price_digits, round_price class Move(metaclass=PoolMeta): @@ -80,10 +78,11 @@ class Move(metaclass=PoolMeta): Uom = pool.get('product.uom') if (self.unit_price and self.uom and self.secondary_unit and (self.secondary_uom_factor or self.secondary_uom_rate)): - return Uom.compute_price( + unit_price = Uom.compute_price( self.uom, self.unit_price, self.secondary_unit, factor=self.secondary_uom_factor, rate=self.secondary_uom_rate - ).quantize(Decimal(1) / 10 ** price_digits[1]) + ) + return round_price(unit_price) else: return None @@ -95,8 +94,8 @@ class Move(metaclass=PoolMeta): and (self.secondary_uom_factor or self.secondary_uom_rate)): self.unit_price = Uom.compute_price( self.secondary_unit, self.secondary_unit_price, self.uom, - factor=self.secondary_uom_rate, rate=self.secondary_uom_factor - ).quantize(Decimal(1) / 10 ** price_digits[1]) + factor=self.secondary_uom_rate, rate=self.secondary_uom_factor) + self.unit_price = round_price(self.unit_price) @fields.depends(methods=[ 'on_change_secondary_quantity', 'on_change_secondary_unit_price']) diff --git a/tryton.cfg b/tryton.cfg index ed5696495d..c4761a80a9 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -3,5 +3,6 @@ version=5.5.0 depends: ir stock + product xml: stock.xml