From c81f3f33dbc07afaf0058c7e39924c6e4f773f6a 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 --- account.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/account.py b/account.py index 7d9f521780..2848fe7723 100644 --- a/account.py +++ b/account.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 InvoiceLine(metaclass=PoolMeta): @@ -86,10 +84,11 @@ class InvoiceLine(metaclass=PoolMeta): Uom = pool.get('product.uom') if (self.unit_price is not None and self.unit and self.secondary_unit and (self.secondary_uom_factor or self.secondary_uom_rate)): - return Uom.compute_price( + unit_price = Uom.compute_price( self.unit, 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 @@ -104,7 +103,8 @@ class InvoiceLine(metaclass=PoolMeta): self.unit_price = Uom.compute_price( self.secondary_unit, self.secondary_unit_price, self.unit, factor=self.secondary_uom_rate, rate=self.secondary_uom_factor - ).quantize(Decimal(1) / 10 ** price_digits[1]) + ) + self.unit_price = round_price(self.unit_price) self.amount = self.on_change_with_amount() @fields.depends(methods=[