no-raise-unlink (E8140)#
unlink() raises an exception.
Applies to Odoo 15.0 and later.
What it does#
Reports raise statements inside the unlink() method of a model.
Why is this bad?#
Since Odoo 15.0, checks that prevent deleting records belong in a method
decorated with @api.ondelete. That method is skipped when the module is
uninstalled, so uninstalling does not fail on your check.
Example#
def unlink(self):
if self.filtered("posted"):
raise UserError(_("Cannot delete posted entries."))
return super().unlink()
Use instead:
@api.ondelete(at_uninstall=False)
def _unlink_except_posted(self):
if self.filtered("posted"):
raise UserError(_("Cannot delete posted entries."))