diff --git a/addons/stock/stock.py b/addons/stock/stock.py index f7927cabd73..9ae7bbb37a3 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2073,7 +2073,7 @@ class stock_move(osv.osv): raise UserError(_('Cannot unreserve a done move')) quant_obj.quants_unreserve(cr, uid, move, context=context) if not context.get('no_state_change'): - if self.find_move_ancestors(cr, uid, move, context=context): + if move.procure_method == 'make_to_order' or self.find_move_ancestors(cr, uid, move, context=context): self.write(cr, uid, [move.id], {'state': 'waiting'}, context=context) else: self.write(cr, uid, [move.id], {'state': 'confirmed'}, context=context) @@ -2572,7 +2572,7 @@ class stock_move(osv.osv): if len(reserved_quant_ids) == 0 and move.partially_available: vals['partially_available'] = False if move.state == 'assigned': - if self.find_move_ancestors(cr, uid, move, context=context): + if move.procure_method == 'make_to_order' or self.find_move_ancestors(cr, uid, move, context=context): vals['state'] = 'waiting' else: vals['state'] = 'confirmed' diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 62aeb59d065..07d402985d5 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -1621,3 +1621,68 @@ class TestStockFlow(TestStockCommon): # There should be no quant in the inventory loss location quant = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', location_loss.id)]) self.assertEqual(len(quant), 0) + + def test_74_move_state_waiting_mto(self): + """ This test will check that when a move is unreserved, its state changes to 'waiting' if + it has ancestors or if it has a 'procure_method' equal to 'make_to_order' else the state + changes to 'confirmed'. + """ + picking_out = self.PickingObj.create({ + 'partner_id': self.partner_agrolite_id, + 'picking_type_id': self.picking_type_out, + 'location_id': self.stock_location, + 'location_dest_id': self.customer_location}) + move_mto_alone = self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking_out.id, + 'location_id': self.stock_location, + 'location_dest_id': self.customer_location, + 'procure_method':'make_to_order'}) + move_with_ancestors = self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking_out.id, + 'location_id': self.stock_location, + 'location_dest_id': self.customer_location}) + self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking_out.id, + 'location_id': self.stock_location, + 'location_dest_id': self.customer_location, + 'move_dest_id': move_with_ancestors.id}) + other_move = self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking_out.id, + 'location_id': self.stock_location, + 'location_dest_id': self.customer_location}) + + move_mto_alone.action_confirm() + move_with_ancestors.action_confirm() + other_move.action_confirm() + + move_mto_alone.do_unreserve() + move_with_ancestors.do_unreserve() + other_move.do_unreserve() + + self.assertEquals(move_mto_alone.state, "waiting") + self.assertEquals(move_with_ancestors.state, "waiting") + self.assertEquals(other_move.state, "confirmed") + + move_mto_alone.recalculate_move_state() + move_with_ancestors.recalculate_move_state() + other_move.recalculate_move_state() + + self.assertEquals(move_mto_alone.state, "waiting") + self.assertEquals(move_with_ancestors.state, "waiting") + self.assertEquals(other_move.state, "confirmed")