From 14fbf769da8cd62cf659931b52bedc2367f4b4ee 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 --- production.py | 5 +++-- tryton.cfg | 1 + work.py | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/production.py b/production.py index 5b231df6d1..354e5ddf57 100644 --- a/production.py +++ b/production.py @@ -11,6 +11,8 @@ from trytond.model.exceptions import AccessError from trytond.pyson import Eval, Bool from trytond.transaction import Transaction +from trytond.modules.product import round_price + class Production(metaclass=PoolMeta): __name__ = 'production' @@ -60,8 +62,7 @@ class Production(metaclass=PoolMeta): cycle_cost = Decimal(cycle_cost) cost += cycle_cost - digits = self.__class__.cost.digits - return cost.quantize(Decimal(str(10 ** -digits[1]))) + return round_price(cost) @classmethod @ModelView.button diff --git a/tryton.cfg b/tryton.cfg index d34a0f811c..1bcbcb1c81 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -3,6 +3,7 @@ version=5.5.0 depends: company ir + product production production_routing stock diff --git a/work.py b/work.py index 9e7c20266c..d09912fe5a 100644 --- a/work.py +++ b/work.py @@ -14,7 +14,7 @@ from trytond.pool import Pool from trytond.pyson import Eval, If, Bool from trytond.transaction import Transaction -from trytond.modules.product import price_digits +from trytond.modules.product import price_digits, round_price from .exceptions import PickerError @@ -314,7 +314,6 @@ class WorkCycle(Workflow, ModelSQL, ModelView): if center.cost_method == 'cycle': self.cost = center.cost_price elif center.cost_method == 'hour': - digits = self.__class__.cost.digits hours = self.duration.total_seconds() / (60 * 60) self.cost = center.cost_price * Decimal(str(hours)) - self.cost = self.cost.quantize(Decimal(str(10 ** -digits[1]))) + self.cost = round_price(self.cost)