changeset 35afec960bc8 in modules/production:default
details:
https://hg.tryton.org/modules/production?cmd=changeset;node=35afec960bc8
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 | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diffs (41 lines):
diff -r 181990035a27 -r 35afec960bc8 production.py
--- a/production.py Mon Apr 20 14:00:59 2020 +0200
+++ b/production.py Thu Apr 23 21:44:00 2020 +0200
@@ -12,7 +12,7 @@
from trytond.transaction import Transaction
from trytond.modules.company.model import employee_field, set_employee
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
BOM_CHANGES = ['bom', 'product', 'quantity', 'uom', 'warehouse', 'location',
'company', 'inputs', 'outputs']
@@ -426,9 +426,7 @@
else:
cost_price = input_.product.cost_price
cost += (Decimal(str(input_.internal_quantity)) * cost_price)
-
- digits = self.__class__.cost.digits
- return cost.quantize(Decimal(str(10 ** -digits[1])))
+ return round_price(cost)
@fields.depends('inputs')
def on_change_with_cost(self):
@@ -522,7 +520,6 @@
Uom = pool.get('product.uom')
Move = pool.get('stock.move')
- digits = Decimal(str(10 ** -Move.unit_price.digits[1]))
moves = []
for production in productions:
sum_ = Decimal(0)
@@ -554,8 +551,7 @@
else:
ratio = Decimal(1) / len(production.outputs)
quantity = Decimal(str(output.quantity))
- unit_price = (
- production.cost * ratio / quantity).quantize(digits)
+ unit_price = round_price(production.cost * ratio / quantity)
if output.unit_price != unit_price:
output.unit_price = unit_price
moves.append(output)