diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 385fbeb6f23..c42646ea186 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -3,6 +3,7 @@ import ast import collections import datetime +import functools import inspect import json import logging @@ -2195,7 +2196,13 @@ class NameManager: @lazy_property def field_info(self): - return self.model.fields_get() + field_info = self.model.fields_get() + has_access = functools.partial(self.model.check_access_rights, raise_exception=False) + if not (has_access('write') or has_access('create')): + for info in field_info.vals(): + info['readonly'] = True + info['states'] = {} + return field_info def has_field(self, name, info=frozendict()): self.available_fields[name].update(info) diff --git a/odoo/fields.py b/odoo/fields.py index 3c73428c535..bdf2ea0082b 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -793,10 +793,12 @@ class Field(MetaField('DummyField', (object,), {})): # Field description # - def get_description(self, env): + def get_description(self, env, attributes=None): """ Return a dictionary that describes the field ``self``. """ - desc = {'type': self.type} + desc = {} for attr, prop in self.description_attrs: + if attributes is not None and attr not in attributes: + continue value = getattr(self, prop) if callable(value): value = value(env) @@ -806,6 +808,8 @@ class Field(MetaField('DummyField', (object,), {})): return desc # properties used by get_description() + _description_name = property(attrgetter('name')) + _description_type = property(attrgetter('type')) _description_store = property(attrgetter('store')) _description_manual = property(attrgetter('manual')) _description_related = property(attrgetter('related')) diff --git a/odoo/models.py b/odoo/models.py index ab16f1c40f7..60720e79c73 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3195,9 +3195,6 @@ class BaseModel(metaclass=MetaModel): :param allfields: list of fields to document, all if empty or not provided :param attributes: list of description attributes to return for each field, all if empty or not provided """ - has_access = functools.partial(self.check_access_rights, raise_exception=False) - readonly = not (has_access('write') or has_access('create')) - res = {} for fname, field in self._fields.items(): if allfields and fname not in allfields: @@ -3205,15 +3202,7 @@ class BaseModel(metaclass=MetaModel): if field.groups and not self.env.su and not self.user_has_groups(field.groups): continue - description = field.get_description(self.env) - description['name'] = fname - if readonly: - description['readonly'] = True - description['states'] = {} - if attributes: - description = {key: val - for key, val in description.items() - if key in attributes} + description = field.get_description(self.env, attributes=attributes) res[fname] = description return res