[FIX] base: fix read methods for reified fields in res.users
Before this patch it was impossible to add a reified field to a res.users list view via Studio. The internal methods used by search_read are overwritten in res.users to ignore reified fields. closes odoo/odoo#123994 X-original-commit: 11e791d68256a5411d727b031930471eceaafb3f Signed-off-by: Rémy Voet <ryv@odoo.com> Signed-off-by: Jinane Maksoud (maji) <maji@odoo.com> Co-authored-by: Alvaro Fuentes <afu@odoo.com>
This commit is contained in:
co-authored by
Alvaro Fuentes
parent
bc877cbf3f
commit
ff33fa9faf
@@ -1695,6 +1695,14 @@ class UsersView(models.Model):
|
||||
self._add_reified_groups(group_fields, values)
|
||||
return values
|
||||
|
||||
def _determine_fields_to_fetch(self, field_names, ignore_when_in_cache=False):
|
||||
valid_fields = partition(is_reified_group, field_names)[1]
|
||||
return super()._determine_fields_to_fetch(valid_fields, ignore_when_in_cache)
|
||||
|
||||
def _read_format(self, fnames, load='_classic_read'):
|
||||
valid_fields = partition(is_reified_group, fnames)[1]
|
||||
return super()._read_format(valid_fields, load)
|
||||
|
||||
def onchange(self, values, field_name, field_onchange):
|
||||
# field_name can be either a string, a list or Falsy
|
||||
if isinstance(field_name, list):
|
||||
|
||||
@@ -283,8 +283,8 @@ class TestUsers2(TransactionCase):
|
||||
self.assertEqual(user.groups_id & groups, groups)
|
||||
self.assertEqual(user.read([fname])[0][fname], group2.id)
|
||||
|
||||
def test_read_group_with_reified_field(self):
|
||||
""" Check that read_group gets rid of reified fields"""
|
||||
def test_read_list_with_reified_field(self):
|
||||
""" Check that read_group and search_read get rid of reified fields"""
|
||||
User = self.env['res.users']
|
||||
fnames = ['name', 'email', 'login']
|
||||
|
||||
@@ -298,7 +298,13 @@ class TestUsers2(TransactionCase):
|
||||
# check that the reified field name has no effect in fields
|
||||
res_with_reified = User.read_group([], fnames + [reified_fname], ['company_id'])
|
||||
res_without_reified = User.read_group([], fnames, ['company_id'])
|
||||
self.assertEqual(res_with_reified, res_without_reified, "Reified fields should be ignored")
|
||||
self.assertEqual(res_with_reified, res_without_reified, "Reified fields should be ignored in read_group")
|
||||
|
||||
# check that the reified fields are not considered invalid in search_read
|
||||
# and are ignored
|
||||
res_with_reified = User.search_read([], fnames + [reified_fname])
|
||||
res_without_reified = User.search_read([], fnames)
|
||||
self.assertEqual(res_with_reified, res_without_reified, "Reified fields should be ignored in search_read")
|
||||
|
||||
# Verify that the read_group is raising an error if reified field is used as groupby
|
||||
with self.assertRaises(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user