Skip to content

Commit

Permalink
[IMP] stock_available_to_promise_release: Don't release reserved avai…
Browse files Browse the repository at this point in the history
…lable qty
  • Loading branch information
lmignon committed Oct 17, 2024
1 parent 4db5838 commit 3391a78
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stock_available_to_promise_release/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _run_stock_rule(self):
procurement_requests.append(
self.env["procurement.group"].Procurement(
move.product_id,
move.product_uom_qty,
move.product_uom_qty - move.reserved_availability,
move.product_uom,
move.location_id,
move.rule_id and move.rule_id.name or "/",
Expand Down
38 changes: 38 additions & 0 deletions stock_available_to_promise_release/tests/test_unrelease_2steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,41 @@ def test_cancel_pick(self):
self.assertFalse(self.shipping1.need_release)
self.picking1.action_cancel()
self.assertTrue(self.shipping1.need_release)

def test_cancel_partial_pick(self):
# In this tests we partially process a picking then confirm it.
# We cancel the backorder and check that the shippings is set to need_release
# We then release the shippings again and check that the backorder is created
# for the remaining qty only
self.assertFalse(self.shipping1.need_release)
self.assertFalse(self.shipping2.need_release)
original_qty = self.picking1.move_ids.product_uom_qty
self.assertGreater(original_qty, 1)
self.picking1.move_line_ids[0].qty_done = 1
self.picking1._action_done()
self.assertEqual(self.shipping1.move_ids.state, "partially_available")
# get the backorder
backorder_pick = self._prev_picking(self.shipping1).filtered(
lambda p: p.state == "assigned"
)
self.assertTrue(backorder_pick)
backorder_pick.action_assign()
self.assertEqual(backorder_pick.move_ids.state, "assigned")
# the backorder should have only one move for the remaining qty
self.assertEqual(backorder_pick.move_ids.product_uom_qty, original_qty - 1)
# we cancel the backorder
backorder_pick.action_cancel()
# the shipping should be set to need_release
self.assertTrue(self.shipping1.need_release)
self.assertTrue(self.shipping2.need_release)
# the shipping move should still be partially available
self.assertEqual(self.shipping1.move_ids.state, "partially_available")
self.assertEqual(self.shipping2.move_ids.state, "waiting")
# and if we release it again, the backorder should be created
# for the remaining qty
self.deliveries.release_available_to_promise()
backorder_pick = self._prev_picking(self.shipping1).filtered(
lambda p: p.state == "assigned"
)
self.assertTrue(backorder_pick)
self.assertEqual(backorder_pick.move_ids.product_uom_qty, original_qty - 1)

0 comments on commit 3391a78

Please sign in to comment.