Merge pull request !3728 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-07-08 08:34:52 +00:00
committed by Gitee
3 changed files with 46 additions and 7 deletions
@@ -1,6 +1,6 @@
from odoo.http import Controller, request, route
from odoo import models, fields, api, http, SUPERUSER_ID, _
from datetime import datetime
from datetime import datetime,date
import logging
from geopy.distance import geodesic
from datetime import timedelta
@@ -48,10 +48,10 @@ class AppletAttendance(Controller):
}
"""
_logger.info("----------------/yuthon/att/today---------接口收到响应-------------------------------")
current_data = fields.Date.today()
current_date = fields.Date.today()
user_id = request.env(user=SUPERUSER_ID)["res.users"].search([('id', '=', int(kw['user_id']))])
employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('name', '=', user_id.name)])
attendance_id = request.env(user=SUPERUSER_ID)["hr.attendance"].search([('employee_id', '=', employee_id.id), ('current_data', '=', current_data)])
attendance_id = request.env(user=SUPERUSER_ID)["hr.attendance"].search([('employee_id', '=', employee_id.id), ('current_data', '=', current_date)])
check_in = attendance_id.check_in + timedelta(hours=8) if attendance_id.check_in else ''
check_out = attendance_id.check_out + timedelta(hours=8) if attendance_id.check_out else ''
check_in_start = attendance_id.shift_id.template_id.check_in_start
@@ -86,10 +86,14 @@ class AppletAttendance(Controller):
message = '可以打卡'
state = 'yes'
break
if self.is_workday(current_date):
attendance_id_class = f"{attendance_id.shift_name}{start_time_str}-{end_time_str}"
else:
attendance_id_class = f"{attendance_id.shift_name}/休息"
data = {
'location': self_address['formatted_address'],
'user_id': user_id.id,
'class': f"{attendance_id.shift_name}{start_time_str}-{end_time_str}",
'class': f"{attendance_id_class}",
'state_result': state_result,
'check_in': check_in_html,
'check_in_status': check_in_status,
@@ -102,6 +106,41 @@ class AppletAttendance(Controller):
_logger.info(f"人员{employee_id.name}地址{self_address['formatted_address']}__________")
return json.dumps(return_data)
def is_workday(self, date):
"""判断指定日期是否为工作日(考虑法定节假日和调休)
如果是工作日返回True
如果是休息日返回False
"""
calendar_leaves = request.env['resource.calendar.leaves'].sudo().search([("calendar_id", "=", "行政考勤工作日")])
holidays_set = set()
shift_days_set = set()
for leave in calendar_leaves:
if leave.holidays:
holidays_set.update(leave.holidays.split(','))
if leave.alternate_rest_day:
holidays_set.update(leave.alternate_rest_day.split(','))
if leave.shift_replacement_day:
shift_days_set.update(leave.shift_replacement_day.split(','))
date_str = date.strftime('%m月%d日')
date_str = self.remove_leading_zero(date_str)
is_weekend = date.weekday() in [5, 6]
if date_str in holidays_set:
return False
elif date_str in shift_days_set:
return True
else:
return not is_weekend
def remove_leading_zero(self, date_str):
month, day = date_str.split('月')
month = month.lstrip('0')
day = day.rstrip('日')
day = day.lstrip('0')
return f'{month}月{day}日'
def is_within_radius_geopy(self, lat1, lon1, lat2, lon2, radius_km):
"""
使用geopy库判断是否在范围内
@@ -13,7 +13,7 @@ class YutransferApproval(models.Model):
code = fields.Char(string="编号",
default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_leaving_approval_code'))
users_id = fields.Many2one('res.users', string="录入人", default=lambda self: self.env.user.id)
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
department_id = fields.Many2one(related='employee_id.department_id', string="部门")
main_post = fields.Many2one("hr.job", string="主岗")
duties = fields.Char(string="职务")
job_type_id = fields.Many2one('hr.job.type', string="岗位类别")
@@ -52,7 +52,7 @@
</group>
<group string="基础信息" col="3">
<group>
<field name="department_id" widget="ztree_select"/>
<field name="department_id"/>
</group>
<group>
<field name="users_id"/>
@@ -67,7 +67,7 @@
<field name="reward_results_ids" string=" ">
<tree editable="bottom">
<field name="name"/>
<field name="department_id" widget="ztree_select"/>
<field name="department_id"/>
<field name="job_id"/>
<field name="reward_punishment_id"/>
<field name="reward_punishment_type"/>