Skip to content
Open
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
13 changes: 8 additions & 5 deletions base_exception/models/base_exception_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ def _detect_exceptions(self, rule_info):
elif rule_info.exception_type == "by_method":
return self._detect_exceptions_by_method(rule_info)

def _get_base_domain(self):
return [("ignore_exception", "=", False)]
def _get_base_domain(self, rule_info=None):
domain = [("ignore_exception", "=", False)]
if rule_info is not None and rule_info.filter_domain:
domain = expression.AND([domain, safe_eval(rule_info.filter_domain)])
return domain

def _detect_exceptions_by_py_code(self, rule_info):
"""
Find exceptions found on self.
"""
domain = self._get_base_domain()
domain = self._get_base_domain(rule_info=rule_info)
records = self.filtered_domain(domain)
records_with_exception = self.env[self._name]
for record in records:
Expand All @@ -144,7 +147,7 @@ def _detect_exceptions_by_domain(self, rule_info):
"""
Find exceptions found on self.
"""
base_domain = self._get_base_domain()
base_domain = self._get_base_domain(rule_info=rule_info)
rule_domain = rule_info.domain
domain = expression.AND([base_domain, rule_domain])
return self.filtered_domain(domain)
Expand All @@ -153,6 +156,6 @@ def _detect_exceptions_by_method(self, rule_info):
"""
Find exceptions found on self.
"""
base_domain = self._get_base_domain()
base_domain = self._get_base_domain(rule_info=rule_info)
records = self.filtered_domain(base_domain)
return getattr(records, rule_info.method)()
8 changes: 7 additions & 1 deletion base_exception/models/exception_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class ExceptionRule(models.Model):
name = fields.Char("Exception Name", required=True, translate=True)
description = fields.Text(translate=True)
sequence = fields.Integer(help="Gives the sequence order when applying the test")
model = fields.Selection(selection=[], string="Apply on", required=True)
model = fields.Selection(selection=[], string="Apply on model", required=True)
filter_domain = fields.Char(
string="Apply on records",
default="[]",
help="If present, this condition must be satisfied to trigger the exception.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="If present, this condition must be satisfied to trigger the exception.",
help="If present, this condition must be satisfied to trigger the exception, no matter the Exception type.",

)

exception_type = fields.Selection(
selection=[
Expand Down Expand Up @@ -119,6 +124,7 @@ def _to_cache_entry(self):
"method": self.method,
"code": self.code,
"is_blocking": self.is_blocking,
"filter_domain": self.filter_domain,
}

@api.model_create_multi
Expand Down
5 changes: 5 additions & 0 deletions base_exception/tests/test_base_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ def test_blocking_exception(self):
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
self.assertTrue(self.po.exceptions_summary)

def test_filtered_domain(self):
self.exception_rule.filter_domain = "['|', ('partner_id.country_id', '=', False), ('partner_id.country_id.zip_required', '=', True)]" # noqa
self.partner.country_id = self.env.ref("base.bz")
self.po.button_confirm()
5 changes: 5 additions & 0 deletions base_exception/views/base_exception_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<group>
<group colspan="4" groups="base.group_system">
<field name="model" />
<field
name="filter_domain"
widget="domain"
options="{'model': 'model', 'in_dialog': True}"
/>
<field name="exception_type" widget="radio" />
<field
name="domain"
Expand Down