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 939b1b607a
commit 14fbf769da
3 changed files with 6 additions and 5 deletions
+3 -2
View File
@@ -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
+1
View File
@@ -3,6 +3,7 @@ version=5.5.0
depends:
company
ir
product
production
production_routing
stock
+2 -3
View File
@@ -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)