forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_available_to_promise_release: Add unrelease action on rel…
…eased moves
- Loading branch information
Showing
12 changed files
with
319 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
stock_available_to_promise_release/security/ir.model.access.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_stock_release_wizard,access.stock.release.wizard,model_stock_release,stock.group_stock_user,1,1,1,0 | ||
access_stock_unrelease_wizard,access.stock.unrelease.wizard,model_stock_unrelease,stock.group_stock_user,1,1,1,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_reservation | ||
from . import test_unrelease |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
stock_available_to_promise_release/tests/test_unrelease.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2022 ACSONE SA/NV (https://www.acsone.eu) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
from contextlib import contextmanager | ||
from datetime import datetime | ||
|
||
from odoo.exceptions import UserError | ||
|
||
from .common import PromiseReleaseCommonCase | ||
|
||
|
||
class TestAvailableToPromiseRelease(PromiseReleaseCommonCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.shipping = cls._out_picking( | ||
cls._create_picking_chain( | ||
cls.wh, [(cls.product1, 5)], date=datetime(2019, 9, 2, 16, 0) | ||
) | ||
) | ||
cls._update_qty_in_location(cls.loc_bin1, cls.product1, 15.0) | ||
cls.wh.delivery_route_id.write( | ||
{ | ||
"available_to_promise_defer_pull": True, | ||
"no_backorder_at_release": True, | ||
} | ||
) | ||
|
||
cls.shipping.release_available_to_promise() | ||
cls.picking = cls._prev_picking(cls.shipping) | ||
cls.picking.action_assign() | ||
|
||
@contextmanager | ||
def _assert_full_unreleased(self): | ||
self.assertRecordValues( | ||
self.shipping.move_ids, | ||
[ | ||
{ | ||
"state": "waiting", | ||
"need_release": False, | ||
"unrelease_allowed": True, | ||
} | ||
], | ||
) | ||
yield | ||
self.assertRecordValues( | ||
self.shipping.move_ids, | ||
[ | ||
{ | ||
"state": "waiting", | ||
"need_release": True, | ||
"unrelease_allowed": False, | ||
} | ||
], | ||
) | ||
self.assertEqual(self.picking.move_ids.state, "cancel") | ||
self.assertEqual(self.picking.state, "cancel") | ||
|
||
def test_unrelease_full(self): | ||
"""Unrelease all moves of a released ship. The pick should be deleted and | ||
the moves should be mark as to release""" | ||
with self._assert_full_unreleased(): | ||
self.shipping.move_ids.unrelease() | ||
|
||
# I can release again the move and a new pick is created | ||
self.shipping.release_available_to_promise() | ||
new_picking = self._prev_picking(self.shipping) - self.picking | ||
self.assertTrue(new_picking) | ||
self.assertEqual(new_picking.state, "assigned") | ||
|
||
def test_unrelease_partially_processed_move(self): | ||
"""Check it's not possible to unrelease a move that has been partially | ||
processed""" | ||
line = self.picking.move_ids.move_line_ids | ||
line.qty_done = line.reserved_qty - 1 | ||
self.picking.with_context( | ||
skip_immediate=True, skip_backorder=True | ||
).button_validate() | ||
self.assertEqual(self.picking.state, "done") | ||
self.assertFalse(self.shipping.move_ids.unrelease_allowed) | ||
with self.assertRaisesRegex( | ||
UserError, "You are not allowed to unrelease this move" | ||
): | ||
self.shipping.move_ids.unrelease() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import stock_release | ||
from . import stock_unrelease |
19 changes: 19 additions & 0 deletions
19
stock_available_to_promise_release/wizards/stock_unrelease.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2023 ACSONE SA/NV (https://www.acsone.eu) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockUnRelease(models.TransientModel): | ||
_name = "stock.unrelease" | ||
_description = "Stock Allocations Un Release" | ||
|
||
def unrelease(self): | ||
model = self.env.context.get("active_model") | ||
if model not in ("stock.move", "stock.picking"): | ||
return | ||
records = ( | ||
self.env[model].browse(self.env.context.get("active_ids", [])).exists() | ||
) | ||
records.unrelease(safe_unrelease=True) | ||
return {"type": "ir.actions.act_window_close"} |
41 changes: 41 additions & 0 deletions
41
stock_available_to_promise_release/wizards/stock_unrelease_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="view_stock_unrelease_form" model="ir.ui.view"> | ||
<field name="name">Stock Allocations Un Release</field> | ||
<field name="model">stock.unrelease</field> | ||
<field name="arch" type="xml"> | ||
<form string="Stock Allocations Un Release"> | ||
<p class="oe_grey"> | ||
The selected records will be un released. | ||
</p> | ||
<footer> | ||
<button | ||
name="unrelease" | ||
string="Un Release" | ||
type="object" | ||
class="btn-primary" | ||
/> | ||
<button string="Cancel" class="btn-secondary" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
<record id="action_view_stock_move_unrelease_form" model="ir.actions.act_window"> | ||
<field name="name">Un Release Move Allocations</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">stock.unrelease</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field name="groups_id" eval="[(4,ref('stock.group_stock_user'))]" /> | ||
<field name="binding_model_id" ref="stock.model_stock_move" /> | ||
</record> | ||
<record id="action_view_stock_picking_unrelease_form" model="ir.actions.act_window"> | ||
<field name="name">Un Release Transfers Allocations</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">stock.unrelease</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field name="groups_id" eval="[(4,ref('stock.group_stock_user'))]" /> | ||
<field name="binding_model_id" ref="stock.model_stock_picking" /> | ||
</record> | ||
</odoo> |