diff --git a/base_user_role/models/role.py b/base_user_role/models/role.py index 495a5b66d..089ac25f9 100644 --- a/base_user_role/models/role.py +++ b/base_user_role/models/role.py @@ -47,6 +47,14 @@ class ResUsersRole(models.Model): return new_record 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) self.update_users() return res diff --git a/base_user_role/tests/test_user_role.py b/base_user_role/tests/test_user_role.py index 703372356..55a005bee 100644 --- a/base_user_role/tests/test_user_role.py +++ b/base_user_role/tests/test_user_role.py @@ -224,3 +224,8 @@ class TestUserRole(TransactionCase): role_group_ids = sorted(set(role_group_ids)) # Check that user have groups implied by role 2 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")