Skip to Content
Menu
This question has been flagged
2 Replies
2221 Views

Hello,

I tried to do this:


    is_acc_manager = fields.Boolean(default=False)
    acc_manager = self.env['res.groups'].search( [ ('name','in',['Accountant','Chief Accountant']), ('category_id.name','=','Invoicing')] )

   def validate_user(self):
         if acc_manager = ???: - What to compare?

            is_acc_manager = True
         else:

            is_acc_manager = False

How to know if the user is accounting or the user profile is in Invoicing?

Avatar
Discard
Best Answer

Hi,

You can check whether the logged in user is in particular group or not like this,

self.env.user.has_group('hr.group_hr_manager')

Where, hr.group_hr_manager , is the external id of the corresponding group.

Code sample:

def action_set_present(self):
if not self.env.user.has_group('hr.group_hr_manager'):
raise UserError(_("You don't have the right to do this. Please contact an Administrator."))
self.write({'manually_set_present': True})


Thanks

Avatar
Discard
Best Answer
Using has_group can check user is related to particular group
Example default hr core module code

@api.multi
def _compute_show_leaves(self):
show_leaves = self.env['res.users'].has_group('hr_holidays.group_hr_holidays_user')
for employee in self:
if show_leaves or employee.user_id == self.env.user:
employee.show_leaves = True
else
:
employee.show_leaves = False
Avatar
Discard
Author

Is the self.env.user equal to the login user?

Yes, current login user, example it will return res.users(1).

Related Posts Replies Views Activity
2
Nov 24
57
1
Oct 24
324
0
Sep 24
124
1
Sep 24
468
3
Jun 24
2501