[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:
@@ -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 ""
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user