121 lines
5.8 KiB
Python
121 lines
5.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
import binascii, json
|
|
from odoo import fields, http, SUPERUSER_ID, _
|
|
from odoo.exceptions import AccessError, MissingError, ValidationError
|
|
from odoo.http import request
|
|
from ....addons.portal.controllers import portal
|
|
from datetime import datetime, date, time, timedelta
|
|
|
|
|
|
class CustomerPortal(portal.CustomerPortal):
|
|
|
|
@http.route(['/my/attendance/month/detail/<int:attendance_id>'], type='http', auth="public", website=True)
|
|
def portal_attendance_month_detail_page(self, attendance_id, report_type=None, access_token=None, message=False, download=False, **kw):
|
|
# 后期有需求的话可以进行加密处理数据,包括请求地址进行加密处理数据
|
|
try:
|
|
attendance_sudo = self._document_check_access('hr.attendance.month.detail', attendance_id, access_token=access_token)
|
|
except (AccessError, MissingError):
|
|
return request.redirect('/my')
|
|
|
|
values = {
|
|
'attendance_month': attendance_sudo,
|
|
'message': message,
|
|
'report_type': 'html',
|
|
'res_company': attendance_sudo.employee_id.user_id.company_id,
|
|
}
|
|
return request.render('yuthon_hr_attendance.attendance_month_portal_template', values)
|
|
|
|
@http.route(['/my/attendance/month/detail/<int:attendance_id>/accept'], type='json', auth="public", website=True)
|
|
def portal_attendance_month_detail_quote_accept(self, attendance_id, access_token=None, name=None, signature=None):
|
|
# 后期有需求的话可以进行加密处理数据,包括请求地址进行加密处理数据
|
|
access_token = access_token or request.httprequest.args.get('access_token')
|
|
try:
|
|
attendance_sudo = self._document_check_access('hr.attendance.month.detail', attendance_id, access_token=access_token)
|
|
except (AccessError, MissingError):
|
|
return {'error': _('无效的信息')}
|
|
|
|
try:
|
|
attendance_sudo.write({
|
|
'signed_by': name,
|
|
'signed_on': fields.Datetime.now(),
|
|
'signature': signature,
|
|
'state': "confirmed"
|
|
})
|
|
request.env.cr.commit()
|
|
except (TypeError, binascii.Error) as e:
|
|
return {'error': _('无效的签名.')}
|
|
|
|
query_string = '&message=sign_ok'
|
|
return {
|
|
'force_refresh': True,
|
|
'redirect_url': attendance_sudo.get_portal_url(query_string=query_string),
|
|
}
|
|
|
|
@http.route('/phone/vacation/self', type='http', auth="none", csrf=False, cors='*')
|
|
def phone_vacation_self(self, **kw):
|
|
records = request.env['yuthon.vacation.reports'].sudo().search([('employee_id.id', '=', kw.get('employee_id'))])
|
|
data = {}
|
|
for record in records:
|
|
year = record.vacation_date.year
|
|
key = f'{year}年'
|
|
if key not in data:
|
|
data[key] = []
|
|
vacation_state = '已确认' if record.vacation_state == 'confirmed' else '待确认'
|
|
data[key].append({
|
|
'id': record.id,
|
|
'state': vacation_state,
|
|
'month': record.vacation_date.month,
|
|
})
|
|
return json.dumps({'data': data, 'code': 200, 'message': ''})
|
|
|
|
@http.route('/phone/vacation/self/detail', type='http', auth="none", csrf=False, cors='*')
|
|
def phone_vacation_self_detail(self, **kw):
|
|
record = request.env['yuthon.vacation.reports'].sudo().search([('id', '=', kw.get('id'))])
|
|
current_date = record.vacation_date
|
|
if current_date.month == 1:
|
|
last_month_year = current_date.year - 1
|
|
last_month = 12
|
|
else:
|
|
last_month_year = current_date.year
|
|
last_month = current_date.month - 1
|
|
records = request.env['yuthon.vacation.reports'].sudo().search([
|
|
('employee_id', '=', record.employee_id.id),
|
|
('vacation_date', '>=', f'{last_month_year}-{last_month:02d}-01'),
|
|
('vacation_date', '<', f'{last_month_year}-{last_month + 1:02d}-01' if last_month < 12 else f'{last_month_year + 1}-01-01')
|
|
], limit=1)
|
|
data = {
|
|
'日期': record.display_date,
|
|
'应到': records.should_attendance,
|
|
'实到': records.actual_attendance,
|
|
'迟到': records.is_late_card,
|
|
'早退': records.is_early_card,
|
|
'缺卡': records.is_no_card,
|
|
'旷工': records.is_work,
|
|
'异常': records.is_abnormal,
|
|
'年假': records.done_leave,
|
|
'加班时': records.done_working_overtime,
|
|
'调休': records.compensatory_leave,
|
|
'事假': records.leave_of_absence,
|
|
'加班时(法定假)': records.statutory_leave,
|
|
'育儿假': records.parental_leave,
|
|
'值班调休': records.duty_off_leave,
|
|
'婚假': records.marriage_leave,
|
|
'产假': records.maternity_leave,
|
|
'陪产假': records.paternity_leave,
|
|
'计生假': records.family_planning_leave,
|
|
'丧假': records.bereavement_leave,
|
|
'探亲假': records.home_visit_leave,
|
|
'家长会假': records.parents_meeting_leave,
|
|
'病假(普通)': records.general_sick_leave,
|
|
'病假(住院期)': records.hospital_sick_leave,
|
|
'病假(出院恢复期)': records.recovery_sick_leave,
|
|
'考试假': records.exam_leave,
|
|
}
|
|
return json.dumps({'data': data, 'code': 200, 'message': ''})
|
|
|
|
@http.route('/phone/vacation/self/status', type='http', auth="none", csrf=False, cors='*')
|
|
def phone_vacation_self_status(self, **kw):
|
|
record_id = request.env['yuthon.vacation.reports'].sudo().search([('id', '=', kw.get('id'))])
|
|
record_id.write({'vacation_state': 'confirmed'})
|
|
return json.dumps({'code': 200, 'message': 'OK'})
|