Skip to content
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

[14.0][FIX] stock_picking_restrict_cancel backport fixes from 16.0 #1827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(

Check warning on line 20 in stock_picking_restrict_cancel_printed/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/models/stock_move.py#L20

Added line #L20 was not covered by tests
_("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")

Check warning on line 17 in stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py#L17

Added line #L17 was not covered by tests
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 @@
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()

Check warning on line 53 in stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py#L50-L53

Added lines #L50 - L53 were not covered by tests

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()

Check warning on line 58 in stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py#L55-L58

Added lines #L55 - L58 were not covered by tests

def test_stock_move_restrict_cancel_printed_enabled_nobackorder(self):

Check warning on line 60 in stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py#L60

Added line #L60 was not covered by tests
"""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()

Check warning on line 65 in stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_restrict_cancel_printed/tests/test_stock_picking_restrict_cancel_printed.py#L62-L65

Added lines #L62 - L65 were not covered by tests
Loading