diff --git a/mrp_production_real_cost/models/stock_move.py b/mrp_production_real_cost/models/stock_move.py index 227e8a2b2..a903fe839 100644 --- a/mrp_production_real_cost/models/stock_move.py +++ b/mrp_production_real_cost/models/stock_move.py @@ -27,11 +27,13 @@ class StockMove(models.Model): record.work_order.routing_wc_line.routing_id.code or '', record.product_id.default_code or '', _('MAT')]) + amount = (-record.product_id.standard_price * record.product_qty) + if record.product_id.cost_method == 'real': + amount = sum([-x.cost * x.qty for x in record.quant_ids]) analytic_vals = (production._prepare_real_cost_analytic_line( journal_id, name, production, record.product_id, workorder=record.work_order, qty=record.product_qty, - amount=(-record.product_id.standard_price * - record.product_qty))) + amount=amount)) task = task_obj.search([('mrp_production_id', '=', production.id), ('workorder', '=', False)]) analytic_vals['task_id'] = task and task[0].id or False diff --git a/mrp_production_real_cost/tests/test_mrp_production_real_cost.py b/mrp_production_real_cost/tests/test_mrp_production_real_cost.py index 09b7ec911..8e5b2eae0 100644 --- a/mrp_production_real_cost/tests/test_mrp_production_real_cost.py +++ b/mrp_production_real_cost/tests/test_mrp_production_real_cost.py @@ -72,6 +72,7 @@ class TestMrpProductionRealCost(common.TransactionCase): initial_price, self.production.product_id.standard_price) def test_produce_real(self): + self.production.move_lines[:1].product_id.cost_method = 'real' self.production.product_id.cost_method = 'real' for line in self.production.workcenter_lines: line.signal_workflow('button_start_working')