Skip to content

Commit

Permalink
Merge PR #1827 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Jan 13, 2025
2 parents 8f8b426 + c1c68d3 commit 5d25c9f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions stock_picking_restrict_cancel_printed/__manifest__.py
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).

{
Expand All @@ -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"],
Expand Down
1 change: 1 addition & 0 deletions stock_picking_restrict_cancel_printed/models/__init__.py
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 stock_picking_restrict_cancel_printed/models/stock_move.py
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()
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,
}
)
],
}
)

Expand All @@ -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()

0 comments on commit 5d25c9f

Please sign in to comment.