From 96b8ced6ef4b3329e7e480c8668fe9093f01a203 Mon Sep 17 00:00:00 2001 From: zhouzhou <123@qq.com> Date: Fri, 20 Dec 2024 17:18:18 +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 --- .../models/yuthon_duty_plan.py | 5 +- .../models/yuthon_run_planning.py | 6 +- yuthon_wechat/models/hr_attendance_detail.py | 210 +++++++++++++++--- 3 files changed, 185 insertions(+), 36 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_duty_plan.py b/yuthon_hr_attendance/models/yuthon_duty_plan.py index d0fb862fb..798d82a0f 100644 --- a/yuthon_hr_attendance/models/yuthon_duty_plan.py +++ b/yuthon_hr_attendance/models/yuthon_duty_plan.py @@ -18,7 +18,7 @@ class YuthonDutyPlan(models.Model): select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'), ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'), ('9', '九月'), ('10', '十月'), ('11', '十一月'), - ('12', '十二月')], string='选择月份') + ('12', '十二月')], string='选择月份', default=lambda self: self._get_default_month()) # default = lambda self: self._default_month() # @api.model # def _default_month(self): @@ -137,6 +137,9 @@ class YuthonDutyPlan(models.Model): def duty_next_plan(self): self.auto_duty_plan(next_date=True) + def _get_default_month(self): + current_month = datetime.now().month + return str(current_month) class DutyPlanLine(models.Model): _name = 'duty.plan.line' diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py index 5ed3c714e..d4f3090ab 100644 --- a/yuthon_hr_attendance/models/yuthon_run_planning.py +++ b/yuthon_hr_attendance/models/yuthon_run_planning.py @@ -18,7 +18,7 @@ class YuthonRunPlanning(models.Model): select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'), ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'), ('9', '九月'), ('10', '十月'), ('11', '十一月'), - ('12', '十二月')], string='选择月份') + ('12', '十二月')], string='选择月份', default=lambda self: self._get_default_month()) # 运行班 def run_confirm(self,next_date=False): selected_month = int(self.select_time) @@ -293,6 +293,10 @@ class YuthonRunPlanning(models.Model): def comprehensive_next_planning(self): self.integrated_confirm(next_date=True) + def _get_default_month(self): + current_month = datetime.now().month + return str(current_month) + class YuthonEngineeringRunLine(models.Model): _name = 'yuthon.engineering.run.line' _description = '运行班计划明细' diff --git a/yuthon_wechat/models/hr_attendance_detail.py b/yuthon_wechat/models/hr_attendance_detail.py index 3079b82b3..200c612a1 100644 --- a/yuthon_wechat/models/hr_attendance_detail.py +++ b/yuthon_wechat/models/hr_attendance_detail.py @@ -241,6 +241,9 @@ class HrAttendanceDetail(models.Model): current_data = (sch_checkin_time + datetime.timedelta(hours=8)).strftime("%Y-%m-%d") if sch_checkin_time_now else checkin_time_now.strftime("%Y-%m-%d") # 同步整理当天出勤数据 attendance_obj = self.env['hr.attendance'].search([("userid", "=", userid), ("current_data", "=", current_data)], limit=1) + attendance_obj.attendance_type = "wx_work" + checkin_type = data.get("checkin_type", "") + exception_type = data.get("exception_type", "") if not attendance_obj: res_user_obj = self.env['res.users'].search([("oauth_uid", "=", userid)], limit=1) hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", res_user_obj.id)], limit=1) @@ -252,23 +255,22 @@ class HrAttendanceDetail(models.Model): "attendance_type": "wx_work" }) else: - if hr_employee_obj.default_planning_role_id.name == '保安部': - current_datetime_start = datetime.datetime.combine( - datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.min) - current_datetime_end = datetime.datetime.combine( - datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.max) - planning_slot_id = self.env['planning.slot'].search( - [('resource_id', '=', hr_employee_obj.resource_id.id), - ('start_datetime', '>=', current_datetime_start), - ('start_datetime', '<=', current_datetime_end)]) - if planning_slot_id: - attendance_obj = self.env['hr.attendance'].sudo().create({ - 'employee_id': hr_employee_obj.id, - "userid": userid, - "current_data": current_data, - "shift_id": planning_slot_id.id, - "attendance_type": "wx_work" - }) + current_datetime_start = datetime.datetime.combine( + datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.min) + current_datetime_end = datetime.datetime.combine( + datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.max) + planning_slot_id = self.env['planning.slot'].search( + [('resource_id', '=', hr_employee_obj.resource_id.id), + ('start_datetime', '>=', current_datetime_start), + ('start_datetime', '<=', current_datetime_end)]) + if planning_slot_id: + attendance_obj = self.env['hr.attendance'].sudo().create({ + 'employee_id': hr_employee_obj.id, + "userid": userid, + "current_data": current_data, + "shift_id": planning_slot_id.id, + "attendance_type": "wx_work" + }) if not hr_employee_obj.default_planning_role_id: # 获取考勤日历的上班下班时间 min_hour_from = self.env['resource.calendar'].search([])[0].attendance_ids[0].hour_from @@ -281,9 +283,6 @@ class HrAttendanceDetail(models.Model): # 已经审批修复无需再次进行更新数据 return True # 赋值企业微信打卡数据 - attendance_obj.attendance_type = "wx_work" - checkin_type = data.get("checkin_type", "") - exception_type = data.get("exception_type", "") will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute) will_datetime_end = checkin_time.replace(hour=max_hour, minute=max_minute) if exception_type != "未打卡": @@ -327,9 +326,7 @@ class HrAttendanceDetail(models.Model): attendance_obj.sudo().write({"is_abnormal": True}) else: attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) - elif hr_employee_obj.default_planning_role_id.name == '保安部': - attendance_obj.attendance_type = "wx_work" - checkin_type = data.get("checkin_type", "") + else: current_datetime_start = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.min) current_datetime_end = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.max) planning_id = self.env['planning.slot'].search([('resource_id', '=', hr_employee_obj.resource_id.id), @@ -338,17 +335,162 @@ class HrAttendanceDetail(models.Model): if planning_id: planning_start_time = planning_id.start_datetime planning_end_time = planning_id.end_datetime - if checkin_time: - if checkin_time and checkin_type == "上班打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "check_in": checkin_time, - "is_late_card": checkin_time > planning_start_time - }) - elif checkin_time and checkin_type == "下班打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "check_out": checkin_time, - "is_early_card": planning_end_time> checkin_time, - }) + if planning_id.department_id.name == '保安部': + # 白班上班区间 + start_time = datetime.datetime.combine(current_data, datetime.time(6, 0)) + end_time = datetime.datetime.combine(current_data, datetime.time(9, 0)) + # 白班下班区间 + start_time1 = datetime.datetime.combine(current_data, datetime.time(2, 0)) + end_time1 = datetime.datetime.combine(current_data, datetime.time(4, 0)) + # 中班上班区间 + start_time2 = datetime.datetime.combine(current_data, datetime.time(14, 0)) + end_time2 = datetime.datetime.combine(current_data, datetime.time(17, 0)) + # 中班下班区间 + start_time3 = datetime.datetime.combine(current_data, datetime.time(22, 0)) + end_time3 = datetime.datetime.combine(current_data, datetime.time(1, 0)) + # 夜班上班区间 + start_time4 = datetime.datetime.combine(current_data, datetime.time(22, 0)) + end_time4 = datetime.datetime.combine(current_data, datetime.time(1, 0)) + # 夜班下班区间 + start_time5 = datetime.datetime.combine(current_data, datetime.time(6, 0)) + end_time5 = datetime.datetime.combine(current_data, datetime.time(9, 0)) + if checkin_time: + if start_time<= checkin_time <=end_time and not attendance_obj.check_in and planning_id.template_id.planning == '白班': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif start_time1<= checkin_time <=end_time1 and not attendance_obj.check_out and planning_id.template_id.planning == '白班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_early_card": planning_end_time> checkin_time, + }) + elif start_time2 <= checkin_time <= end_time2 and not attendance_obj.check_out and planning_id.template_id.planning == '中班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif start_time3 <= checkin_time <= end_time3 and not attendance_obj.check_out and planning_id.template_id.planning == '中班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_early_card": planning_end_time > checkin_time, + }) + elif start_time4 <= checkin_time <= end_time4 and not attendance_obj.check_out and planning_id.template_id.planning == '夜班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif start_time5 <= checkin_time <= end_time5 and not attendance_obj.check_out and planning_id.template_id.planning == '夜班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_early_card": planning_end_time > checkin_time, + }) + elif attendance_obj.is_early_card or attendance_obj.is_late_card: + attendance_obj.sudo().write({"is_abnormal": True}) + else: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + elif planning_id.department_id.name == '工程部': + # 白班和白值上班区间 + start_time = datetime.datetime.combine(current_data, datetime.time(7, 0)) + end_time = datetime.datetime.combine(current_data, datetime.time(10, 0)) + # 白班和白值下班区间 + start_time1 = datetime.datetime.combine(current_data, datetime.time(16, 0)) + end_time1 = datetime.datetime.combine(current_data, datetime.time(19, 0)) + # 白值值班打卡区间 + start_time2 = datetime.datetime.combine(current_data, datetime.time(11,30)) + end_time2 = datetime.datetime.combine(current_data, datetime.time(13, 30)) + # 中夜上班区间 中夜下班区间跟白班上班区间一样 + start_time3 = datetime.datetime.combine(current_data, datetime.time(13, 0)) + end_time3 = datetime.datetime.combine(current_data, datetime.time(16, 0)) + # 中夜值班打卡区间 + start_time4 = datetime.datetime.combine(current_data, datetime.time(20, 0)) + end_time4 = datetime.datetime.combine(current_data, datetime.time(23, 0)) + if planning_id: + if checkin_time: + if start_time<= checkin_time <=end_time and not attendance_obj.check_in and (planning_id.template_id.planning in ['白班','白值']): + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif end_time1<= checkin_time <=start_time1 and not attendance_obj.check_out and (planning_id.template_id.planning in ['白班','白值']): + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_early_card": planning_end_time > checkin_time, + }) + elif start_time3<= checkin_time <=end_time3 and not attendance_obj.check_in and planning_id.template_id.planning == '中夜': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif start_time<= checkin_time <=end_time and not attendance_obj.check_in and planning_id.template_id.planning == '中夜': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_early_card":checkin_time > planning_start_time + }) + elif planning_id.template_id.planning == '白值' and start_time2 <= checkin_time <= end_time2: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "noon_duty": checkin_time, + }) + elif planning_id.template_id.planning == '中夜' and start_time4 <= checkin_time <= end_time4: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "night_duty": checkin_time, + }) + # 异常情况处理,移到所有打卡逻辑之后 + if (attendance_obj.is_early_card or attendance_obj.is_late_card or + (planning_id.template_id.planning == '白值' and not attendance_obj.noon_duty) or + (planning_id.template_id.planning == '中夜' and not attendance_obj.night_duty)): + attendance_obj.sudo().write({"is_abnormal": True}) + else: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + elif planning_id.department_id.name == '联安粮储': + # 白班上班区间 + start_time = datetime.datetime.combine(current_data, datetime.time(7, 0)) + end_time = datetime.datetime.combine(current_data, datetime.time(10, 0)) + # 白班下班区间 + start_time1 = datetime.datetime.combine(current_data, datetime.time(15, 0)) + end_time1 = datetime.datetime.combine(current_data, datetime.time(18, 0)) + # 白值上班 + start_time2 = datetime.datetime.combine(current_data, datetime.time(8,0 )) + end_time2 = datetime.datetime.combine(current_data, datetime.time(10, 0)) + # 白值下班 + start_time4 = datetime.datetime.combine(current_data, datetime.time(4, 0)) + end_time4 = datetime.datetime.combine(current_data, datetime.time(7, 0)) + # 白值打卡区间、 + start_time3 = datetime.datetime.combine(current_data, datetime.time(11, 30)) + end_time3 = datetime.datetime.combine(current_data, datetime.time(13, 30)) + if planning_id: + if start_time<= checkin_time <=end_time and not attendance_obj.check_in and planning_id.template_id.planning == '白班': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_late_card": checkin_time > planning_start_time + }) + elif start_time1<= checkin_time <=end_time1 and not attendance_obj.check_in and planning_id.template_id.planning == '白班': + attendance_obj.sudo().write({ + "check_out": checkin_time, + "is_early_card": planning_end_time > checkin_time, + }) + elif start_time2<= checkin_time <=end_time2 and not attendance_obj.check_in and planning_id.template_id.planning == '白值': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_late_card": checkin_time > planning_start_time, + }) + elif start_time4<= checkin_time <=end_time4 and not attendance_obj.check_in and planning_id.template_id.planning == '白值': + attendance_obj.sudo().write({ + "check_in": checkin_time, + "is_early_card": planning_end_time > checkin_time, + }) + elif start_time3<= checkin_time <=end_time3 and not attendance_obj.check_in and planning_id.template_id.planning == '白值': + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "noon_duty": checkin_time, + }) + if (attendance_obj.is_early_card or attendance_obj.is_late_card or + (planning_id.template_id.planning == '白值班' and not attendance_obj.noon_duty)): + attendance_obj.sudo().write({"is_abnormal": True}) + else: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) # 进行关联 attendance_detail_obj.hr_attendance_id = attendance_obj.id return True