From de44acc019802fe2725c4f08fdf2dcbf70d3b6aa Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Fri, 3 Jan 2025 12:35:23 +0100 Subject: [PATCH] stock_picking_restrict_cancel_printed: fix no backorder Allow to validate a partial picking when the backorder policy is set to never --- .../models/stock_move.py | 3 +++ .../tests/test_stock_picking_restrict_cancel_printed.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/stock_picking_restrict_cancel_printed/models/stock_move.py b/stock_picking_restrict_cancel_printed/models/stock_move.py index 709168b7bd6c..070c99778fe0 100644 --- a/stock_picking_restrict_cancel_printed/models/stock_move.py +++ b/stock_picking_restrict_cancel_printed/models/stock_move.py @@ -9,6 +9,9 @@ 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 diff --git a/stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py b/stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py index f138207c57a3..ff65f68fb015 100644 --- a/stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py +++ b/stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py @@ -28,7 +28,7 @@ def setUpClass(cls): { "name": "Test move", "product_id": cls.product.id, - "product_uom_qty": 1, + "product_uom_qty": 3, "location_id": cls.env.ref("stock.stock_location_stock").id, "location_dest_id": cls.env.ref( "stock.stock_location_customers" @@ -58,3 +58,10 @@ 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()