Skip to content

Commit

Permalink
[FIX] stock: MTO move status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pimodoo committed Jul 24, 2017
1 parent 7333f5e commit e2a2557
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/stock/stock.py
Expand Up @@ -2073,7 +2073,7 @@ def do_unreserve(self, cr, uid, move_ids, context=None):
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)
Expand Down Expand Up @@ -2572,7 +2572,7 @@ def recalculate_move_state(self, cr, uid, move_ids, context=None):
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'
Expand Down
65 changes: 65 additions & 0 deletions addons/stock/tests/test_stock_flow.py
Expand Up @@ -1621,3 +1621,68 @@ def test_inventory_adjustment_and_negative_quants_2(self):
# 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")

0 comments on commit e2a2557

Please sign in to comment.