project task timesheets related roles update

This commit is contained in:
pranaysaidurga 2026-07-14 16:11:54 +05:30
parent 1335c60b76
commit fd866fb866
2 changed files with 64 additions and 20 deletions

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):
@ -21,14 +22,22 @@ class ProjectRole(models.Model):
string='Description',
help="Detailed description of the role responsibilities"
)
user_ids = fields.Many2many(
'res.users',
'project_role_user_rel',
'role_id',
'user_id',
string='Assigned Users',
help="Users assigned to this role"
)
user_ids = fields.Many2many(
'res.users',
'project_role_user_rel',
'role_id',
'user_id',
string='Assigned Users',
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(
string='Active',
default=True,
@ -47,20 +56,46 @@ class ProjectRole(models.Model):
help="Structured authority level of the role"
)
def action_update_users(self):
return {
'type': 'ir.actions.act_window',
'name': 'Add Users',
def action_update_users(self):
return {
'type': 'ir.actions.act_window',
'name': 'Add Users',
'res_model': 'roles.user.assign.wizard',
'view_mode': 'form',
'view_id': self.env.ref('project_task_timesheet_extended.roles_user_assignment_form_view').id,
'target': 'new',
'context': {'default_members_ids': [(6, 0, self.user_ids.ids)],
},
}
def action_view_users(self):
"""Open users assigned to this role"""
self.ensure_one()
},
}
def action_grant_access(self):
"""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 = {
'name': f'Users in {self.name} Role',
'type': 'ir.actions.act_window',
@ -97,4 +132,4 @@ class ProjectStage(models.Model):
def _compute_user_ids(self):
"""Compute users from assigned roles"""
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>
<div class="oe_button_box" name="button_box">
<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 class="oe_title">
<h1>
@ -50,6 +51,9 @@
<field name="description" placeholder="Enter role description..."/>
</page>
<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">
<list create="0" edit="0" delete="0">
<field name="name"/>
@ -58,6 +62,11 @@
</list>
</field>
</page>
<page string="Required Groups">
<group>
<field name="required_groups" widget="many2many_tags" options="{'no_create': True, 'no_quick_create': True}"/>
</group>
</page>
</notebook>
</sheet>
</form>
@ -202,4 +211,4 @@
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
</odoo>
</odoo>