feature/share_module #24

Merged
pranay merged 4 commits from feature/share_module into srivyn_test 2026-07-14 18:33:21 +05:30
2 changed files with 64 additions and 20 deletions
Showing only changes of commit fd866fb866 - Show all commits

View File

@ -1,4 +1,5 @@
from odoo import fields, models from odoo import _, fields, models
from odoo.exceptions import UserError
class ProjectRole(models.Model): class ProjectRole(models.Model):
@ -21,14 +22,22 @@ class ProjectRole(models.Model):
string='Description', string='Description',
help="Detailed description of the role responsibilities" help="Detailed description of the role responsibilities"
) )
user_ids = fields.Many2many( user_ids = fields.Many2many(
'res.users', 'res.users',
'project_role_user_rel', 'project_role_user_rel',
'role_id', 'role_id',
'user_id', 'user_id',
string='Assigned Users', string='Assigned Users',
help="Users assigned to this role" help="Users assigned to this role"
) )
required_groups = fields.Many2many(
'res.groups',
'project_role_required_group_rel',
'role_id',
'group_id',
string='Required Groups',
help="Groups that should be granted to the assigned users for this role"
)
active = fields.Boolean( active = fields.Boolean(
string='Active', string='Active',
default=True, default=True,
@ -47,20 +56,46 @@ class ProjectRole(models.Model):
help="Structured authority level of the role" help="Structured authority level of the role"
) )
def action_update_users(self): def action_update_users(self):
return { return {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'name': 'Add Users', 'name': 'Add Users',
'res_model': 'roles.user.assign.wizard', 'res_model': 'roles.user.assign.wizard',
'view_mode': 'form', 'view_mode': 'form',
'view_id': self.env.ref('project_task_timesheet_extended.roles_user_assignment_form_view').id, 'view_id': self.env.ref('project_task_timesheet_extended.roles_user_assignment_form_view').id,
'target': 'new', 'target': 'new',
'context': {'default_members_ids': [(6, 0, self.user_ids.ids)], 'context': {'default_members_ids': [(6, 0, self.user_ids.ids)],
}, },
} }
def action_view_users(self):
"""Open users assigned to this role""" def action_grant_access(self):
self.ensure_one() """Grant the selected required groups to all assigned users."""
for role in self:
role.check_access('write')
if not role.user_ids:
raise UserError(_("Please assign at least one user before granting access."))
if not role.required_groups:
raise UserError(_("Please select at least one required group before granting access."))
users = role.user_ids.sudo()
groups = role.required_groups.sudo()
for user in users:
user.write({'groups_id': [(4, group.id) for group in groups]})
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('Access Granted'),
'message': _('Required groups were added to the assigned users.'),
'type': 'success',
'sticky': False,
}
}
def action_view_users(self):
"""Open users assigned to this role"""
self.ensure_one()
action = { action = {
'name': f'Users in {self.name} Role', 'name': f'Users in {self.name} Role',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
@ -97,4 +132,4 @@ class ProjectStage(models.Model):
def _compute_user_ids(self): def _compute_user_ids(self):
"""Compute users from assigned roles""" """Compute users from assigned roles"""
for stage in self: for stage in self:
stage.user_ids = stage.role_ids.mapped('user_ids') stage.user_ids = stage.role_ids.mapped('user_ids')

View File

@ -31,6 +31,7 @@
<sheet> <sheet>
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button name="action_update_users" type="object" string="Modify Users" class="btn-primary"/> <button name="action_update_users" type="object" string="Modify Users" class="btn-primary"/>
<button name="action_grant_access" type="object" string="Grant Access" class="btn-secondary"/>
</div> </div>
<div class="oe_title"> <div class="oe_title">
<h1> <h1>
@ -50,6 +51,9 @@
<field name="description" placeholder="Enter role description..."/> <field name="description" placeholder="Enter role description..."/>
</page> </page>
<page string="Assigned Users"> <page string="Assigned Users">
<!-- <group>-->
<!-- <field name="required_groups" widget="many2many_tags" options="{'no_create': True, 'no_quick_create': True}"/>-->
<!-- </group>-->
<field name="user_ids" can_create="False" can_write="False"> <field name="user_ids" can_create="False" can_write="False">
<list create="0" edit="0" delete="0"> <list create="0" edit="0" delete="0">
<field name="name"/> <field name="name"/>
@ -58,6 +62,11 @@
</list> </list>
</field> </field>
</page> </page>
<page string="Required Groups">
<group>
<field name="required_groups" widget="many2many_tags" options="{'no_create': True, 'no_quick_create': True}"/>
</group>
</page>
</notebook> </notebook>
</sheet> </sheet>
</form> </form>
@ -202,4 +211,4 @@
<!-- </xpath>--> <!-- </xpath>-->
<!-- </field>--> <!-- </field>-->
<!-- </record>--> <!-- </record>-->
</odoo> </odoo>