changeset a3b11530ef77 in modules/production_work:default
details:
https://hg.tryton.org/modules/production_work?cmd=changeset;node=a3b11530ef77
description:
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
diffstat:
production.py | 5 +++--
tryton.cfg | 1 +
work.py | 5 ++---
3 files changed, 6 insertions(+), 5 deletions(-)
diffs (54 lines):
diff -r 7268db8d6f9b -r a3b11530ef77 production.py
--- a/production.py Thu Mar 19 19:07:08 2020 +0100
+++ b/production.py Thu Apr 23 21:44:00 2020 +0200
@@ -11,6 +11,8 @@
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 @@
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 -r 7268db8d6f9b -r a3b11530ef77 tryton.cfg
--- a/tryton.cfg Thu Mar 19 19:07:08 2020 +0100
+++ b/tryton.cfg Thu Apr 23 21:44:00 2020 +0200
@@ -3,6 +3,7 @@
depends:
company
ir
+ product
production
production_routing
stock
diff -r 7268db8d6f9b -r a3b11530ef77 work.py
--- a/work.py Thu Mar 19 19:07:08 2020 +0100
+++ b/work.py Thu Apr 23 21:44:00 2020 +0200
@@ -14,7 +14,7 @@
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 @@
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)