[IMP] res_config: Apply groups to users accross companies
Purpose ======= When enabling/disabling a group, the modification is only applied to the users from the enabled companies. It should be applied to all the users. closes odoo/odoo#36744 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_res_config
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestResConfig(TransactionCase):
|
||||
|
||||
def test_multi_company_res_config_group(self):
|
||||
# Enable/Disable a group in a multi-company environment
|
||||
# 1/ All the users should be added/removed from the group
|
||||
# and not only the users of the allowed companies
|
||||
# 2/ The changes should be reflected for new users (Default User Template)
|
||||
|
||||
company = self.env['res.company'].create({'name': 'My Last Company'})
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'My User'
|
||||
})
|
||||
user = self.env['res.users'].create({
|
||||
'login': 'My User',
|
||||
'company_id': company.id,
|
||||
'company_ids': [(4, company.id)],
|
||||
'partner_id': partner.id,
|
||||
})
|
||||
|
||||
ResConfig = self.env['res.config.settings']
|
||||
default_values = ResConfig.default_get(list(ResConfig.fields_get()))
|
||||
|
||||
# Case 1: Enable a group
|
||||
default_values.update({'group_multi_currency': True})
|
||||
ResConfig.create(default_values).execute()
|
||||
self.assertTrue(user in self.env.ref('base.group_multi_currency').sudo().users)
|
||||
|
||||
new_partner = self.env['res.partner'].create({'name': 'New User'})
|
||||
new_user = self.env['res.users'].create({
|
||||
'login': 'My First New User',
|
||||
'company_id': company.id,
|
||||
'company_ids': [(4, company.id)],
|
||||
'partner_id': new_partner.id,
|
||||
})
|
||||
self.assertTrue(new_user in self.env.ref('base.group_multi_currency').sudo().users)
|
||||
|
||||
# Case 2: Disable a group
|
||||
default_values.update({'group_multi_currency': False})
|
||||
ResConfig.create(default_values).execute()
|
||||
self.assertTrue(user not in self.env.ref('base.group_multi_currency').sudo().users)
|
||||
|
||||
new_partner = self.env['res.partner'].create({'name': 'New User'})
|
||||
new_user = self.env['res.users'].create({
|
||||
'login': 'My Second New User',
|
||||
'company_id': company.id,
|
||||
'company_ids': [(4, company.id)],
|
||||
'partner_id': new_partner.id,
|
||||
})
|
||||
self.assertTrue(new_user not in self.env.ref('base.group_multi_currency').sudo().users)
|
||||
@@ -568,6 +568,8 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
|
||||
current_settings = self.default_get(list(self.fields_get()))
|
||||
with self.env.norecompute():
|
||||
for name, groups, implied_group in classified['group']:
|
||||
groups = groups.sudo()
|
||||
implied_group = implied_group.sudo()
|
||||
if self[name] == current_settings[name]:
|
||||
continue
|
||||
if int(self[name]):
|
||||
@@ -627,6 +629,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
|
||||
|
||||
self._install_modules(to_install)
|
||||
|
||||
|
||||
if to_install or to_uninstall_modules:
|
||||
# After the uninstall/install calls, the registry and environments
|
||||
# are no longer valid. So we reset the environment.
|
||||
|
||||
Reference in New Issue
Block a user