[FIX] base, web: graph and pivot views requires more field descriptions

Following odoo/odoo@4636620004
`get_views` only pass the model fields included in the view architecture,
except for the main model when the search views is requested.
Because the search views requires all fields for the user to be able
to make advanced filters and advanced group by using any fields of the
model.

However, other views requires more field descriptions as well than
just the fields included in their architecture:
- the graph view requires all integer and float fields,
    to automatically add suggestions of measures in the measures dropdown
    menu. It's a bit like the search view, the user should be able
    to choose any measure available in the model
    (as long as this is integer or float fields)
- the pivot view requires all groupable fields,
    so the user can group by any groupable fields of the model.

The JS MockServer `getViews` is adapted to include the changes added by the above
revision as well as the current revision,
for the qunit tests suite to be able to reflect these API changes
from the server side.

closes odoo/odoo#100376

Related: odoo/enterprise#31427
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
Denis Ledoux
2022-09-17 00:51:34 +02:00
parent 82e8c74f1e
commit ef16e96255
4 changed files with 103 additions and 30 deletions
+25 -6
View File
@@ -1659,15 +1659,10 @@ class BaseModel(metaclass=MetaModel):
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)
models.setdefault(model, set()).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()
@@ -1797,6 +1792,7 @@ class BaseModel(metaclass=MetaModel):
# Apply post processing, groups and modifiers etc...
arch, models = view.postprocess_and_fields(arch, model=self._name, **options)
models = self._get_view_fields(view_type or view.type, models)
result = {
'arch': arch,
# TODO: only `web_studio` seems to require this. I guess this is acceptable to keep it.
@@ -1840,6 +1836,29 @@ class BaseModel(metaclass=MetaModel):
return result
@api.model
def _get_view_fields(self, view_type, models):
""" Returns the field names required by the web client to load the views according to the view type.
The method is meant to be overridden by modules extending web client features and requiring additional
fields.
:param string view_type: type of the view
:param dict models: dict holding the models and fields used in the view architecture.
:return: dict holding the models and field required by the web client given the view type.
:rtype: list
"""
if view_type in ('kanban', 'list', 'form'):
for model_fields in models.values():
model_fields.update({'id', self.CONCURRENCY_CHECK_FIELD})
elif view_type == 'search':
models[self._name] = list(self._fields.keys())
elif view_type == 'graph':
models[self._name].union(fname for fname, field in self._fields.items() if field.type in ('integer', 'float'))
elif view_type == 'pivot':
models[self._name].union(fname for fname, field in self._fields.items() if field.groupable)
return models
@api.model
def _get_view_field_attributes(self):
""" Returns the field attributes required by the web client to load the views.