-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sebalix
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"data/ir_module_category.xml", | ||
"views/role.xml", | ||
"views/user.xml", | ||
"views/group.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import role | ||
from . import user | ||
from . import group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class ResGroups(models.Model): | ||
_inherit = "res.groups" | ||
|
||
# The inverse field of the field group_id on the res.users.role model | ||
# This field should be used a One2one relation as a role can only be | ||
# represented by one group. It's declared as a One2many field as the | ||
# inverse field on the res.users.role it's declared as a Many2one | ||
role_id = fields.One2many( | ||
comodel_name="res.users.role", | ||
inverse_name="group_id", | ||
help="Relation for the groups that represents a role", | ||
) | ||
|
||
role_ids = fields.Many2many( | ||
comodel_name="res.users.role", | ||
relation="res_groups_implied_roles_rel", | ||
string="Roles", | ||
compute="_compute_role_ids", | ||
help="Roles in which the group is involved", | ||
) | ||
|
||
parent_ids = fields.Many2many( | ||
"res.groups", | ||
"res_groups_implied_rel", | ||
"hid", | ||
"gid", | ||
string="Parents", | ||
help="Inverse relation for the Inherits field. " | ||
"The groups from which this group is inheriting", | ||
) | ||
|
||
trans_parent_ids = fields.Many2many( | ||
comodel_name="res.groups", | ||
string="Parent Groups", | ||
compute="_compute_trans_parent_ids", | ||
) | ||
|
||
role_count = fields.Integer("# Roles", compute="_compute_role_count") | ||
|
||
def _compute_role_count(self): | ||
for group in self: | ||
group.role_count = len(group.role_ids) | ||
|
||
@api.depends("parent_ids.trans_parent_ids") | ||
def _compute_trans_parent_ids(self): | ||
for group in self: | ||
group.trans_parent_ids = ( | ||
group.parent_ids | group.parent_ids.trans_parent_ids | ||
) | ||
|
||
def _compute_role_ids(self): | ||
for group in self: | ||
if group.trans_parent_ids: | ||
group.role_ids = group.trans_parent_ids.role_id | ||
else: | ||
group.role_ids = group.role_id | ||
|
||
def action_view_roles(self): | ||
self.ensure_one() | ||
action = self.env["ir.actions.act_window"]._for_xml_id( | ||
"base_user_role.action_res_users_role_tree" | ||
) | ||
action["context"] = {} | ||
if len(self.role_ids) > 1: | ||
action["domain"] = [("id", "in", self.role_ids.ids)] | ||
elif self.role_ids: | ||
form_view = [ | ||
(self.env.ref("base_user_role.view_res_users_role_form").id, "form") | ||
] | ||
if "views" in action: | ||
action["views"] = form_view + [ | ||
(state, view) for state, view in action["views"] if view != "form" | ||
] | ||
else: | ||
action["views"] = form_view | ||
action["res_id"] = self.role_ids.id | ||
else: | ||
action = {"type": "ir.actions.act_window_close"} | ||
return action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" ?> | ||
<odoo> | ||
<record id="res_groups_view_form" model="ir.ui.view"> | ||
<field name="name">res.groups.form - base_user_role</field> | ||
<field name="model">res.groups</field> | ||
<field name="inherit_id" ref="base.view_groups_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//sheet/group" position="before"> | ||
<div name="button_box" class="oe_button_box"> | ||
<button | ||
class="oe_stat_button" | ||
name="action_view_roles" | ||
type="object" | ||
icon="fa-gears" | ||
attrs="{'invisible': [ ('role_count', '=', 0)]}" | ||
> | ||
<field string="Roles" name="role_count" widget="statinfo" /> | ||
</button> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |