diff --git a/addons/mail/models/ir_ui_view.py b/addons/mail/models/ir_ui_view.py index fb2a5552eaf..db1a2d4f325 100644 --- a/addons/mail/models/ir_ui_view.py +++ b/addons/mail/models/ir_ui_view.py @@ -11,5 +11,6 @@ class View(models.Model): if node.xpath("ancestor::div[hasclass('oe_chatter')]"): # Pass the postprocessing of the mail thread fields # The web client makes it completely custom, and this is therefore pointless. + name_manager.has_field(node, node.get('name'), {}) return return super()._postprocess_tag_field(node, name_manager, node_info) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index f944a560b60..8d80f1b164a 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -1006,14 +1006,14 @@ actual arch. arch = etree.tostring(node, encoding="unicode").replace('\t', '') - models = set() + models = {} name_managers = [name_manager] for name_manager in name_managers: - models.add(name_manager.model._name) + models.setdefault(name_manager.model._name, set()).update(name_manager.available_fields) name_managers.extend(name_manager.children) return arch, models - def _postprocess_access_rights(self, tree, models): + def _postprocess_access_rights(self, tree): """ Apply group restrictions: elements with a 'groups' attribute should be removed from the view to people who are not members. @@ -1022,14 +1022,6 @@ actual arch. views can add additional specific rights like creating columns for many2one-based grouping views. """ - models = { - model: { - fname: field - for fname, field in fields.items() - if not field.get('groups') or self.user_has_groups(field['groups']) - } - for model, fields in models.items() - } for node in tree.xpath('//*[@groups]'): if not self.user_has_groups(node.attrib.pop('groups')): @@ -1073,7 +1065,7 @@ actual arch. not self._context.get(action, True) and is_base_model): node.set(action, 'false') - return tree, models + return tree def _postprocess_view(self, node, model_name, editable=True, parent_name_manager=None, **options): """ Process the given architecture, modifying it in-place to add and diff --git a/odoo/models.py b/odoo/models.py index 7d97e7af6f0..84a4b7be48c 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -1654,11 +1654,22 @@ class BaseModel(metaclass=MetaModel): for [v_id, v_type] in views } - result['models'] = { - model: fields - for info in result['views'].values() - for model, fields in info.pop('models').items() - } + models = {} + for view in result['views'].values(): + for model, model_fields in view.pop('models').items(): + models.setdefault(model, {'id', self.CONCURRENCY_CHECK_FIELD}).update(model_fields) + + result['models'] = {} + + if 'search' in result['views']: + # If the search view is requested, all fields of the main model must be passed. + result['models'][self._name] = self.fields_get(attributes=self._get_view_field_attributes()) + models.pop(self._name) + + for model, model_fields in models.items(): + result['models'][model] = self.env[model].fields_get( + allfields=model_fields, attributes=self._get_view_field_attributes() + ) # Add related action information if asked if options.get('toolbar'): @@ -1791,10 +1802,8 @@ class BaseModel(metaclass=MetaModel): # TODO: only `web_studio` seems to require this. But this one on the other hand should be eliminated: # you just called `get_views` for that model, so obviously the web client already knows the model. 'model': self._name, - # sudo is important to get all fields, including fields restricted to groups, in the cache. - 'models': {model: frozendict(self.env[model].sudo().fields_get( - attributes=self._get_view_field_attributes(), - )) for model in models}, + # Set a frozendict and tuple for the field list to make sure the value in cache cannot be updated. + 'models': frozendict({model: tuple(fields) for model, fields in models.items()}), } return frozendict(result) @@ -1824,7 +1833,7 @@ class BaseModel(metaclass=MetaModel): result = dict(self._get_view_cache(view_id, view_type, **options)) node = etree.fromstring(result['arch']) - node, result['models'] = self.env['ir.ui.view']._postprocess_access_rights(node, result['models']) + node = self.env['ir.ui.view']._postprocess_access_rights(node) result['arch'] = etree.tostring(node, encoding="unicode").replace('\t', '') return result