diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 008ab5198..142012da8 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -69,61 +69,6 @@ class HrAttendance(models.Model): format_datetime(self.env, attendance.check_out, dt_format="HH:mm"), ) - # @api.depends('check_in', 'check_out') - # def _compute_attendance_flags(self): - # for record in self: - # record.is_no_card = False - # record.is_late_card = False - # record.is_early_card = False - # if not record.employee_id.resource_id.calendar_id.attendance_ids: - # department_names = ['保安部', '班组A', '班组B', '班组C', '工程部', '运行班', '高压班', '综合班'] - # department_ids = self.env['hr.department'].search([('name', 'in', department_names)]).ids - # employee_ids = self.env['hr.employee'].search([('department_id', 'in', department_ids)]) - # for employee_id in employee_ids: - # planning_ids = self.env['planning.slot'].search([('resource_id', '=', employee_id.resource_id.id)]) - # for planning_id in planning_ids: - # start_date = planning_id.start_datetime.date() - # attendance_id = self.env['hr.attendance'].search( - # [('employee_id', '=', employee_id.id), ('current_data', '=', start_date)]) - # if attendance_id: - # if attendance_id.check_in: - # check_in = attendance_id.check_in + timedelta(hours=8) - # attendance_id.is_late_card = check_in > planning_id.start_datetime - # else: - # attendance_id.is_no_card = True - # if attendance_id.check_out: - # check_in = attendance_id.check_in + timedelta(hours=8) - # attendance_id.is_early_card = planning_id.end_datetime > check_in - # else: - # attendance_id.is_no_card = True - # else: - # min_hour_from = record.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) - # if record.check_in: - # check_in = record.check_in + timedelta(hours=8) - # will_datetime_start = check_in.replace(hour=min_hour, minute=min_minute) - # record.is_late_card = check_in > will_datetime_start - # else: - # record.is_no_card = True - # max_hour_to = record.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) - # if record.check_out: - # check_out = record.check_out + timedelta(hours=8) - # will_datetime_end = check_out.replace(hour=max_hour, minute=max_minute) - # record.is_early_card = will_datetime_end > check_out - # else: - # record.is_no_card = True - # if record.employee_id in record.employee_id.resource_id.calendar_id.resource_user_ids: - # if record.check_in or record.check_out: - # record.write({ - # 'is_abnormal': False, - # 'is_late_card': False, - # 'is_early_card': False, - # 'is_no_card': False - # }) - def add_comment(self): self.ensure_one() menu_id = self.env['ir.ui.menu'].search([('name', '=', '我的异常')]) @@ -153,14 +98,6 @@ class HrAttendance(models.Model): title="打卡异常提醒", description="本月迟到: {}\n本月缺卡: {}\n本月早退: {}\n".format(is_late_card, is_no_card, is_early_card), url=str, btntxt="详细信息") - # @api.depends('is_no_card', 'is_early_card', 'is_late_card') - # def _compute_is_abnormal(self): - # for record in self: - # record.is_abnormal = False - # if record.week not in ["six", "seven"]: - # record.is_abnormal = record.is_no_card or record.is_early_card or record.is_late_card - # record.abnormal = int(record.is_no_card or record.is_early_card or record.is_late_card) - def button_leave(self): form_id = self.env.ref('yuthon_holiday.view_hr_leave_batch_form').id return { diff --git a/yuthon_hr_attendance/models/yuthon_duty_plan.py b/yuthon_hr_attendance/models/yuthon_duty_plan.py index f617edea2..8ed990c3c 100644 --- a/yuthon_hr_attendance/models/yuthon_duty_plan.py +++ b/yuthon_hr_attendance/models/yuthon_duty_plan.py @@ -3,6 +3,7 @@ from datetime import datetime, time, timedelta, date from odoo.exceptions import UserError +# todo 默认当前月份,安排下个月是月份字段+1 注意月份 Selection用1-12 代码优化 class YuthonDutyPlan(models.Model): _name = 'yuthon.duty.plan' _description = '值班计划' @@ -12,13 +13,19 @@ class YuthonDutyPlan(models.Model): end_index_time = fields.Date(string='失效时间') is_enable = fields.Boolean(string="启用", default=True) plan_line_ids = fields.One2many('duty.plan.line', 'duty_plan_id', string='关联计划明细') + white_line_ids = fields.One2many('white.plan.line', 'duty_plan_id', string='关联计划明细') notice = fields.Text(string='计划说明') select_time = fields.Selection([('January', '一月'), ('February', '二月'), ('March', '三月'), ('April', '四月'), ('May', '五月'), ('June', '六月'), ('July', '七月'), ('August', '八月'), ('September', '九月'), ('October', '十月'), ('November', '十一月'), ('December', '十二月')], string='选择月份') + # default = lambda self: self._default_month() + # @api.model + # def _default_month(self): + # current_month = datetime.now().strftime('%B') + # return current_month - def auto_duty_plan(self,next_date=False): + def auto_duty_plan(self, next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, @@ -92,6 +99,38 @@ class YuthonDutyPlan(models.Model): week = i.start_datetime.weekday() if week == 5 or week == 6: i.sudo().unlink() + + + other_data = {} + for other in self.white_line_ids: + if other.employee_id: + other_resource_id = other.employee_id.resource_id + regular_holiday = other.regular_holidays + weekday_mapping = {'one': 7, 'two': 1, 'three': 2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6} + weekday_number = weekday_mapping.get(regular_holiday) + other_data[other_resource_id.id] = weekday_number + + for employee in self.white_line_ids: + current_date = first_day_of_month + while current_date <= last_day_of_month: + current_datetime = datetime.combine(current_date, time(0, 0, 0)) + start_hour = int(role_template_a.start_time) + end_hour = int(role_template_a.end_time) + start_time = current_datetime.replace(hour=start_hour, minute=30) - timedelta(hours=8) + end_time = current_datetime.replace(hour=end_hour, minute=30) - timedelta(hours=8) + resource_id = employee.employee_id.resource_id + if not other_data[resource_id.id] == datetime(current_date.year, current_date.month,current_date.day).weekday(): + self.env['planning.slot'].create({ + 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).id, + 'resource_id': resource_id.id, + 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, start_time) + timedelta(hours=16) - timedelta(days=1), + 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, end_time) + timedelta(hours=16) - timedelta(days=1), + 'role_id': role_a.id, + 'allocated_hours': 8, + }) + current_date += timedelta(days=1) + if current_date > last_day_of_month: + break return { 'type': 'ir.actions.client', 'tag': 'display_notification', @@ -105,6 +144,7 @@ class YuthonDutyPlan(models.Model): def duty_next_plan(self): self.auto_duty_plan(next_date=True) + class DutyPlanLine(models.Model): _name = 'duty.plan.line' _description = '值班计划明细行' @@ -113,3 +153,15 @@ class DutyPlanLine(models.Model): duty_plan_id = fields.Many2one('yuthon.duty.plan', string='关联计划名称') employee_ids = fields.Many2many('hr.employee', string='值班人员') duty_class_id = fields.Many2one('yuthon.duty.class.setting', string="班组名称") + + +class WhitePlanLine(models.Model): + _name = 'white.plan.line' + _description = '值班常白计划明细行' + + sequence = fields.Char(string='序号', store=True) + duty_plan_id = fields.Many2one('yuthon.duty.plan', string='关联计划名称') + employee_id = fields.Many2one('hr.employee', string='值班人员') + regular_holidays = fields.Selection([('one', '星期一'), ('two', '星期二'), ('three', '星期三'), + ('four', '星期四'), ('five', '星期五'), ('six', '星期六'), + ('seven', '星期日')], string='固定休息日') diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py index 55f356a82..81cb0bd17 100644 --- a/yuthon_hr_attendance/models/yuthon_run_planning.py +++ b/yuthon_hr_attendance/models/yuthon_run_planning.py @@ -3,6 +3,7 @@ from datetime import datetime, time, timedelta from odoo.exceptions import UserError from datetime import date, timedelta + class YuthonRunPlanning(models.Model): _name = 'yuthon.run.planning' _description = '工程部排班计划' diff --git a/yuthon_hr_attendance/security/ir.model.access.csv b/yuthon_hr_attendance/security/ir.model.access.csv index 178ddeda2..99aeafbf3 100644 --- a/yuthon_hr_attendance/security/ir.model.access.csv +++ b/yuthon_hr_attendance/security/ir.model.access.csv @@ -25,6 +25,7 @@ access_yuthon_customer_approval,yuthon.customer.approval,model_yuthon_customer_a access_yuthon_duty_plan,yuthon.duty.plan,model_yuthon_duty_plan,base.group_user,1,1,1,1 access_duty_plan_line,duty.plan.line,model_duty_plan_line,base.group_user,1,1,1,1 +access_white_plan_line,white.plan.line,model_white_plan_line,base.group_user,1,1,1,1 access_yuthon_duty_class_setting,yuthon.duty.class.setting,model_yuthon_duty_class_setting,base.group_user,1,1,1,1 access_yuthon_adjustments_approval,yuthon.adjustments.approval,model_yuthon_adjustments_approval,base.group_user,1,1,1,1 access_yuthon_abnormal_approval,yuthon.abnormal.approval,model_yuthon_abnormal_approval,base.group_user,1,1,1,1 diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index 5b85c5d02..0f0ffe6c7 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -160,28 +160,31 @@ hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company','=','thtz'), ('week', 'not in', ['seven', 'six'])]] + [('employee_id.yuthon_company','=','thtz'), ('week', 'not in', ['seven', 'six'])] 天河粮储 hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company', '=', 'thlc'), ('week', 'not in', ['seven', 'six'])]] + [('employee_id.yuthon_company', '=', 'thlc'), + ('week', 'not in', ['seven', 'six']), + ('employee_id.department_id.name','not in',['仓储组', '综合组','保管组', '机安组', '1库', '2库', '3库', '联安粮库'])] 天河物管 hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company', '=', 'thwg'), ('week', 'not in', ['seven', 'six'])]] + [('employee_id.yuthon_company', '=', 'thwg'), ('week', 'not in', ['seven', 'six']), + ('employee_id.department_id.name','not in',['运行班', '高压班','综合班','班组A', '班组B','班组C'])] 考勤记录 hr.attendance tree {"search_default_employee": 1} - [('employee_id.department_id.name','in',['保安部', '班组A', '班组B','班组C'])] + [('employee_id.department_id.name','in',['班组A', '班组B','班组C'])] @@ -190,7 +193,7 @@ hr.attendance tree {"search_default_employee": 1} - [('employee_id.department_id.name','in',['工程部', '运行班', '高压班','综合班'])]] + [('employee_id.department_id.name','in',['运行班', '高压班','综合班'])] @@ -199,7 +202,7 @@ hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.department_id.name','in',['仓储组', '综合组','保管组', '机安组', '1库', '2库', '3库', '联安粮库'])]] + [('employee_id.department_id.name','in',['仓储组', '综合组','保管组', '机安组', '1库', '2库', '3库', '联安粮库'])] diff --git a/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml b/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml index 6118fedeb..a8063887b 100644 --- a/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml +++ b/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml @@ -39,21 +39,31 @@ - - - - - - - - - - - - + +
+ + + + + + + + +
+ +
+ + + + + + + + +
diff --git a/yuthon_wechat/models/hr_attendance_detail.py b/yuthon_wechat/models/hr_attendance_detail.py index 1e880801a..24abc164e 100644 --- a/yuthon_wechat/models/hr_attendance_detail.py +++ b/yuthon_wechat/models/hr_attendance_detail.py @@ -266,349 +266,343 @@ class HrAttendanceDetail(models.Model): 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 hr_employee_obj.default_planning_role_id: - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > 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}) + # if not hr_employee_obj.default_planning_role_id: + if exception_type != "未打卡": + if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, + }) + elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, + }) + elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, + }) + elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, + }) + elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, + }) + elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, + }) + elif attendance_obj.is_early_card or attendance_obj.is_late_card: + attendance_obj.sudo().write({"is_abnormal": True}) else: - current_datetime_start = datetime.datetime.combine(current_data, datetime.time.min) - current_datetime_end = datetime.datetime.combine(current_data, 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: - if planning_slot_id.department_id.name == '保安部': - 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 exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.is_early_card or attendance_obj.is_late_card: - attendance_obj.sudo().write({"is_abnormal": True}) - elif planning_slot_id.department_id.name == '工程部': - 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 planning_slot_id.template_id.planning_name == '中值': - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif datetime.time(11, 30)<= checkin_time <= datetime.time(13, 30): - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "noon_duty":False - }) - elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: - attendance_obj.sudo().write({"is_abnormal": True}) - else: - attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) - elif planning_slot_id.template_id.planning_name == '夜值': - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or - datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)): - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "night_duty": False - }) - elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.night_duty: - attendance_obj.sudo().write({"is_abnormal": True}) - else: - attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) - else: - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: - attendance_obj.sudo().write({"is_abnormal": True}) - else: - attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) - elif planning_slot_id.department_id.name == '联安粮库': - 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 planning_slot_id.template_id.planning_name == '夜值': - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or - datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)): - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "night_duty": False - }) - elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: - attendance_obj.sudo().write({"is_abnormal": True}) - else: - attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) - else: - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time, - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime, - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > 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}) - # 进行关联 + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # 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_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: + # if planning_slot_id.department_id.name == '保安部': + # 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 exception_type != "未打卡": + # 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_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.is_early_card or attendance_obj.is_late_card: + # attendance_obj.sudo().write({"is_abnormal": True}) + # elif planning_slot_id.department_id.name == '工程部': + # 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 planning_slot_id.template_id.planning_name == '中值': + # if exception_type != "未打卡": + # if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif datetime.time(11, 30)<= checkin_time <= datetime.time(13, 30): + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "noon_duty":False + # }) + # elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: + # attendance_obj.sudo().write({"is_abnormal": True}) + # else: + # attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # elif planning_slot_id.template_id.planning_name == '夜值': + # if exception_type != "未打卡": + # if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or + # datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)): + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "night_duty": False + # }) + # elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.night_duty: + # attendance_obj.sudo().write({"is_abnormal": True}) + # else: + # attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # else: + # if exception_type != "未打卡": + # if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: + # attendance_obj.sudo().write({"is_abnormal": True}) + # else: + # attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # elif planning_slot_id.department_id.name == '联安粮库': + # 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 planning_slot_id.template_id.planning_name == '夜值': + # if exception_type != "未打卡": + # if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or + # datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)): + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "night_duty": False + # }) + # elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty: + # attendance_obj.sudo().write({"is_abnormal": True}) + # else: + # attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # else: + # if exception_type != "未打卡": + # if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > checkin_time, + # }) + # elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_in_time": sch_checkin_time, + # "check_in": checkin_time, + # "is_late_card": checkin_time > planning_slot_id.start_datetime, + # }) + # elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + # attendance_obj.sudo().write({ + # "sch_check_out_time": sch_checkin_time, + # "check_out": checkin_time, + # "is_early_card": planning_slot_id.end_datetime > 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}) + # # 进行关联 attendance_detail_obj.hr_attendance_id = attendance_obj.id return True def get_hr_attendance_time(self):