[IMP] base: use helper methods for implied groups

In this PR, we add a helper method to add/remove implied groups - update the base to use these instead

Task 2610735
This commit is contained in:
Habib (ayh)
2021-08-13 14:50:44 +00:00
parent be7fced806
commit 4f19f29a09
2 changed files with 17 additions and 3 deletions
+2 -3
View File
@@ -577,10 +577,9 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
if self[name] == current_settings[name]:
continue
if int(self[name]):
groups.write({'implied_ids': [Command.link(implied_group.id)]})
groups._apply_group(implied_group)
else:
groups.write({'implied_ids': [Command.unlink(implied_group.id)]})
implied_group.write({'users': [Command.unlink(user.id) for user in groups.users]})
groups._remove_group(implied_group)
# config fields: store ir.config_parameters
IrConfigParameter = self.env['ir.config_parameter'].sudo()
+15
View File
@@ -1091,6 +1091,21 @@ class GroupsImplied(models.Model):
self._check_one_user_type()
return res
def _apply_group(self, implied_group):
""" Add the given group to the groups implied by the current group
:param implied_group: the implied group to add
"""
if implied_group not in self.implied_ids:
self.write({'implied_ids': [Command.link(implied_group.id)]})
def _remove_group(self, implied_group):
""" Remove the given group from the implied groups of the current group
:param implied_group: the implied group to remove
"""
if implied_group in self.implied_ids:
self.write({'implied_ids': [Command.unlink(implied_group.id)]})
implied_group.write({'users': [Command.unlink(user.id) for user in self.users]})
class UsersImplied(models.Model):
_inherit = 'res.users'