From 9337d10d5cf1f223df46ec5df382fa049106fc15 Mon Sep 17 00:00:00 2001 From: agaldona Date: Tue, 15 Nov 2016 17:31:42 +0100 Subject: [PATCH] [IMP] mrp_production_real_cost: load production unit cost in final product quants --- mrp_production_real_cost/models/stock_move.py | 5 +++++ .../tests/test_mrp_production_real_cost.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/mrp_production_real_cost/models/stock_move.py b/mrp_production_real_cost/models/stock_move.py index 011cd28fa..227e8a2b2 100644 --- a/mrp_production_real_cost/models/stock_move.py +++ b/mrp_production_real_cost/models/stock_move.py @@ -75,6 +75,11 @@ class StockMove(models.Model): for product_id, product_data in products.iteritems(): new_price = self._new_average_price(product_data) product_data['product'].sudo().standard_price = new_price + real_moves = self.filtered( + lambda x: (x.production_id and x.product_id.cost_method == 'real')) + for move in real_moves: + move.mapped('quant_ids').write({'cost': + move.production_id.unit_real_cost}) @api.model def get_price_unit(self, move): 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 532c7b37c..09b7ec911 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 @@ -71,6 +71,19 @@ class TestMrpProductionRealCost(common.TransactionCase): self.assertNotEqual( initial_price, self.production.product_id.standard_price) + def test_produce_real(self): + self.production.product_id.cost_method = 'real' + for line in self.production.workcenter_lines: + line.signal_workflow('button_start_working') + line.operation_time_lines[-1].start_date = self.start_date + line.operation_time_lines[-1].end_date = ( + self.start_date + (timedelta(hours=3))) + self.production.action_produce( + self.production.id, self.production.product_qty, 'consume_produce') + self.assertTrue(self.production.unit_real_cost) + for quant in self.production.mapped('move_created_ids2.quant_ids'): + self.assertEqual(quant.cost, self.production.unit_real_cost) + def test_onchange_lines_default(self): workcenter0 = self.browse_ref('mrp.mrp_workcenter_0') routing = self.env['mrp.routing.workcenter'].new({