[FIX] stock: MTO move status

When we validate a SO with an MTO product, then an RFQ and a delivery
picking are created. The status of the delivery picking is in state
'confirmed', but should be 'waiting' as the delivery waits for a
specific delivery input.

The problem is caused by the unreserve method, which is called in the
'procurement_jit' module. This method only checks that a move has
ancestors to determine if the move should be in waiting or in confirmed,
which is not the case for our delivery move because the RFQ has not been
validated yet so there is not ancestors yet.

To fix this issue, we check the 'procure_method' of the move, and if it
is in 'make_to_order' we put it in 'waiting' instead of 'confirmed'.

We also fixed the function recalculate_move_state that could cause the
same problem.
This commit is contained in:
Pierre Masereel
2017-07-24 10:53:36 +02:00
committed by pimodoo
parent 7333f5e9b8
commit e2a255717f
2 changed files with 67 additions and 2 deletions
+2 -2
View File
@@ -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'
+65
View File
@@ -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")