diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 62a0fb6ec..b029f630c 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -229,7 +229,7 @@ class HolidaysRequestBatch(models.Model): column1='leave_id', column2='attachment_id' ) - holiday_allowance = fields.Html(string="常用假期额度") + holiday_allowance = fields.Text(string="常用假期额度", compute='_compute_holiday_allowance', store=True) active = fields.Boolean('Active', default=True, tracking=True) def _get_default_name_title(self): @@ -293,6 +293,21 @@ class HolidaysRequestBatch(models.Model): else: self.name = f"{self.employee_id.name}" + @api.depends('users_id') + def _compute_holiday_allowance(self): + for record in self: + holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '年假')]) + leave_id = self.env['hr.leave.allocation'].search([('employee_id', '=', record.users_id.employee_id.id), + ('holiday_status_id', '=', holiday_status_id.id)]) + employee = self.env['hr.employee'].search([('id', '=', record.users_id.employee_id.id)]) + all_overtime_hours = employee.all_overtime_hours + if leave_id: + number_of_days = int(leave_id.number_of_days) + else: + number_of_days = 0 + record.holiday_allowance = (f"1.年假分配{number_of_days}天\n" + f"2.加班{all_overtime_hours}小时") + class HrLeaveLine(models.Model): _name = 'hr.leave.line' diff --git a/yuthon_holiday/models/inherit_hr_leave_type.py b/yuthon_holiday/models/inherit_hr_leave_type.py index ef002376b..86b05c046 100644 --- a/yuthon_holiday/models/inherit_hr_leave_type.py +++ b/yuthon_holiday/models/inherit_hr_leave_type.py @@ -15,3 +15,8 @@ class HrLeaveType(models.Model): is_enable = fields.Boolean(string="启用", default=True) employee_ids = fields.Many2many('hr.employee', string='人员范围') type_of_work = fields.Selection([('0', '工作日'), ('1', '自然日')], string="工作类型", default='0') + + @api.depends_context('holiday_status_display_name', 'employee_id', 'from_manager_leave_form') + def _compute_display_name(self): + for record in self: + record.display_name = record.name \ No newline at end of file