Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0] stock_available_to_promise_release: split picking on release #19

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 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,22 @@ 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`.
if not self.picking_id.printed:
self.picking_id.printed = True
new_move = self.browse(self._split(remaining_qty))
# Picking assignment is needed here because `_split` copies the move
# thus the `_should_be_assigned` condition is not satisfied
# and the move is not assigned.
new_move._assign_picking()
simahawk marked this conversation as resolved.
Show resolved Hide resolved
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