Browse Source

[IMP] Fix edition of role

14.0
Sébastien BEAU 4 years ago
parent
commit
7eb3e12a14
  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

@ -47,6 +47,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

@ -224,3 +224,8 @@ class TestUserRole(TransactionCase):
role_group_ids = sorted(set(role_group_ids)) role_group_ids = sorted(set(role_group_ids))
# Check that user have groups implied by role 2 # Check that user have groups implied by role 2
self.assertEqual(user_group_ids, role_group_ids) self.assertEqual(user_group_ids, role_group_ids)
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