Browse Source

Merge pull request #1474 from akretion/10-base_exception-filter-rules

[10][IMP] base_exception allow to filter rules
pull/1481/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
01dc1da644
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      base_exception/__manifest__.py
  2. 12
      base_exception/models/base_exception.py

2
base_exception/__manifest__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{'name': 'Exception Rule', {'name': 'Exception Rule',
'version': '10.0.2.0.0',
'version': '10.0.2.0.1',
'category': 'Generic Modules', 'category': 'Generic Modules',
'summary': """This module provide an abstract model to manage customizable 'summary': """This module provide an abstract model to manage customizable
exceptions to be applied on different models (sale order, invoice, ...)""", exceptions to be applied on different models (sale order, invoice, ...)""",

12
base_exception/models/base_exception.py

@ -187,6 +187,15 @@ class BaseException(models.AbstractModel):
if hasattr(exception_obj, field.name) if hasattr(exception_obj, field.name)
] or [None])[0] ] or [None])[0]
def _rule_domain(self):
"""Filter exception.rules.
By default, only the rules with the correct rule group
will be used.
"""
# TODO fix self[0] : it may not be the same on all ids in self
return [('rule_group', '=', self[0].rule_group)]
@api.multi @api.multi
def detect_exceptions(self): def detect_exceptions(self):
"""List all exception_ids applied on self """List all exception_ids applied on self
@ -196,8 +205,7 @@ class BaseException(models.AbstractModel):
return [] return []
exception_obj = self.env['exception.rule'] exception_obj = self.env['exception.rule']
all_exceptions = exception_obj.sudo().search( all_exceptions = exception_obj.sudo().search(
[('rule_group', '=', self[0].rule_group)])
# TODO fix self[0] : it may not be the same on all ids in self
self._rule_domain())
model_exceptions = all_exceptions.filtered( model_exceptions = all_exceptions.filtered(
lambda ex: ex.model == self._name) lambda ex: ex.model == self._name)
sub_exceptions = all_exceptions.filtered( sub_exceptions = all_exceptions.filtered(

Loading…
Cancel
Save