From 45704b621838c674fb85fd9fd186f2baa7587b5f Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 29 Sep 2017 14:33:38 +0200 Subject: [PATCH] [FIX] mrp: action_explode We initially only ran action_explode on manufactured move, but it should be for done for classic move to make it work in classic deliveries (confirming a move for a kit should cancel the originl move and add new moves for the kit's components). --- addons/mrp/models/stock_move.py | 4 ++-- addons/sale_mrp/tests/test_sale_mrp_flow.py | 3 ++- addons/stock/models/stock_move.py | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index f26097d6648..966e3365b6c 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -129,8 +129,8 @@ class StockMove(models.Model): return super(StockMove, self)._action_cancel() def _action_confirm(self, merge=True): - moves = self - for move in self.filtered(lambda m: m.production_id): + moves = self.env['stock.move'] + for move in self: moves |= move.action_explode() # we go further with the list of ids potentially changed by action_explode return super(StockMove, moves)._action_confirm(merge=merge) diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index f6a87c7a926..7efdc9a9e7d 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -335,6 +335,8 @@ class TestSaleMrpFlow(common.TransactionCase): self.partner = self.env.ref('base.res_partner_1') self.product = self.env.ref('mrp.product_product_build_kit') self.product.invoice_policy = 'delivery' + # Remove the MTO route as purchase is not installed and since the procurement removal the exception is directly raised + self.product.write({'route_ids': [(6, 0, [self.warehouse.manufacture_pull_id.route_id.id])]}) so_vals = { 'partner_id': self.partner.id, 'partner_invoice_id': self.partner.id, @@ -360,7 +362,6 @@ class TestSaleMrpFlow(common.TransactionCase): wiz_act = pick.button_validate() wiz = self.env[wiz_act['res_model']].browse(wiz_act['res_id']) wiz.process() - self.assertEqual(self.so.invoice_status, 'no', 'Sale MRP: so invoice_status should be "no" after partial delivery of a kit') del_qty = sum(sol.qty_delivered for sol in self.so.order_line) self.assertEqual(del_qty, 0.0, 'Sale MRP: delivered quantity should be zero after partial delivery of a kit') diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index b47ae639c83..1c80d61f316 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1019,6 +1019,8 @@ class StockMove(models.Model): def unlink(self): if any(move.state not in ('draft', 'cancel') for move in self): raise UserError(_('You can only delete draft moves.')) + # With the non plannified picking, draft moves could have some move lines. + self.mapped('move_line_ids').unlink() return super(StockMove, self).unlink() def _prepare_move_split_vals(self, uom_qty):