From 91a4fb45209d20e2edbe3f1a39e71284d0e7787a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6ftner?= Date: Mon, 10 Dec 2012 00:19:32 +0100 Subject: [PATCH] proper rounding for unit_price in Production.set_moves review600003 issue2904 (transplanted from 7191832dfd42adc565d3f28b64793b2b7beb9e41) --- production.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/production.py b/production.py index e5dce450c7..f0a2c08f08 100644 --- a/production.py +++ b/production.py @@ -385,6 +385,10 @@ class Production(Workflow, ModelSQL, ModelView): return cost def set_moves(self): + pool = Pool() + Template = pool.get('product.template') + Product = pool.get('product.product') + storage_location = self.warehouse.storage_location location = self.location company = self.company @@ -412,6 +416,11 @@ class Production(Workflow, ModelSQL, ModelView): move.save() cost += Decimal(str(quantity)) * product.cost_price + if hasatttr(Product, 'cost_price'): + digits = Product.cost_price.digits + else: + digits = Template.cost_price.digits + for output in self.bom.outputs: quantity = output.compute_quantity(factor) product = output.product @@ -420,7 +429,9 @@ class Production(Workflow, ModelSQL, ModelView): if move: move.production_output = self if product == self.product: - move.unit_price = cost / Decimal(str(quantity)) + move.unit_price = Decimal( + cost / Decimal(str(quantity)) + ).quantize(Decimal(str(10 ** -digits[1]))) move.save() self._set_move_planned_date()