Merge PR #114 into 12.0

Signed-off-by StefanRijnhart
This commit is contained in:
OCA-git-bot
2021-04-26 14:28:00 +00:00
5 changed files with 42 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
{ {
"name": "User roles", "name": "User roles",
"version": "12.0.2.0.1", "version": "12.0.2.1.0",
"category": "Tools", "category": "Tools",
"author": "ABF OSIELL, Odoo Community Association (OCA)", "author": "ABF OSIELL, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",

View File

@@ -3,8 +3,9 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record model="ir.module.category" id="ir_module_category_role"> <record model="ir.module.category" id="ir_module_category_role">
<field name='name'>User roles</field> <field name="name">User roles</field>
</record> <field name="sequence">200</field>
</record>
</odoo> </odoo>

View 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)

View File

@@ -31,16 +31,18 @@ class ResUsersRole(models.Model):
string="Users list", string="Users list",
compute="_compute_user_ids", 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( group_category_id = fields.Many2one(
comodel_name="ir.module.category",
related="group_id.category_id", related="group_id.category_id",
default=lambda cls: cls.env.ref(
"base_user_role.ir_module_category_role"
).id,
string="Associated category", string="Associated category",
help="Associated group's category",
) )
comment = fields.Html(string="Internal Notes") 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.multi
@api.depends("line_ids.user_id") @api.depends("line_ids.user_id")
def _compute_user_ids(self): def _compute_user_ids(self):
@@ -49,6 +51,8 @@ class ResUsersRole(models.Model):
@api.model @api.model
def create(self, vals): 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 = super(ResUsersRole, self).create(vals)
new_record.update_users() new_record.update_users()
return new_record return new_record

View File

@@ -297,3 +297,11 @@ class TestUserRole(SavepointCase):
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_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
)