i'm using odoo11 and i have installed a custom module to calculate the overtime. i have many team leaders. Every team leader he has a number of employee .I want to limit the approve action for the manager in a way every manager approve request of his own employees only. i have override the approve action to verify if the person who's gone approve is his manager or not but always it allows any manager to approve all the requests. Here is code :
overtime.py
class BtHrOvertime(models.Model): _name = "bt.hr.overtime" _description = "Bt Hr Overtime" _rec_name = 'employee_id' _order = 'id desc' employee_id = fields.Many2one('hr.employee', string="Employee") manager_id = fields.Many2one('hr.employee', string='Manager') start_date = fields.Datetime('Date check in') end_date = fields.Datetime('Date check out') overtime_hours = fields.Float('Overtime Hours') notes = fields.Text(string='Notes') state = fields.Selection([('draft', 'Draft'), ('confirm', 'Waiting for Approval'), ('refuse', 'Refused'), ('validate', 'Approved'), ('cancel', 'Cancelled')], default='draft', copy=False) attendance_id = fields.Many2one('hr.attendance', string='Attendance') user_id = fields.Many2one('res.users', string='User', related='employee_id.user_id', related_sudo=True, compute_sudo=True, store=True, default=lambda self: self.env.uid, readonly=True) parent_id = fields.Many2one('bt.hr.overtime', string='Parent', copy=False) @api.multi def action_approve(self): if (self.employee_id.parent_id.user_id.id != uid): raise exceptions.UserError(_('You cannot approve.')) elif self.attendance_id.check_in and self.attendance_id.check_out: start_date = datetime.datetime.strptime(self.attendance_id.check_in, DEFAULT_SERVER_DATETIME_FORMAT) end_date = datetime.datetime.strptime(self.attendance_id.check_out, DEFAULT_SERVER_DATETIME_FORMAT) difference = end_date - start_date hour_diff = str(difference).split(':')[0] min_diff = str(difference).split(':')[1] tot_diff = hour_diff + '.' + min_diff actual_working_hours = float(tot_diff) for record in self: if actual_working_hours > 9: record.overtime_hours = actual_working_hours - 9 record.start_date = record.attendance_id.check_in record.end_date = record.attendance_id.check_out else: record.overtime_hours = 0 record.start_date = record.attendance_id.check_in record.end_date = record.attendance_id.check_out return self.write({'state': 'validate'})