Skip to content

Commit

Permalink
Merge PR #1644 into 10.0
Browse files Browse the repository at this point in the history
Signed-off-by guewen
  • Loading branch information
OCA-git-bot committed Oct 14, 2019
2 parents c7b8902 + 2750e15 commit f472093
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions base_exception/models/base_exception.py
Expand Up @@ -251,14 +251,40 @@ def _get_popup_action(self):
@api.multi
def _check_exception(self):
"""
This method must be used in a constraint that must be created in the
object that inherits for base.exception.
for sale :
@api.constrains('ignore_exception',)
This method must be called in the create and write methods of the model
using exceptions. The model has to inherit from 'base.exception'.
Example for sale (used in OCA/sale-workflow/sale_exception):
def _fields_trigger_check_exception(self):
return ['ignore_exception', 'order_line', 'state']
@api.model
def create(self, vals):
record = super(SaleOrder, self).create(vals)
check_exceptions = any(
field in vals for field
in self._fields_trigger_check_exception()
)
if check_exceptions:
record.sale_check_exception()
return record
@api.multi
def write(self, vals):
result = super(SaleOrder, self).write(vals)
check_exceptions = any(
field in vals for field
in self._fields_trigger_check_exception()
)
if check_exceptions:
self.sale_check_exception()
return result
def sale_check_exception(self):
...
...
self._check_exception
orders = self.filtered(lambda s: s.state == 'sale')
if orders:
orders._check_exception()
"""
exception_ids = self.detect_exceptions()
if exception_ids:
Expand Down

0 comments on commit f472093

Please sign in to comment.