|
|
|
@@ -14,6 +14,17 @@ class AppletAttendance(Controller):
|
|
|
|
|
小程序考勤接口
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@http.route('/ro/base/user/login/v1', type='http', auth="public", csrf=False, cors='*')
|
|
|
|
|
def ro_base_user_login_v1(self, **kw):
|
|
|
|
|
password = kw.get('password')
|
|
|
|
|
login = kw.get('login')
|
|
|
|
|
uid = request.session.authenticate(request.env.cr.dbname, login, password)
|
|
|
|
|
user_id = request.env['res.users'].sudo().browse(uid)
|
|
|
|
|
employee_id = user_id.with_company(user_id.company_id.id).employee_id
|
|
|
|
|
data = {'name': employee_id.name, 'id': user_id.id}
|
|
|
|
|
return_data = {'data': data, 'code': 200, 'message': ''}
|
|
|
|
|
return json.dumps(return_data)
|
|
|
|
|
|
|
|
|
|
@route('/yuthon/att/today', methods=['POST'], type='http', auth='none', cors='*', csrf=False)
|
|
|
|
|
def apple_yuthon_att_today(self, **kw):
|
|
|
|
|
"""
|
|
|
|
@@ -55,13 +66,15 @@ class AppletAttendance(Controller):
|
|
|
|
|
return json.dumps(return_data)
|
|
|
|
|
att_longitude = kw['att_longitude'] # 打卡经度
|
|
|
|
|
att_latitude = kw['att_latitude'] # 打卡纬度
|
|
|
|
|
longitude = address_id.longitude # 要求经度
|
|
|
|
|
latitude = address_id.latitude # 要求纬度]
|
|
|
|
|
longitude = kw['att_longitude'] # 要求经度
|
|
|
|
|
# longitude = address_id.longitude # 要求经度
|
|
|
|
|
latitude = kw['att_latitude'] # 要求纬度
|
|
|
|
|
# latitude = address_id.latitude # 要求纬度
|
|
|
|
|
if not att_longitude or not att_latitude:
|
|
|
|
|
return_data = {
|
|
|
|
|
'data': {"message": "经纬度必填", 'state': 'no', 'state_result': '超出范围'},
|
|
|
|
|
'check_in': '未签到',
|
|
|
|
|
'check_out':'未签到',
|
|
|
|
|
'check_out': '未签到',
|
|
|
|
|
'group_id': group_id,
|
|
|
|
|
'code': '200',
|
|
|
|
|
'message': 'OK',
|
|
|
|
@@ -119,8 +132,8 @@ class AppletAttendance(Controller):
|
|
|
|
|
check_in_str = check_in.strftime('%H:%M:%S') if check_in else ' '
|
|
|
|
|
check_out_str = check_out.strftime('%H:%M:%S') if check_out else ' '
|
|
|
|
|
# 构建带样式的富文本
|
|
|
|
|
check_in_html = f'<p style="color:{get_status_color(check_in_status)}">{check_in_str} {check_in_status}</p>'
|
|
|
|
|
check_out_html = f'<p style="color:{get_status_color(check_out_status)}">{check_out_str} {check_out_status}</p>'
|
|
|
|
|
check_in_html = f'<p style="color:{get_status_color(check_in_status)}">{check_in_str}</p>'
|
|
|
|
|
check_out_html = f'<p style="color:{get_status_color(check_out_status)}">{check_out_str}</p>'
|
|
|
|
|
return_data = {
|
|
|
|
|
'data': {
|
|
|
|
|
'location': '%s' % address_id.address_name,
|
|
|
|
@@ -129,7 +142,9 @@ class AppletAttendance(Controller):
|
|
|
|
|
'class': f'{attendance_class}{start_datetime}/{end_datetime}',
|
|
|
|
|
'state_result': state_result,
|
|
|
|
|
'check_in': check_in_html,
|
|
|
|
|
'check_in_status': check_in_status,
|
|
|
|
|
'check_out': check_out_html,
|
|
|
|
|
'check_out_status': check_out_status,
|
|
|
|
|
},
|
|
|
|
|
'code': '200',
|
|
|
|
|
'message': 'OK',
|
|
|
|
@@ -151,22 +166,17 @@ class AppletAttendance(Controller):
|
|
|
|
|
小程序创建打卡记录
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
user_id = int(kw.get('id'))
|
|
|
|
|
employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('user_id', '=', user_id.id)])
|
|
|
|
|
recog_time_str = kw.get('recog_time_str')
|
|
|
|
|
location_title = kw.get('location_title')
|
|
|
|
|
checkin_time = datetime.strptime(recog_time_str, "%Y-%m-%d %H:%M:%S")
|
|
|
|
|
user_id = kw.get('user_id')
|
|
|
|
|
employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('user_id', '=', user_id)])
|
|
|
|
|
if employee_id:
|
|
|
|
|
request.env(user=SUPERUSER_ID)["hr.attendance.detail"].create({
|
|
|
|
|
'employee_id': employee_id.id, # 员工
|
|
|
|
|
'checkin_time': checkin_time, # 打卡时间
|
|
|
|
|
'source': 'mini_programs', # 打卡来源
|
|
|
|
|
'location_title': location_title, # 打卡地点
|
|
|
|
|
'employee_id': employee_id.id,
|
|
|
|
|
'checkin_time': fields.Datetime.now(),
|
|
|
|
|
'source': 'mini_programs',
|
|
|
|
|
})
|
|
|
|
|
return_data = {
|
|
|
|
|
'code': '200',
|
|
|
|
|
'message': '推送成功',
|
|
|
|
|
}
|
|
|
|
|
return_data = {'code': '200', 'message': '推送成功'}
|
|
|
|
|
else:
|
|
|
|
|
return_data = {'code': '200', 'message': '未识别到员工'}
|
|
|
|
|
return json.dumps(return_data)
|
|
|
|
|
|
|
|
|
|
@route('/yuthon/app/att', methods=['POST'], type='http', auth='none', csrf=False)
|
|
|
|
@@ -216,15 +226,14 @@ class AppletAttendance(Controller):
|
|
|
|
|
"""
|
|
|
|
|
user_id = int(kw['user_id'])
|
|
|
|
|
month = kw['selected_month'] # 2015-01
|
|
|
|
|
year = month[0:4]
|
|
|
|
|
month = month[-2:]
|
|
|
|
|
year = int(month[0:4])
|
|
|
|
|
month = int(month[-2:])
|
|
|
|
|
# 当月日期范围
|
|
|
|
|
current_month_first = datetime(year, month, 1)
|
|
|
|
|
if month == 12:
|
|
|
|
|
current_month_last = datetime(year + 1, 1, 1) - timedelta(days=1)
|
|
|
|
|
else:
|
|
|
|
|
current_month_last = datetime(year, month + 1, 1) - timedelta(days=1)
|
|
|
|
|
|
|
|
|
|
calendar_leaves = request.env(user=SUPERUSER_ID)['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")]) # 少一个search
|
|
|
|
|
# 本月的节假日
|
|
|
|
|
holiday_data = self.get_holiday_data(current_month_first.date(), current_month_last.date())
|
|
|
|
@@ -369,6 +378,7 @@ class AppletAttendance(Controller):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 水电表接口
|
|
|
|
|
|
|
|
|
|
@route('/yuthon/meter/reading', methods=['POST'], type='http', auth='none', cors='*', csrf=False)
|
|
|
|
|
def yuthon_meter_reading(self, **kw):
|
|
|
|
|
"""
|
|
|
|
@@ -384,35 +394,36 @@ class AppletAttendance(Controller):
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
_logger.info("----------------/yuthon/meter/reading---------接口收到响应-------------------------------")
|
|
|
|
|
electric_records = request.env(user=SUPERUSER_ID)['property.electric.reading'].search([('reading_type', '=', '待抄')])
|
|
|
|
|
water_records = request.env(user=SUPERUSER_ID)['property.water.reading'].search([('reading_type', '=', '待抄')])
|
|
|
|
|
electric_records = request.env(user=SUPERUSER_ID)['property.electric.reading'].search([('reading_state', '=', 'wait')])
|
|
|
|
|
water_records = request.env(user=SUPERUSER_ID)['property.water.reading'].search([('reading_state', '=', 'wait')])
|
|
|
|
|
result_list = []
|
|
|
|
|
# 处理电表记录
|
|
|
|
|
for record in electric_records:
|
|
|
|
|
record_data = {
|
|
|
|
|
'code': record.property_id.code,
|
|
|
|
|
'code': record.code,
|
|
|
|
|
'last_dosage': record.last_dosage,
|
|
|
|
|
'current_meter': record.current_meter,
|
|
|
|
|
'dosage': record.dosage,
|
|
|
|
|
'employee_name': record.employee_id.name,
|
|
|
|
|
'employee_name': record.employee_ids[0].name,
|
|
|
|
|
'meter_type': 'electric', # 添加仪表类型
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
result_list.append(record_data)
|
|
|
|
|
# 处理水表记录
|
|
|
|
|
for record in water_records:
|
|
|
|
|
record_data = {
|
|
|
|
|
'code': record.property_id.code,
|
|
|
|
|
'code': record.code,
|
|
|
|
|
'last_dosage': record.last_dosage,
|
|
|
|
|
'current_meter': record.current_meter,
|
|
|
|
|
'dosage': record.dosage,
|
|
|
|
|
'employee_list': record.employee_id.name,
|
|
|
|
|
'employee_list': record.employee_ids[0].name,
|
|
|
|
|
'meter_type': 'water',
|
|
|
|
|
}
|
|
|
|
|
result_list.append(record_data)
|
|
|
|
|
return_data = {
|
|
|
|
|
'data': result_list,
|
|
|
|
|
'code': '200',
|
|
|
|
|
'message': 'OK',
|
|
|
|
|
'data': result_list,
|
|
|
|
|
}
|
|
|
|
|
return json.dumps(return_data)
|
|
|
|
|
|
|
|
|
|