[13.0][IMP] base_exception add blocking exceptions

By default exceptions can be ignored by the click of a button.
Users begin human they will just click that button what ever
the internal rules.

So this PR adds the option to set specific exceptions as blocking.

When exceptions are detected if one of them is blocking, the user
will not be able to ignore them.
pull/2463/head
Thierry Ducrest 2021-03-24 13:28:41 +01:00 committed by matiasperalta1
parent d9281728b6
commit 82e0042208
2 changed files with 22 additions and 2 deletions

View File

@ -42,6 +42,9 @@ class ExceptionRule(models.Model):
help="Python code executed to check if the exception apply or "
"not. Use failed = True to block the exception",
)
is_blocking = fields.Boolean(
string="Is blocking", help="When checked the exception can not be ignored",
)
@api.constrains("exception_type", "domain", "code")
def check_exception_type_consistency(self):
@ -201,6 +204,13 @@ class BaseExceptionModel(models.AbstractModel):
ignore_exception = fields.Boolean("Ignore Exceptions", copy=False)
def action_ignore_exceptions(self):
if any(self.exception_ids.mapped("is_blocking")):
raise UserError(
_(
"The exceptions can not be ignored, because "
"some of them are blocking."
)
)
self.write({"ignore_exception": True})
return True
@ -218,8 +228,17 @@ class BaseExceptionModel(models.AbstractModel):
if rec.exception_ids and not rec.ignore_exception:
rec.exceptions_summary = "<ul>%s</ul>" % "".join(
[
"<li>%s: <i>%s</i></li>"
% tuple(map(html.escape, (e.name, e.description or "")))
"<li>%s: <i>%s</i> <b>%s<b></li>"
% tuple(
map(
html.escape,
(
e.name,
e.description or "",
_("(Blocking exception)") if e.is_blocking else "",
),
)
)
for e in rec.exception_ids
]
)

View File

@ -49,6 +49,7 @@
widget="domain"
options="{'model': 'model'}"
/>
<field name="is_blocking" />
</group>
</group>
<notebook>