[FIX] stock: state of DO for an MTO product

When confirming a quotation for an MTO product, the state of the
delivery order goes from draft to waiting another operation to waiting
while it should stays in waiting another operation.

If procurement_jit is enabled, confirming a sale order line will
unreserve and rereserve the pickings associated (see
`action_launch_procurement_rule` override). Unreserving a picking will
always set its state to "confirmed", which is wrong if it should be in
"waiting another operation". Not writing on state (which is a computed
field) and let the depends call _compute_state fixes the issue.

The unreserve/rereserve thing is probably useless and is a remain of the
previous stock implementation where it was not possible to complete the
reservation of a move without wiping all its current reservation.
Another commit will improve this part of the code.

opw-801588
This commit is contained in:
Simon Lejeune
2017-12-29 15:56:30 +01:00
parent 88afd055cf
commit 652f8746d6
2 changed files with 19 additions and 4 deletions
+2 -4
View File
@@ -666,10 +666,8 @@ class Picking(models.Model):
@api.multi
def do_unreserve(self):
for move in self:
for move_line in move.move_lines:
move_line._do_unreserve()
self.write({'state': 'confirmed'})
for picking in self:
picking.move_lines._do_unreserve()
@api.multi
def button_validate(self):
+17
View File
@@ -648,6 +648,23 @@ class TestPickShip(TestStockCommon):
self.assertEqual(picking_client.move_lines.state, 'confirmed', 'The move should be confirmed since all the origin moves are processed.')
self.assertEqual(picking_client.state, 'confirmed', 'The picking should be confirmed since all the moves are confirmed.')
def test_unreserve(self):
picking_pick, picking_client = self.create_pick_ship()
self.assertEqual(picking_pick.state, 'confirmed')
picking_pick.do_unreserve()
self.assertEqual(picking_pick.state, 'confirmed')
location = self.env['stock.location'].browse(self.stock_location)
self.env['stock.quant']._update_available_quantity(self.productA, location, 10.0)
picking_pick.action_assign()
self.assertEqual(picking_pick.state, 'assigned')
picking_pick.do_unreserve()
self.assertEqual(picking_pick.state, 'confirmed')
self.assertEqual(picking_client.state, 'waiting')
picking_client.do_unreserve()
self.assertEqual(picking_client.state, 'waiting')
class TestSinglePicking(TestStockCommon):
def test_backorder_1(self):