From 732fd98bbc4224155d280900bef177efd46cafed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Wed, 26 Feb 2020 22:36:22 +0000 Subject: [PATCH] [IMP] models.py: Method search_read propagate kwargs to read method Currently the method `read` uses by default the parameter `load='classic_read')` - `self.read(fields, load='classic_read')` So, it computes `name_get` for all m2o fields for all records in `self`. If you want to avoid computing the `name_get` to save time and process You can use an empty string in load parameter: - e.g. `self.read(..., load='')` The method `self.search_read` call to `search` and `read` methods but `search_read` method is not possible to assign `load=''` argument (or other arguments of the method `read`) - e.g. `self.search_read(..., load='')` So, you need to use 2 lines of code: records = self.search(...) records.read(..., load='') This commit changes `search_read` method to receive all keyword arguments of the method `read` So, you can use `self.search_read(..., load='')` and the `read` parameter will be propagated closes odoo/odoo#46391 Signed-off-by: Xavier Morel (xmo) --- odoo/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 329e64bca7c..ae4d6590148 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4719,7 +4719,7 @@ Fields: return cls._transient @api.model - def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): + def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs): """Perform a :meth:`search` followed by a :meth:`read`. :param domain: Search domain, see ``args`` parameter in :meth:`search`. @@ -4732,6 +4732,8 @@ Fields: Defaults to no limit. :param order: Columns to sort result, see ``order`` parameter in :meth:`search`. Defaults to no sort. + :param read_kwargs: All read keywords arguments used to call read(..., **read_kwargs) method + E.g. you can use search_read(..., load='') in order to avoid computing name_get :return: List of dictionaries containing the asked fields. :rtype: list(dict). """ @@ -4752,7 +4754,7 @@ Fields: del context['active_test'] records = records.with_context(context) - result = records.read(fields) + result = records.read(fields, **read_kwargs) if len(result) <= 1: return result