Skip to Content
Menu
This question has been flagged
1 Reply
2935 Views

I have this function I want to : if the current user is the leaves manager ( that I make it from sittings by making this user is leaves manager and in employees is officer) : make this check box True 
but even  I logged in by leaves manager the check box not checked yet 


state = fields.Selection([
('draft', 'To Submit'),
('cancel', 'Cancelled'),
('confirm', 'To Approve'),
('manager', 'Manager Approve'),
('hr_approve','HR Approve'),
('refuse', 'Refused'),
('validate1', 'Second Approval'),
('validate', 'Approved')
], string='Status', readonly=True, track_visibility='onchange', copy=False, default='confirm',
help="The status is set to 'To Submit', when a holiday request is created." +
"\nThe status is 'To Approve', when holiday request is confirmed by user." +
"\nThe status is 'Refused', when holiday request is refused by manager." +
"\nThe status is 'Approved', when holiday request is approved by manager.")
@api.one
@api.depends('state')
def _compute_can_hr_approved(self):
current_user_id = self.env.uid
is_hr=self.env['res.users'].has_group('hr_holidays.group_hr_holidays_manager')
if self.state == 'manager' and current_user_id == is_hr:
self.can_hr_approved = True
else:
self.can_hr_approved = False
self.is_hr=is_hr

is_hr = fields.Many2one('res.users', 'HR', store=True)
can_hr_approved = fields.Boolean(string='Can HR approved', compute='_compute_can_hr_approved')

Avatar
Discard

How to check login user group in odoo: https://goo.gl/Ts3qqK

Best Answer

Hi,

Update the function like this and see,


@api.depends('state')
def _compute_can_hr_approved(self):
if self.state == 'manager' and self.env.user.has_group('hr_holidays.group_hr_holidays_manager'):
self.can_hr_approved = True
else:
self.can_hr_approved = False

Thanks

Avatar
Discard
Author

It works , thanks alot

Related Posts Replies Views Activity
1
Jan 20
3686
2
Sep 19
2879
2
Nov 24
25096
2
May 24
5519
3
Mar 24
4964