diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 21e4792df..617396b35 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -48,6 +48,11 @@ class YuthonVacationReports(models.Model): late_allowed = fields.Float(related="employee_id.late_allowed", string="允许迟到次数") leave_ids = fields.One2many('vacation.leave.line', 'vacation_id', string='年假明细') overtime_ids = fields.One2many('vacation.over.line', 'vacation_id', string='加班明细') + # 加班明细合计字段 + overtime_workday_total = fields.Float(string='工作日合计', compute='_compute_overtime_totals', digits=(16, 1)) + overtime_legal_day_total = fields.Float(string='法定节假日合计', compute='_compute_overtime_totals', digits=(16, 1)) + overtime_public_holidays_total = fields.Float(string='公休日合计', compute='_compute_overtime_totals', digits=(16, 1)) + overtime_grand_total = fields.Float(string='总合计', compute='_compute_overtime_totals', digits=(16, 1)) meal_fee_ids = fields.One2many('vacation.meal.line', 'vacation_id', string='误餐明细') medical_fee_ids = fields.One2many('vacation.medical.line', 'vacation_id', string='体检费明细') parenting_line_ids = fields.One2many('vacation.parenting.line', 'vacation_id', string='育儿假明细') @@ -1406,6 +1411,34 @@ class YuthonVacationReports(models.Model): record.statutory_leave = legal_total/8 record.cop_leave = total_add2 / 8 + @api.depends('overtime_ids.workday', 'overtime_ids.legal_day', 'overtime_ids.public_holidays', 'overtime_ids.update_type', 'overtime_ids.is_void') + def _compute_overtime_totals(self): + """计算加班明细的合计:工作日、法定节假日、公休日的合计,以及总合计 + 根据update_type判断是增加还是减少 + """ + for record in self: + workday_total = 0.0 + legal_day_total = 0.0 + public_holidays_total = 0.0 + + for line in record.overtime_ids: + if line.is_void: + continue + + if line.update_type == 'add': + workday_total += line.workday or 0 + legal_day_total += line.legal_day or 0 + public_holidays_total += line.public_holidays or 0 + elif line.update_type == 'reduce': + workday_total -= line.workday or 0 + legal_day_total -= line.legal_day or 0 + public_holidays_total -= line.public_holidays or 0 + + record.overtime_workday_total = workday_total + record.overtime_legal_day_total = legal_day_total + record.overtime_public_holidays_total = public_holidays_total + record.overtime_grand_total = workday_total + legal_day_total + public_holidays_total + @api.depends('meal_fee_ids.update_lines', 'meal_fee_ids.update_type', 'meal_fee_ids.is_void') def _compute_meal_fee(self): for record in self: diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index 1bd0dfacc..bb15a57f6 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -250,6 +250,20 @@