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 committed 2020-04-23 21:44:00 +02:00
1 parent 0f30e6a5a9
commit c2e88a2651
1 file changed
+3 -7
+3 -7
View File
@@ -12,7 +12,7 @@ from trytond.pool import Pool
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 @@ class Production(Workflow, ModelSQL, ModelView):
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 @@ class Production(Workflow, ModelSQL, ModelView):
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 @@ class Production(Workflow, ModelSQL, ModelView):
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)