From 9420559413ca67713219ce5d2c43eefe4a81cf41 Mon Sep 17 00:00:00 2001
From: zhou <123@>
Date: Wed, 30 Jul 2025 21:02: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
---
.../controllers/applet_attendance.py | 74 ++++++++++++++++++-
.../views/property_bank_statements_views.xml | 3 +-
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/yuthon_hr_attendance/controllers/applet_attendance.py b/yuthon_hr_attendance/controllers/applet_attendance.py
index 120959e12..aa574c035 100644
--- a/yuthon_hr_attendance/controllers/applet_attendance.py
+++ b/yuthon_hr_attendance/controllers/applet_attendance.py
@@ -204,11 +204,81 @@ class AppletAttendance(Controller):
# user_id = request.env['res.users'].sudo().browse(uid)
_logger.info(f"传过来的user_id:{kw.get('user_id')},名称{res_user_id.name}")
employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('name', '=', res_user_id.name)])
- if res_user_id:
+ if res_user_id and employee_id:
+ # 初始化变量
+ checkin_type = None
+ current_datetime = fields.Datetime.now() # 打卡时间
+ current_date = current_datetime.date()
+
+ department = employee_id.department_id
+ slot_template = None
+ if department:
+ slot_template = request.env(user=SUPERUSER_ID)["planning.slot.template"].search(
+ [('department_id', '=', department.id)],
+ limit=1
+ )
+ if not slot_template:
+ slot_template = request.env(user=SUPERUSER_ID)["planning.slot.template"].search(
+ [('planning_name', '=', '集团行政')],
+ limit=1
+ )
+ if slot_template:
+ if slot_template.planning_name == "集团行政":
+ groupname = "集团行政"
+ elif slot_template.role_id and slot_template.planning_name:
+ groupname = f"{slot_template.role_id.name} - {slot_template.planning_name}"
+
+ # 时间转换辅助函数(考虑day2次日标记)
+ def get_schedule_datetime(float_hour, is_check_out_end=False, is_day2=False):
+ if float_hour is None:
+ return None
+ # 只有下班结束时间且是次日时才加一天
+ base_date = current_date
+ if is_check_out_end and is_day2:
+ base_date = current_date + timedelta(days=1)
+ hours = int(float_hour)
+ minutes = int((float_hour - hours) * 60)
+ return datetime.combine(base_date, datetime.min.time()) + timedelta(hours=hours, minutes=minutes)
+
+ # 解析班次时间
+ check_in_start = None
+ check_in_end = None
+ check_out_start = None
+ check_out_end = None
+ if slot_template:
+ if slot_template:
+ check_in_start = get_schedule_datetime(slot_template.check_in_start)
+ check_in_end = get_schedule_datetime(slot_template.check_in_end)
+ check_out_start = get_schedule_datetime(slot_template.check_out_start)
+ check_out_end = get_schedule_datetime(slot_template.check_out_end,is_check_out_end=True,is_day2=slot_template.day2)
+ # 检查该员工是否已有上班打卡记录
+ has_checkin = False
+ if employee_id:
+ # 查询今天是否有上班打卡记录
+ checkin_records = request.env(user=SUPERUSER_ID)["hr.attendance.detail"].search([
+ ('employee_id', '=', employee_id.id),
+ ('checkin_type', '=', '上班打卡'),
+ ('checkin_time', '>=', fields.Datetime.to_string(current_date)),
+ ('checkin_time', '<', fields.Datetime.to_string(current_date + timedelta(days=1)))
+ ])
+ has_checkin = bool(checkin_records)
+ sch_checkin_time = check_in_start
+ # 判断打卡类型并设置标准打卡时间
+ if check_in_start and check_in_end and check_in_start <= current_datetime <= check_in_end:
+ checkin_type = "上班打卡"
+ sch_checkin_time = check_in_start
+ elif has_checkin and check_out_start and check_out_end and check_out_start <= current_datetime <= check_out_end:
+ checkin_type = "下班打卡"
+ sch_checkin_time = check_out_end
+
+ # 创建考勤记录
request.env(user=SUPERUSER_ID)["hr.attendance.detail"].create({
'employee_id': employee_id.id,
- 'checkin_time': fields.Datetime.now(),
+ 'checkin_time': current_datetime,
'source': 'mini_programs',
+ 'groupname': groupname,
+ 'checkin_type': checkin_type,
+ 'sch_checkin_time': sch_checkin_time,
})
return_data = {'code': '200', 'message': '打卡成功'}
_logger.info("打卡记录创建成功")
diff --git a/yuthon_property/views/property_bank_statements_views.xml b/yuthon_property/views/property_bank_statements_views.xml
index 910bf8460..b3bb54adc 100644
--- a/yuthon_property/views/property_bank_statements_views.xml
+++ b/yuthon_property/views/property_bank_statements_views.xml
@@ -84,8 +84,7 @@
对账
property.bank.statements
tree,search
- [('is_company', '=', True)]
- [('bank_state', '=', 'not_reconciled')]
+ [('bank_state', '=', 'not_reconciled'), ('is_company', '=', True)]