diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index dfb0238e327..2f4ffb39f31 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -244,8 +244,7 @@ class IrModel(models.Model): def _check_model_name(self): for model in self: if model.state == 'manual': - if not model.model.startswith('x_'): - raise ValidationError(_("The model name must start with 'x_'.")) + self._check_manual_name(model.model) if not models.check_object_name(model.model): raise ValidationError(_("The model name can only contain lowercase characters, digits, underscores and dots.")) @@ -443,6 +442,15 @@ class IrModel(models.Model): return CustomModel + @api.model + def _is_manual_name(self, name): + return name.startswith('x_') + + @api.model + def _check_manual_name(self, name): + if not self._is_manual_name(name): + raise ValidationError(_("The model name must start with 'x_'.")) + def _add_manual_models(self): """ Add extra models to the registry. """ # clean up registry first @@ -1255,7 +1263,7 @@ class IrModelFields(models.Model): elif field_data['ttype'] == 'monetary': # be sure that custom monetary field are always instanciated if not self.pool.loaded and \ - not (field_data['currency_field'] and field_data['currency_field'].startswith('x_')): + not (field_data['currency_field'] and self._is_manual_name(field_data['currency_field'])): return attrs['currency_field'] = field_data['currency_field'] # add compute function if given @@ -1269,6 +1277,10 @@ class IrModelFields(models.Model): if attrs: return fields.Field.by_type[field_data['ttype']](**attrs) + @api.model + def _is_manual_name(self, name): + return name.startswith('x_') + def _add_manual_fields(self, model): """ Add extra fields on model. """ fields_data = self._get_manual_field_data(model._name) diff --git a/odoo/models.py b/odoo/models.py index 24c38cea41a..944028f929b 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -645,7 +645,7 @@ class BaseModel(metaclass=MetaModel): isinstance(getattr(model, name, None), fields.Field) for model in [cls] + [self.env.registry[inherit] for inherit in cls._inherits] ) - if not (is_class_field or name.startswith('x_')): + if not (is_class_field or self.env['ir.model.fields']._is_manual_name(name)): raise ValidationError( f"The field `{name}` is not defined in the `{cls._name}` Python class and does not start with 'x_'" )