Skip to content

Commit

Permalink
stock_available_to_promise_release: split picking on release
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Mar 20, 2020
1 parent fc78dc3 commit dd75c76
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
23 changes: 22 additions & 1 deletion stock_available_to_promise_release/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ def _run_stock_rule(self):
# we don't want to deliver unless we can deliver all at
# once
continue
move.with_context(release_available_to_promise=True)._split(remaining)
move.with_context(release_available_to_promise=True)._release_split(
remaining
)

if not move.picking_id.printed:
# Make sure the flag is set even if no split happens.
move.picking_id.printed = True

values = move._prepare_procurement_values()
procurement_requests.append(
Expand All @@ -168,3 +174,18 @@ def _run_stock_rule(self):
pulled_moves = pulled_moves.mapped("move_orig_ids")

return True

def _release_split(self, remaining_qty):
"""Split move and create a new picking for it.
Instead of splitting the move and leave remaining qty into the same picking
we move it to a new one so that we can release it later as soon as
the qty is available.
"""
# Rely on `printed` flag to make _assign_picking create a new picking.
# See `stock.move._assign_picking` and
# `stock.move._search_picking_for_assignation`.
self.picking_id.printed = True
new_move = self.browse(self._split(remaining_qty))
new_move._assign_picking()
return new_move
53 changes: 49 additions & 4 deletions stock_available_to_promise_release/tests/test_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,17 @@ def test_defer_creation_backorder(self):
)

cust_picking.release_available_to_promise()
out_pickings = sorted(
self._pickings_in_group(pickings.group_id) - cust_picking,
key=lambda x: x.move_lines.product_qty,
)
# 2 pickings instead of just one because remaining qty to process
# is split into a new one.
self.assertEqual(len(out_pickings), 2)
out_picking = out_pickings[0]
split_out_picking = out_pickings[1]

out_picking = self._pickings_in_group(pickings.group_id) - cust_picking

# the complete one is assigned and placed into stock output
self.assertRecordValues(
out_picking,
[
Expand All @@ -355,9 +363,22 @@ def test_defer_creation_backorder(self):
}
],
)
# the split once stays in the original location
self.assertRecordValues(
split_out_picking,
[
{
"state": "waiting",
"location_id": self.wh.wh_output_stock_loc_id.id,
"location_dest_id": self.loc_customer.id,
}
],
)

self.assertRecordValues(out_picking.move_lines, [{"product_qty": 7.0}])
self.assertRecordValues(split_out_picking.move_lines, [{"product_qty": 13.0}])

# let's deliver what we can
self._deliver(out_picking)
self.assertRecordValues(out_picking, [{"state": "done"}])

Expand All @@ -371,6 +392,12 @@ def test_defer_creation_backorder(self):
"reserved_availability": 7.0,
"procure_method": "make_to_order",
},
],
)
self.assertRecordValues(split_out_picking, [{"state": "waiting"}])
self.assertRecordValues(
split_out_picking.move_lines,
[
{
"state": "waiting",
"product_qty": 13.0,
Expand Down Expand Up @@ -494,8 +521,15 @@ def test_defer_creation_uom(self):
)

cust_picking.move_lines.release_available_to_promise()
out_picking = self._pickings_in_group(pickings.group_id) - cust_picking

out_pickings = sorted(
self._pickings_in_group(pickings.group_id) - cust_picking,
key=lambda x: x.move_lines.product_qty,
)
# 2 pickings instead of just one because remaining qty to process
# is split into a new one.
self.assertEqual(len(out_pickings), 2)
out_picking = out_pickings[0]
split_out_picking = out_pickings[1]
self.assertRecordValues(
out_picking.move_lines,
[
Expand All @@ -507,6 +541,17 @@ def test_defer_creation_uom(self):
}
],
)
self.assertRecordValues(
split_out_picking.move_lines,
[
{
"state": "waiting",
"product_qty": 12.0,
"reserved_availability": 0.0,
"product_uom_qty": 1.0,
}
],
)

def test_mto_picking(self):
self.wh.delivery_route_id.write({"available_to_promise_defer_pull": True})
Expand Down

0 comments on commit dd75c76

Please sign in to comment.