From dec36839addbfddaefc978fcedbc788a34574240 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Thu, 10 Apr 2025 15:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_hr_attendance/models/card_approval.py | 78 +++++++++++-------- yuthon_hr_attendance/models/go_approval.py | 29 ++++++- yuthon_hr_attendance/models/hr_attendance.py | 6 +- yuthon_hr_attendance/views/card_approval.xml | 4 +- yuthon_hr_attendance/views/go_approval.xml | 26 +++++-- .../views/hr_attendance_views.xml | 2 +- .../models/yuthon_payroll_project.py | 6 +- .../inherit_hr_payroll_structure_views.xml | 1 + 8 files changed, 98 insertions(+), 54 deletions(-) diff --git a/yuthon_hr_attendance/models/card_approval.py b/yuthon_hr_attendance/models/card_approval.py index 389329137..9cd257597 100644 --- a/yuthon_hr_attendance/models/card_approval.py +++ b/yuthon_hr_attendance/models/card_approval.py @@ -25,6 +25,8 @@ class CardApprovals(models.Model): reason_application = fields.Html(string="申请事由") documents_ids = fields.Many2many('ir.attachment', string="附件") attendance_id = fields.Many2one('hr.attendance', string="补卡日期") + attendance = fields.Char(string="补卡日期") + is_attendance = fields.Boolean(string="字段隐藏") replacement_time = fields.Selection([('work', '上班卡'), ('quitting', '下班卡'), ('all', '全天卡')], string="补卡", store=True) active = fields.Boolean('Active', default=True) urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度', @@ -39,6 +41,7 @@ class CardApprovals(models.Model): @api.onchange('attendance_id') def onchange_replacement_time(self): for rep in self: + rep.attendance = rep.attendance_id.display_name rep.replacement_time = None if rep.attendance_id.is_early_card and not rep.attendance_id.is_late_card: rep.replacement_time = 'quitting' @@ -71,41 +74,48 @@ class CardApprovals(models.Model): record.name = f"{record.users_id.name}补卡" def confirm_approval(self): - if not self.users_id.employee_id.resource_id.calendar_id: - planning_id = self.env['planning.slot.template'].search([('planning_name', '=', self.shift_id.template_id.planning_name), ('department_id.name', '=', self.shift_id.role_id.name)], limit=1) - start_hour = int(planning_id.start_time) - end_hour = float(planning_id.end_time) - hour = int(end_hour) # 小时部分 - current_datetime = datetime.combine(self.attendance_id.current_data, time(0, 0, 0)) - start_time = current_datetime.replace(hour=start_hour) - timedelta(hours=8) - end_time = current_datetime.replace(hour=hour)- timedelta(hours=8) - self.attendance_id.write({'check_in': start_time, 'check_out': end_time}) - else: - min_hour_from = self.users_id.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from - min_hour = int(min_hour_from) - min_minute = int(min_hour_from * 10 % min_hour_from) - max_hour_to = self.users_id.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to - max_hour = int(max_hour_to) - max_minute = int(max_hour_to * 10 % max_hour_to) - for rec in self: - current_data = rec.attendance_id.current_data - current_datetime = datetime.combine(current_data, datetime.min.time()) - if rec.attendance_id.check_in: - rec.attendance_id.check_in = rec.attendance_id.check_in.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8) - else: - rec.attendance_id.check_in = current_datetime.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8) - if rec.attendance_id.check_out: - rec.attendance_id.check_out = rec.attendance_id.check_in.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8) - else: - rec.attendance_id.check_out = current_datetime.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8) + if not self.users_id.employee_id.resource_id.calendar_id: + planning_id = self.env['planning.slot.template'].search([('planning_name', '=', self.shift_id.template_id.planning_name), ('department_id.name', '=', self.shift_id.role_id.name)], limit=1) + start_hour = int(planning_id.start_time) + end_hour = float(planning_id.end_time) + hour = int(end_hour) # 小时部分 + current_datetime = datetime.combine(self.attendance_id.current_data, time(0, 0, 0)) + start_time = current_datetime.replace(hour=start_hour) - timedelta(hours=8) + end_time = current_datetime.replace(hour=hour)- timedelta(hours=8) + original_attendance = self.attendance + self.attendance_id.write({'check_in': start_time, 'check_out': end_time}) + self.is_attendance = True + self.attendance = original_attendance - self.attendance_id.sudo().write({ - 'is_approval': True, - 'is_abnormal': False, - 'is_no_card': False, - 'is_late_card': False, - 'is_early_card': False, - }) + else: + min_hour_from = self.users_id.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from + min_hour = int(min_hour_from) + min_minute = int(min_hour_from * 10 % min_hour_from) + max_hour_to = self.users_id.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to + max_hour = int(max_hour_to) + max_minute = int(max_hour_to * 10 % max_hour_to) + for rec in self: + current_data = rec.attendance_id.current_data + current_datetime = datetime.combine(current_data, datetime.min.time()) + original_attendance = self.attendance + if rec.attendance_id.check_in: + rec.attendance_id.check_in = rec.attendance_id.check_in.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8) + else: + rec.attendance_id.check_in = current_datetime.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8) + if rec.attendance_id.check_out: + rec.attendance_id.check_out = rec.attendance_id.check_in.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8) + else: + rec.attendance_id.check_out = current_datetime.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8) + self.is_attendance = True + self.attendance = original_attendance + + self.attendance_id.sudo().write({ + 'is_approval': True, + 'is_abnormal': False, + 'is_no_card': False, + 'is_late_card': False, + 'is_early_card': False, + }) @api.onchange('is_issues') def _onchange_is_issues(self): diff --git a/yuthon_hr_attendance/models/go_approval.py b/yuthon_hr_attendance/models/go_approval.py index 3376fbe09..c4c6896e9 100644 --- a/yuthon_hr_attendance/models/go_approval.py +++ b/yuthon_hr_attendance/models/go_approval.py @@ -35,12 +35,33 @@ class GoApprovals(models.Model): default='normal') active = fields.Boolean('Active', default=True, tracking=True) work_end = fields.Boolean(string="结束") + is_day = fields.Boolean(string="按天") + is_hour = fields.Boolean(string="按小时") + start_day_selection = fields.Selection([('half', '上半天'),('afternoon', '下半天')], string="天") + end_day_selection = fields.Selection([('half', '上半天'), ('afternoon', '下半天')], string="天") + statr_date = fields.Date(string="开始日期") + end_date = fields.Date(string="结束日期") def _get_default_name_title(self): return self._description if self._description else self._name name_title = fields.Char(default=_get_default_name_title) + @api.onchange('start_day_selection', 'end_day_selection') + def _onchange_selection_fields(self): + for record in self: + if record.start_day_selection == 'afternoon' and record.end_day_selection == 'half': + raise ValidationError("当开始日期为下半天时,结束选择日期只能下半天。") + if record.start_day_selection == 'afternoon' and record.end_day_selection == 'afternoon': + record.hours = 4 + record.days = 0.5 + elif record.start_day_selection == 'half' and record.end_day_selection == 'afternoon': + record.hours = 8 + record.days = 1 + else: + record.hours = 0 + record.days = 0 + @api.onchange('date_start', 'date_end') def _onchange_date_range(self): if self.date_start and self.date_end: @@ -70,11 +91,11 @@ class GoApprovals(models.Model): @api.depends('users_id', 'days', 'hours') def _compute_name(self): for rec in self: - if rec.days == 0 and rec.hours == 0: - rec.name = f"{rec.users_id.name}外出" - elif rec.days == 0: + if rec.is_hour == True: rec.name = f"{rec.users_id.name}外出{rec.hours}小时" + elif rec.is_day == True: + rec.name = f"{rec.users_id.name}外出{rec.days}天" else: - rec.name = f"{rec.users_id.name}外出{rec.days}天{rec.hours}小时" + rec.name = f"{rec.users_id.name}外出" diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index f86f0fe09..298398848 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -58,7 +58,7 @@ class HrAttendance(models.Model): if not attendance.check_out: attendance.display_name = _( str(attendance.current_data) + " 上午:%s" + is_late_card + " -下午缺卡", - format_datetime(self.env, attendance.check_in, dt_format="HH:mm"), + format_datetime(self.env, attendance.check_in, dt_format="HH:mrm"), ) elif not attendance.check_in: attendance.display_name = _( @@ -192,7 +192,7 @@ class HrAttendance(models.Model): max_hour = int(max_hour_to) max_minute = int(max_hour_to * 10 % max_hour_to) will_datetime_end = current_date.replace(year=year, month=month, day=day, hour=max_hour, minute=max_minute) - timedelta(hours=8) - record.write({'check_out': will_datetime_end, 'is_approval': True, 'is_abnormal':False, 'is_no_card':False, 'is_early_card':False, 'is_late_card':False }) + record.write({'check_out': will_datetime_end, 'is_approval': True, 'is_abnormal':False, 'is_no_card':False, 'is_early_card':False, 'is_late_card':False, 'absenteeism_card':False}) else: check_in_start = record.shift_id.template_id.check_in_start check_out_end = record.shift_id.template_id.check_out_end @@ -212,7 +212,7 @@ class HrAttendance(models.Model): end_datetime = end_datetime + timedelta(days=1) record.write( {'check_out': end_datetime, 'check_in':start_datetime, 'is_approval': True, 'is_abnormal': False, 'is_no_card': False, - 'is_early_card': False, 'is_late_card': False}) + 'is_early_card': False, 'is_late_card': False, 'absenteeism_card':False}) def button_batch_correct(self): attendance_ids = self.env["hr.attendance"].browse(self._context.get('active_ids', self._context.get('active_id'))) diff --git a/yuthon_hr_attendance/views/card_approval.xml b/yuthon_hr_attendance/views/card_approval.xml index bb446c5ba..985ae9a07 100644 --- a/yuthon_hr_attendance/views/card_approval.xml +++ b/yuthon_hr_attendance/views/card_approval.xml @@ -49,7 +49,9 @@ - + + + diff --git a/yuthon_hr_attendance/views/go_approval.xml b/yuthon_hr_attendance/views/go_approval.xml index 2cac1f8b0..a6a24b917 100644 --- a/yuthon_hr_attendance/views/go_approval.xml +++ b/yuthon_hr_attendance/views/go_approval.xml @@ -49,25 +49,35 @@ - - - + + + + - - + + + + + + + + + + + + + + - - - diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index 5023bf56e..a5131bffe 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -28,7 +28,7 @@