From 3443879831b1c4bce49ee37731b4bc8fea21f28c Mon Sep 17 00:00:00 2001 From: agaldona Date: Tue, 19 Dec 2017 14:41:38 +0100 Subject: [PATCH] [IMP] mrp_production_real_cost: calculate of unit cost taking into account real produced quantity --- mrp_production_real_cost/models/mrp_production.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mrp_production_real_cost/models/mrp_production.py b/mrp_production_real_cost/models/mrp_production.py index c31aa1384..a35c37fba 100644 --- a/mrp_production_real_cost/models/mrp_production.py +++ b/mrp_production_real_cost/models/mrp_production.py @@ -17,8 +17,12 @@ class MrpProduction(models.Model): cost_lines = production.analytic_line_ids.filtered( lambda l: l.amount < 0) production.real_cost = -sum(cost_lines.mapped('amount')) - production.unit_real_cost = ( - production.real_cost / production.product_qty) + something_done = production.move_created_ids2.filtered( + lambda x: x.state == 'done') + qty = (something_done and + sum(something_done.mapped('product_uom_qty')) or + production.product_qty) + production.unit_real_cost = (production.real_cost / qty) analytic_line_ids = fields.One2many( comodel_name="account.analytic.line", inverse_name="mrp_production_id",