-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by jbaudoux
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>). | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
|
@@ -8,6 +9,7 @@ | |
"category": "Inventory", | ||
"summary": "Prevent canceling a stock transfer if printed.", | ||
"author": "Camptocamp, BCIM, Odoo Community Association (OCA)", | ||
"maintainers": ["jbaudoux"], | ||
"website": "https://github.com/OCA/stock-logistics-workflow", | ||
"license": "AGPL-3", | ||
"depends": ["stock"], | ||
|
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 @@ | ||
from . import stock_move | ||
from . import stock_picking | ||
from . import stock_picking_type |
23 changes: 23 additions & 0 deletions
23
stock_picking_restrict_cancel_printed/models/stock_move.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,23 @@ | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
def _action_cancel(self): | ||
# if picking_type create_backorder is never, then move is canceled on action_done | ||
if self.env.context.get("cancel_backorder"): | ||
return super()._action_cancel() | ||
for move in self: | ||
if ( | ||
move.picking_id.printed | ||
and move.picking_type_id.restrict_cancel_if_printed | ||
): | ||
raise UserError( | ||
_("You cannot cancel a transfer that is already printed.") | ||
) | ||
return super()._action_cancel() |
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,23 +1,39 @@ | ||
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>). | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import Command | ||
from odoo.exceptions import UserError | ||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestResPartnerGetAddress(SavepointCase): | ||
class TestPickingRestrictCancel(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
cls.partner_1 = cls.env.ref("base.res_partner_1") | ||
cls.picking_type = cls.env.ref("stock.picking_type_out") | ||
cls.product = cls.env.ref("product.product_product_5") | ||
cls.picking = cls.env["stock.picking"].create( | ||
{ | ||
"partner_id": cls.partner_1.id, | ||
"picking_type_id": cls.picking_type.id, | ||
"location_id": cls.env.ref("stock.stock_location_stock").id, | ||
"location_dest_id": cls.env.ref("stock.stock_location_customers").id, | ||
"move_ids": [ | ||
Command.create( | ||
{ | ||
"name": "Test move", | ||
"product_id": cls.product.id, | ||
"product_uom_qty": 3, | ||
"location_id": cls.env.ref("stock.stock_location_stock").id, | ||
"location_dest_id": cls.env.ref( | ||
"stock.stock_location_customers" | ||
).id, | ||
} | ||
) | ||
], | ||
} | ||
) | ||
|
||
|
@@ -30,3 +46,20 @@ def test_stock_picking_restrict_cancel_printed_disabled(self): | |
self.picking_type.restrict_cancel_if_printed = False | ||
self.picking.printed = True | ||
self.picking.action_cancel() | ||
|
||
def test_stock_move_restrict_cancel_printed_enabled(self): | ||
self.picking.printed = True | ||
with self.assertRaises(UserError): | ||
self.picking.move_ids._action_cancel() | ||
|
||
def test_stock_move_restrict_cancel_printed_disabled(self): | ||
self.picking_type.restrict_cancel_if_printed = False | ||
self.picking.printed = True | ||
self.picking.move_ids._action_cancel() | ||
|
||
def test_stock_move_restrict_cancel_printed_enabled_nobackorder(self): | ||
"""Check a picking partially processed can be validated when no backorder are created""" | ||
self.picking.printed = True | ||
self.picking.move_ids.quantity_done = 1 | ||
self.picking_type.create_backorder = "never" | ||
self.picking.button_validate() |