Browse Source

Merge PR #105 into 14.0

Signed-off-by dreispt
14.0
OCA-git-bot 4 years ago
parent
commit
5d7a31a73c
  1. 8
      base_user_role/models/role.py
  2. 5
      base_user_role/tests/test_user_role.py

8
base_user_role/models/role.py

@ -49,6 +49,14 @@ class ResUsersRole(models.Model):
return new_record return new_record
def write(self, vals): def write(self, vals):
# Workaround to solve issue with broken code in odoo that clear the cache
# during the write: see odoo/addons/base/models/res_users.py#L226
groups_vals = {}
for field in self.group_id._fields:
if field in vals:
groups_vals[field] = vals.pop(field)
if groups_vals:
self.group_id.write(groups_vals)
res = super(ResUsersRole, self).write(vals) res = super(ResUsersRole, self).write(vals)
self.update_users() self.update_users()
return res return res

5
base_user_role/tests/test_user_role.py

@ -169,3 +169,8 @@ class TestUserRole(TransactionCase):
) )
roles = self.role_model.browse([self.role1_id.id, self.role2_id.id]) roles = self.role_model.browse([self.role1_id.id, self.role2_id.id])
self.assertEqual(user.role_ids, roles) self.assertEqual(user.role_ids, roles)
def test_update_role(self):
self.role1_id.write({"name": "foo", "comment": "FOO"})
self.assertEqual(self.role1_id.group_id.name, "foo")
self.assertEqual(self.role1_id.group_id.comment, "FOO")
Loading…
Cancel
Save