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
This commit is contained in:
Cédric Krier
2020-04-23 21:44:00 +02:00
parent 4c26ae123b
commit 9d7d8843c7
+3 -3
View File
@@ -1,7 +1,6 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import hashlib
from decimal import Decimal
from itertools import groupby
from trytond.i18n import gettext
@@ -9,6 +8,8 @@ from trytond.model import ModelView, Workflow, fields
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool, If
from trytond.modules.product import round_price
from .exceptions import PurchaseWarning
@@ -123,8 +124,7 @@ class Production(metaclass=PoolMeta):
cost += Currency.compute(
line.purchase.currency, line.amount,
self.company.currency, round=False)
digits = self.__class__.cost.digits
return cost.quantize(Decimal(str(10 ** -digits[1])))
return round_price(cost)
@classmethod
@ModelView.button