mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[FIX] base_user_role : affect correct default category, when creating the related group
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
"name": "User roles",
|
||||
"version": "12.0.2.0.1",
|
||||
"version": "12.0.2.1.0",
|
||||
"category": "Tools",
|
||||
"author": "ABF OSIELL, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.module.category" id="ir_module_category_role">
|
||||
<field name='name'>User roles</field>
|
||||
</record>
|
||||
<record model="ir.module.category" id="ir_module_category_role">
|
||||
<field name="name">User roles</field>
|
||||
<field name="sequence">200</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
21
base_user_role/migrations/12.0.2.1.0/post-migration.py
Normal file
21
base_user_role/migrations/12.0.2.1.0/post-migration.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
|
||||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
import logging
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _affect_group_to_category(env):
|
||||
_logger.info("Set Category 'User roles' to groups related to roles")
|
||||
roles = env["res.users.role"].search([])
|
||||
groups = roles.mapped("group_id").filtered(lambda x: not x.category_id)
|
||||
user_role_category = env.ref("base_user_role.ir_module_category_role")
|
||||
groups.write({"category_id": user_role_category.id})
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
with api.Environment.manage():
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
_affect_group_to_category(env)
|
||||
@@ -31,16 +31,18 @@ class ResUsersRole(models.Model):
|
||||
string="Users list",
|
||||
compute="_compute_user_ids",
|
||||
)
|
||||
# TODO, remove in next version as it is not used in the whole module
|
||||
# kept here for legacy reason
|
||||
group_category_id = fields.Many2one(
|
||||
comodel_name="ir.module.category",
|
||||
related="group_id.category_id",
|
||||
default=lambda cls: cls.env.ref(
|
||||
"base_user_role.ir_module_category_role"
|
||||
).id,
|
||||
string="Associated category",
|
||||
help="Associated group's category",
|
||||
)
|
||||
comment = fields.Html(string="Internal Notes")
|
||||
|
||||
def _default_category_id(self):
|
||||
return self.env.ref("base_user_role.ir_module_category_role")
|
||||
|
||||
@api.multi
|
||||
@api.depends("line_ids.user_id")
|
||||
def _compute_user_ids(self):
|
||||
@@ -49,6 +51,8 @@ class ResUsersRole(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if "category_id" not in vals and "group_id" not in vals:
|
||||
vals.update({"category_id": self._default_category_id().id})
|
||||
new_record = super(ResUsersRole, self).create(vals)
|
||||
new_record.update_users()
|
||||
return new_record
|
||||
|
||||
@@ -297,3 +297,11 @@ class TestUserRole(SavepointCase):
|
||||
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_user_role_category(self):
|
||||
# Check that groups created by role has the correct
|
||||
# default category
|
||||
self.assertEqual(
|
||||
self.env.ref("base_user_role.ir_module_category_role").id,
|
||||
self.role1_id.category_id.id
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user