[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/2809/head
Thierry Ducrest 2021-03-24 13:28:41 +01:00 committed by docker-odoo
parent 0554460817
commit 6994ba4b48
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 " help="Python code executed to check if the exception apply or "
"not. Use failed = True to block the exception", "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") @api.constrains("exception_type", "domain", "code")
def check_exception_type_consistency(self): def check_exception_type_consistency(self):
@ -201,6 +204,13 @@ class BaseExceptionModel(models.AbstractModel):
ignore_exception = fields.Boolean("Ignore Exceptions", copy=False) ignore_exception = fields.Boolean("Ignore Exceptions", copy=False)
def action_ignore_exceptions(self): 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}) self.write({"ignore_exception": True})
return True return True
@ -218,8 +228,17 @@ class BaseExceptionModel(models.AbstractModel):
if rec.exception_ids and not rec.ignore_exception: if rec.exception_ids and not rec.ignore_exception:
rec.exceptions_summary = "<ul>%s</ul>" % "".join( rec.exceptions_summary = "<ul>%s</ul>" % "".join(
[ [
"<li>%s: <i>%s</i></li>" "<li>%s: <i>%s</i> <b>%s<b></li>"
% tuple(map(html.escape, (e.name, e.description or ""))) % tuple(
map(
html.escape,
(
e.name,
e.description or "",
_("(Blocking exception)") if e.is_blocking else "",
),
)
)
for e in rec.exception_ids for e in rec.exception_ids
] ]
) )

View File

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