From 13e653b3e371c0ffee6468ad9f2dac17747c1bfa Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 15 Jan 2014 21:01:27 +0100 Subject: [PATCH] Use work_center category for calculating cost if no work center is defined --- operation.py | 5 ++++- tests/scenario_production_operation.rst | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/operation.py b/operation.py index e71613a..c614bac 100644 --- a/operation.py +++ b/operation.py @@ -187,7 +187,8 @@ class OperationTracking(ModelSQL, ModelView): def get_cost(self, name): Uom = Pool().get('product.uom') - work_center = self.operation.work_center + work_center = (self.operation.work_center or + self.operation.work_center_category) if not work_center: return Decimal('0.0') quantity = Uom.compute_qty(self.uom, self.quantity, @@ -293,6 +294,8 @@ class Production: for production in productions: operation_cost = sum(o.cost for o in production.operations) + if operation_cost == Decimal('0.0'): + continue total_quantity = Decimal(str(sum(o.quantity for o in production.outputs))) added_unit_price = Decimal(operation_cost / total_quantity diff --git a/tests/scenario_production_operation.rst b/tests/scenario_production_operation.rst index 3df50ef..719cf2c 100644 --- a/tests/scenario_production_operation.rst +++ b/tests/scenario_production_operation.rst @@ -243,6 +243,8 @@ Make a production:: >>> production.reload() >>> all(i.state == 'done' for i in production.inputs) True + >>> all(o.state == 'waiting' for o in production.operations) + True >>> Production.done([production.id], config.context) Traceback (most recent call last): ...