Skip to content

Commit e59a03b

Browse files
committed
[FIX] sale_exception: add a register_hook to prevent other action_confirm being executed if there is an exception rule
1 parent 3a55bc7 commit e59a03b

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

sale_exception/models/sale_order.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,22 @@ def sale_check_exception(self):
4747
if orders:
4848
orders._check_exception()
4949

50-
def action_confirm(self):
51-
if self.detect_exceptions():
52-
return self._popup_exceptions()
53-
return super().action_confirm()
50+
def _register_hook(self):
51+
ModelClass = self.env.registry["sale.order"]
52+
53+
original_action_confirm = ModelClass.action_confirm
54+
55+
def patched_action_confirm(self):
56+
if self.detect_exceptions():
57+
return self._popup_exceptions()
58+
original_func = patched_action_confirm.origin
59+
return original_func(self)
60+
61+
patched_action_confirm.origin = original_action_confirm
62+
63+
ModelClass.action_confirm = patched_action_confirm
64+
65+
return super()._register_hook()
5466

5567
def action_draft(self):
5668
res = super().action_draft()

sale_exception/tests/test_sale_exception.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class TestSaleException(TransactionCase):
1313
@classmethod
1414
def setUpClass(cls):
1515
super().setUpClass()
16+
cls.env["sale.order"]._register_hook()
17+
cls.env["exception.rule"].search([]).write({"active": False})
1618
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
1719
cls.default_pl = cls.env["product.pricelist"].create(
1820
{

0 commit comments

Comments
 (0)