Remove implicit field names in ModelStorage.search_read
issue8569 review285801003
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Remove implicit field names in ModelStorage.search_read
|
||||
|
||||
Version 5.4.0 - 2019-11-04
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Improve tests on depends
|
||||
|
||||
@@ -276,6 +276,9 @@ class ActionMixin(ModelSQL):
|
||||
if getattr(Action, default_func, None):
|
||||
setattr(cls, default_func,
|
||||
partial(ActionMixin._default_action, name))
|
||||
cls.__rpc__.update({
|
||||
'fetch_action': RPC(cache=dict(days=1)),
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def _default_action(name):
|
||||
@@ -406,6 +409,11 @@ class ActionMixin(ModelSQL):
|
||||
groups = {g.id for a in actions for g in a.groups}
|
||||
return groups
|
||||
|
||||
@classmethod
|
||||
def fetch_action(cls, action_id):
|
||||
fields = list(cls._fields.keys())
|
||||
return cls.search_read([('action', '=', action_id)], fields, limit=1)
|
||||
|
||||
|
||||
class ActionReport(ActionMixin, ModelSQL, ModelView):
|
||||
"Action report"
|
||||
|
||||
@@ -508,8 +508,8 @@ class ModelStorage(Model):
|
||||
'''
|
||||
records = cls.search(domain, offset=offset, limit=limit, order=order)
|
||||
|
||||
if not fields_names:
|
||||
fields_names = list(cls._fields.keys())
|
||||
if fields_names is None:
|
||||
fields_names = ['id']
|
||||
if 'id' not in fields_names:
|
||||
fields_names.append('id')
|
||||
rows = cls.read(list(map(int, records)), fields_names)
|
||||
|
||||
@@ -29,11 +29,13 @@ class ModelStorageTestCase(unittest.TestCase):
|
||||
self.assertTrue(
|
||||
all(x['id'] < y['id'] for x, y in zip(rows, rows[1:])))
|
||||
|
||||
rows = ModelStorage.search_read([], order=[('name', 'ASC')])
|
||||
rows = ModelStorage.search_read(
|
||||
[], order=[('name', 'ASC')], fields_names=['name'])
|
||||
self.assertTrue(
|
||||
all(x['name'] <= y['name'] for x, y in zip(rows, rows[1:])))
|
||||
|
||||
rows = ModelStorage.search_read([], order=[('name', 'DESC')])
|
||||
rows = ModelStorage.search_read(
|
||||
[], order=[('name', 'DESC')], fields_names=['name'])
|
||||
self.assertTrue(
|
||||
all(x['name'] >= y['name'] for x, y in zip(rows, rows[1:])))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user