160 lines
7.2 KiB
Python
160 lines
7.2 KiB
Python
import datetime
|
|
|
|
from .report_utils import _id_list
|
|
from odoo import fields, models, api
|
|
|
|
|
|
class AttendanceReport(models.Model):
|
|
_inherit = 'hr.attendance'
|
|
|
|
def _get_common_domain_and_employees(self, params):
|
|
vacation_domain = []
|
|
if params.get("date_start"):
|
|
date_start = datetime.datetime.fromisoformat(params.get("date_start")).date()
|
|
vacation_domain.append(("vacation_date", ">=", date_start))
|
|
if params.get("date_end"):
|
|
date_end = datetime.datetime.fromisoformat(params.get("date_end")).date()
|
|
vacation_domain.append(("vacation_date", "<=", date_end))
|
|
salary_group_id = params.get('structure_id', False)
|
|
department_id = params.get('department_id', False)
|
|
company_id = _id_list(params.get('company_id', False))
|
|
|
|
employee_domain = []
|
|
if salary_group_id:
|
|
employee_domain.append(('contract_id.salary_group_id', '=', salary_group_id))
|
|
if department_id:
|
|
employee_domain.append(('department_id', '=', department_id))
|
|
if company_id:
|
|
employee_domain.append(('company_id', 'in', company_id))
|
|
|
|
employee_ids = []
|
|
if employee_domain:
|
|
employee_ids = self.env['hr.employee'].search(employee_domain).ids
|
|
if employee_ids:
|
|
vacation_domain.append(("employee_id", "in", employee_ids))
|
|
|
|
return vacation_domain, employee_ids
|
|
|
|
# ---------------------- 年假/其他假期报表 ----------------------
|
|
@api.model
|
|
def get_attendance_report(self, params):
|
|
vacation_domain, employee_ids = self._get_common_domain_and_employees(params)
|
|
if employee_ids and not employee_ids:
|
|
return []
|
|
vacation_reports = self.env['yuthon.vacation.reports'].search(vacation_domain, limit=1000)
|
|
result_list = []
|
|
for report in vacation_reports:
|
|
employee_name = report.employee_id.name or ""
|
|
company_name = report.company_id.name or ""
|
|
for leave_line in report.leave_ids.filtered(lambda l: l.workflow_record_id):
|
|
result_list.append({
|
|
"员工": employee_name,
|
|
"公司": company_name,
|
|
"天数": leave_line.update_lines or 0.0,
|
|
"类型": "年假",
|
|
"流程": leave_line.workflow_record_id.name or ""
|
|
})
|
|
for fee_line in report.other_fee_ids.filtered(lambda l: l.workflow_record_id):
|
|
result_list.append({
|
|
"员工": employee_name,
|
|
"公司": company_name,
|
|
"天数": fee_line.lines or 0.0,
|
|
"类型": fee_line.holiday_type.name or "其他假期",
|
|
"流程": fee_line.workflow_record_id.name or ""
|
|
})
|
|
return result_list
|
|
|
|
# ---------------------- 误餐费报表(外出) ----------------------
|
|
@api.model
|
|
def get_meal_fee_report(self, params):
|
|
vacation_domain, employee_ids = self._get_common_domain_and_employees(params)
|
|
if employee_ids and not employee_ids:
|
|
return []
|
|
vacation_reports = self.env['yuthon.vacation.reports'].search(vacation_domain, limit=1000)
|
|
result_list = []
|
|
for report in vacation_reports:
|
|
employee_name = report.employee_id.name or ""
|
|
company_name = report.company_id.name or ""
|
|
for meal_line in report.meal_fee_ids.filtered(lambda l: l.workflow_record_id):
|
|
result_list.append({
|
|
"员工": employee_name,
|
|
"公司": company_name,
|
|
"次数": meal_line.update_lines or 0,
|
|
"类型": "外出",
|
|
"流程": meal_line.workflow_record_id.name or ""
|
|
})
|
|
return result_list
|
|
|
|
# ---------------------- 加班费报表 ----------------------
|
|
@api.model
|
|
def get_overtime_report(self, params):
|
|
vacation_domain, employee_ids = self._get_common_domain_and_employees(params)
|
|
if employee_ids and not employee_ids:
|
|
return []
|
|
vacation_reports = self.env['yuthon.vacation.reports'].search(vacation_domain, limit=1000)
|
|
result_list = []
|
|
for report in vacation_reports:
|
|
employee_name = report.employee_id.name or ""
|
|
company_name = report.company_id.name or ""
|
|
for overtime_line in report.overtime_ids.filtered(lambda l: l.workflow_record_id):
|
|
overtime_detail = {}
|
|
if overtime_line.workday > 0:
|
|
overtime_detail["加班类型"] = "工作日"
|
|
overtime_detail["时长(小时)"] = overtime_line.workday
|
|
elif overtime_line.legal_day > 0:
|
|
overtime_detail["加班类型"] = "法定节假日"
|
|
overtime_detail["时长(小时)"] = overtime_line.legal_day
|
|
elif overtime_line.public_holidays > 0:
|
|
overtime_detail["加班类型"] = "公休日"
|
|
overtime_detail["时长(小时)"] = overtime_line.public_holidays
|
|
else:
|
|
overtime_detail["加班类型"] = "无"
|
|
overtime_detail["时长(小时)"] = 0.0
|
|
|
|
overtime_method_map = {
|
|
'leave': '补休',
|
|
'fee': '加班费结算'
|
|
}
|
|
compensation_method = overtime_method_map.get(overtime_line.overtime_methods, '补休')
|
|
result_list.append({
|
|
"员工": employee_name,
|
|
"公司": company_name,
|
|
"类型": "加班",
|
|
"补偿方式": compensation_method,
|
|
"加班类型": overtime_detail["加班类型"],
|
|
"时长(小时)": overtime_detail["时长(小时)"],
|
|
"流程": overtime_line.workflow_record_id.name or ""
|
|
})
|
|
return result_list
|
|
|
|
@api.model
|
|
def get_att_report(self, params):
|
|
vacation_domain, employee_ids = self._get_common_domain_and_employees(params)
|
|
if employee_ids and not employee_ids:
|
|
return []
|
|
vacation_reports = self.env['yuthon.vacation.reports'].search(vacation_domain, limit=1000)
|
|
result_list = []
|
|
for report in vacation_reports:
|
|
result_list.append({
|
|
"姓名": report.employee_id.name,
|
|
"参加工作时间": report.employee_id.open_start_time,
|
|
"工作年限": report.employee_id.job_id.years_of_service,
|
|
"本年剩余": report.leave,
|
|
"本年工作日": report.working_overtime,
|
|
})
|
|
return result_list
|
|
|
|
|
|
@api.model
|
|
def get_domain(self, company_id=False):
|
|
# 多选:company_id 标准化为列表
|
|
cid_list = _id_list(company_id)
|
|
if not cid_list:
|
|
return [], []
|
|
|
|
department_records = self.env['hr.department'].search([('company_id', 'in', cid_list)])
|
|
department_ids = [dept.id for dept in department_records]
|
|
salary_group_records = self.env['yuthon.salary.group'].search([('company_id', 'in', cid_list)])
|
|
salary_group_ids = [struct.id for struct in salary_group_records]
|
|
return department_ids, salary_group_ids
|