Merge pull request !4186 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-07-30 13:03:46 +00:00
committed by Gitee
2 changed files with 73 additions and 4 deletions
@@ -192,11 +192,81 @@ class AppletAttendance(Controller):
res_user_id = request.env(user=SUPERUSER_ID)["res.users"].search([('id', '=', kw.get('user_id'))])
_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,
})
now_time = fields.Datetime.to_datetime(fields.Date.today()) + timedelta(hours=8, days=1)
start_time = now_time - timedelta(days=2)
@@ -84,8 +84,7 @@
<field name="name">对账</field>
<field name="res_model">property.bank.statements</field>
<field name="view_mode">tree,search</field>
<field name="domain">[('is_company', '=', True)]</field>
<field name="domain">[('bank_state', '=', 'not_reconciled')]</field>
<field name="domain">[('bank_state', '=', 'not_reconciled'), ('is_company', '=', True)]</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('yuthon_property.view_property_bank_statements_tree')})]"/>
</record>