[IMP] base: Warning on m2o required field with ondelete set to 'Set NULL'

Since a required field can not be empty: a warning message will
be thrown if a many2one required field has the "on_delete"
attribute set to "Set NULL".

Task ID 2250533

closes odoo/odoo#50751

X-original-commit: 084555c6395b484a85ec9d386fbc8afc8aec1f8c
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nasreddin (bon)
2020-05-06 11:59:31 +00:00
parent a3049d1300
commit 04ecbe08b9
2 changed files with 16 additions and 0 deletions
+6
View File
@@ -22181,6 +22181,12 @@ msgstr ""
msgid "The list of models that extends the current model."
msgstr ""
#. module: base
#: code:addons/base/models/ir_model.py:522
#, python-format
msgid "The m2o field %s is required but declares its ondelete policy as being 'set null'. Only 'restrict' and 'cascade' make sense."
msgstr ""
#. module: base
#: model:ir.model.fields,help:base.field_ir_filters__action_id
msgid ""
+10
View File
@@ -679,6 +679,16 @@ class IrModelFields(models.Model):
'message': _("The table %r if used for other, possibly incompatible fields.") % self.relation_table,
}}
@api.onchange('required', 'ttype', 'on_delete')
def _onchange_required(self):
for rec in self:
if rec.ttype == 'many2one' and rec.required and rec.on_delete == 'set null':
return {'warning': {'title': _("Warning"), 'message': _(
"The m2o field %s is required but declares its ondelete policy "
"as being 'set null'. Only 'restrict' and 'cascade' make sense."
% (rec.name)
)}}
def _get(self, model_name, name):
""" Return the (sudoed) `ir.model.fields` record with the given model and name.
The result may be an empty recordset if the model is not found.