-
-
Notifications
You must be signed in to change notification settings - Fork 209
[IMP] stock_release_channel: Allow to sleep and reassign pickings #1011
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
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,10 @@ class StockReleaseChannel(models.Model): | |
| compute="_compute_is_action_wake_up_allowed", | ||
| help="Technical field to check if the " "action 'Wake Up' is allowed.", | ||
| ) | ||
| is_action_safe_sleep_allowed = fields.Boolean( | ||
| compute="_compute_is_action_safe_sleep_allowed", | ||
| help="Technical field to check if the action 'Safe Sleep' is allowed.", | ||
| ) | ||
| is_release_allowed = fields.Boolean( | ||
| compute="_compute_is_release_allowed", | ||
| search="_search_is_release_allowed", | ||
|
|
@@ -270,6 +274,13 @@ def _compute_is_release_allowed(self): | |
| for rec in self: | ||
| rec.is_release_allowed = rec.state == "open" and not rec.release_forbidden | ||
|
|
||
| @api.depends("state") | ||
| def _compute_is_action_safe_sleep_allowed(self): | ||
| for rec in self: | ||
| rec.is_action_safe_sleep_allowed = bool( | ||
| rec.state in ["locked", "open"] and rec.open_picking_ids | ||
| ) | ||
|
|
||
rousseldenis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def _compute_show_last_picking_done(self): | ||
| for rec in self: | ||
| rec.show_last_picking_done = ( | ||
|
|
@@ -872,16 +883,33 @@ def action_unlock(self): | |
| self._check_is_action_unlock_allowed() | ||
| self.write({"state": "open"}) | ||
|
|
||
| def action_sleep(self): | ||
| def _sleep(self, safe=False): | ||
| """ | ||
|
|
||
| Allows to make the channels asleep. | ||
|
|
||
| That will unassign all the related pickings, | ||
| unrelease them and then try to reassign them | ||
| Args: | ||
| safe (bool, optional): This will allow to not unrelease | ||
| the pickings that have related done pickings. | ||
| """ | ||
| self._check_is_action_sleep_allowed() | ||
| pickings_to_unassign = self.env["stock.picking"].search( | ||
| self._get_picking_to_unassign_domain() | ||
| ) | ||
| pickings_to_unassign.write({"release_channel_id": False}) | ||
| pickings_to_unassign.unrelease() | ||
| pickings_to_unassign.unrelease(safe_unrelease=safe) | ||
| self.write({"state": "asleep"}) | ||
| pickings_to_unassign._delay_assign_release_channel() | ||
|
|
||
| def action_sleep(self): | ||
| self._sleep() | ||
|
|
||
| def action_safe_sleep(self): | ||
| self._sleep(safe=True) | ||
| return {"type": "ir.actions.act_window_close"} | ||
|
Comment on lines
+906
to
+911
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not add a second button but manage it in existing |
||
|
|
||
| def action_wake_up(self): | ||
| self._check_is_action_wake_up_allowed() | ||
| for rec in self: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright 2025 ACSONE SA/NV (https://acsone.eu) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
|
||
|
|
||
| from .common import ReleaseChannelCase | ||
|
|
||
|
|
||
| class TestReleaseChannelCancel(ReleaseChannelCase): | ||
| def test_release_channel_cancel(self): | ||
| """ | ||
| Create a new channel with a priority filter | ||
| Release the move with that picking priority | ||
|
|
||
| The created channel is assigned to the move picking | ||
|
|
||
| Call the unassign on the channel and check the | ||
| picking is unassigned | ||
|
|
||
| Set the channel to 'asleep' state | ||
| Try to assign the picking | ||
|
|
||
| The default channel should be set | ||
| """ | ||
| self.env.company.recompute_channel_on_pickings_at_release = True | ||
| channel = self._create_channel( | ||
| name="Test Domain", | ||
| sequence=1, | ||
| rule_domain=[("priority", "=", "1")], | ||
| ) | ||
| move = self._create_single_move(self.product1, 10) | ||
| move.picking_id.priority = "1" | ||
| move.release_available_to_promise() | ||
| self.assertEqual(move.picking_id.release_channel_id, channel) | ||
|
|
||
| channel.action_safe_sleep() | ||
| self.assertFalse(move.picking_id.release_channel_id) | ||
|
|
||
| move.release_available_to_promise() | ||
| self.assertEqual(move.picking_id.release_channel_id, self.default_channel) | ||
|
|
||
| def test_release_channel_cancel_after_picking(self): | ||
| """ | ||
| Create a new channel with a priority filter | ||
| Release the move with that picking priority | ||
|
|
||
| The created channel is assigned to the move picking | ||
|
|
||
| Transfer the picking from stock location | ||
|
|
||
| Call the unassign on the channel and check the | ||
| picking is unassigned | ||
|
|
||
| Set the channel to 'asleep' state | ||
| Try to assign the picking | ||
|
|
||
| The default channel should be set | ||
|
|
||
| Transfer the outgoing picking | ||
|
|
||
| Try to unassign it. It should be impossible | ||
|
|
||
| """ | ||
| self.env.company.recompute_channel_on_pickings_at_release = True | ||
| channel = self._create_channel( | ||
| name="Test Domain", | ||
| sequence=1, | ||
| rule_domain=[("priority", "=", "1")], | ||
| ) | ||
| self._update_qty_in_location(self.wh.lot_stock_id, self.product1, 10.0) | ||
| move = self._create_single_move(self.product1, 10) | ||
| move.warehouse_id = self.wh | ||
| move.procure_method = "make_to_order" | ||
| move.rule_id = self.wh.delivery_route_id.rule_ids.filtered( | ||
| lambda rule: rule.location_dest_id == move.location_dest_id | ||
| ) | ||
| move.route_ids = move.rule_id.route_id | ||
| move.picking_id.priority = "1" | ||
| move.need_release = True | ||
| move.invalidate_cache(["ordered_available_to_promise_qty"]) | ||
| move.release_available_to_promise() | ||
| self.assertEqual(move.picking_id.release_channel_id, channel) | ||
|
|
||
| self.assertTrue(move.move_orig_ids) | ||
|
|
||
| move.move_orig_ids.quantity_done = 10.0 | ||
| move.move_orig_ids._action_done() | ||
|
|
||
| channel.action_safe_sleep() | ||
| self.assertFalse(move.picking_id.release_channel_id) | ||
|
|
||
| move.release_available_to_promise() | ||
| self.assertEqual(move.picking_id.release_channel_id, self.default_channel) | ||
|
|
||
| move.quantity_done = 10.0 | ||
| move._action_done() | ||
| self.assertEqual("done", move.state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think checking open_picking_ids is useful