Skip to content

Commit

Permalink
fixup! fixup! Fix stock_release_channel_auto_release backward port to 14
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Feb 14, 2023
1 parent 31d15b0 commit cb38676
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
14 changes: 6 additions & 8 deletions stock_available_to_promise_release/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class StockPicking(models.Model):

set_printed_at_release = fields.Boolean(compute="_compute_set_printed_at_release")

@api.depends("move_ids")
@api.depends("move_lines")
def _compute_set_printed_at_release(self):
for picking in self:
picking.set_printed_at_release = not (
any(picking.move_ids.mapped("rule_id.no_backorder_at_release"))
any(picking.move_lines.mapped("rule_id.no_backorder_at_release"))
)

@api.depends("move_ids.need_release")
@api.depends("move_lines.need_release")
def _compute_need_release(self):
data = self.env["stock.move"].read_group(
[("need_release", "=", True), ("picking_id", "in", self.ids)],
Expand Down Expand Up @@ -161,17 +161,15 @@ def _after_release_update_chain(self):
self._after_release_set_last_release_date()
self._after_release_set_expected_date()

def _after_release_set_printed(self):
self.filtered(
lambda p: not p.printed and p.set_printed_at_release
).printed = True
def _after_release_set_last_release_date(self):
self.last_release_date = fields.Datetime.now()

def _after_release_set_expected_date(self):
prep_time = self.env.company.stock_release_max_prep_time
new_expected_date = fields.Datetime.add(
fields.Datetime.now(), minutes=prep_time
)
move_to_update = self.move_ids.filtered(lambda m: m.state == "assigned")
move_to_update = self.move_lines.filtered(lambda m: m.state == "assigned")
move_to_update_ids = move_to_update.ids
for origin_moves in move_to_update._get_chained_moves_iterator("move_dest_ids"):
move_to_update_ids += origin_moves.ids
Expand Down
18 changes: 9 additions & 9 deletions stock_available_to_promise_release/tests/test_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def test_defer_creation_no_backorder_partial_available(self):
self.assertEqual(len(pickings), 1, "expect only the last out->customer")

cust_picking = pickings
move_state = cust_picking.mapped("move_ids").mapped("state")
move_state = cust_picking.mapped("move_lines").mapped("state")
self.assertTrue(len(move_state) == 1 and move_state[0] == "waiting")
self.assertEqual(cust_picking.state, "waiting")
self.assertRecordValues(
Expand Down Expand Up @@ -757,11 +757,11 @@ def test_defer_creation_no_backorder_partial_available(self):
# the released customer picking is not set to "printed"
self.assertRecordValues(cust_picking, [{"printed": False}])

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

# the splite moves remains into the customer picking
self.assertRecordValues(
cust_picking.move_ids,
cust_picking.move_lines,
[
{"product_qty": 7.0, "state": "waiting"},
{"product_qty": 13.0, "state": "waiting"},
Expand All @@ -773,7 +773,7 @@ def test_defer_creation_no_backorder_partial_available(self):
self.assertRecordValues(out_picking, [{"state": "done"}])
self.assertRecordValues(cust_picking, [{"state": "assigned"}])
self.assertRecordValues(
cust_picking.move_ids,
cust_picking.move_lines,
[
{
"state": "assigned",
Expand All @@ -798,7 +798,7 @@ def test_defer_creation_no_backorder_partial_available(self):
)
self.assertEqual(len(cust_backorder), 1)

self.env["stock.move"].invalidate_model(
self.env["stock.move"].invalidate_cache(
fnames=[
"previous_promised_qty",
"ordered_available_to_promise_uom_qty",
Expand All @@ -810,7 +810,7 @@ def test_defer_creation_no_backorder_partial_available(self):
cust_backorder.release_available_to_promise()
self.assertEqual(len(self._pickings_in_group(cust_picking.group_id)), 3)

self.env["stock.move"].invalidate_model(
self.env["stock.move"].invalidate_cache(
fnames=[
"previous_promised_qty",
"ordered_available_to_promise_uom_qty",
Expand All @@ -828,7 +828,7 @@ def test_defer_creation_no_backorder_partial_available(self):
- out_picking
)
self.assertRecordValues(
out_backorder.move_ids,
out_backorder.move_lines,
[
{
"state": "assigned",
Expand Down Expand Up @@ -876,7 +876,7 @@ def test_defer_creation_no_backorder_not_available(self):
backorder = cust_picking.backorder_ids
self.assertFalse(backorder)
self.assertRecordValues(
cust_picking.move_ids.sorted("id"),
cust_picking.move_lines.sorted("id"),
[
# product 1 is partially available -> split
{
Expand Down Expand Up @@ -922,7 +922,7 @@ def test_defer_creation_no_backorder_not_available(self):
],
)
self.assertRecordValues(
out_picking.move_ids,
out_picking.move_lines,
[
{"product_qty": 10.0, "product_id": self.product1.id},
{"product_qty": 10.0, "product_id": self.product2.id},
Expand Down

0 comments on commit cb38676

Please sign in to comment.