XH_Digital_Management/application/hrm_mgnt/views.py

1044 lines
39 KiB
Python
Raw Normal View History

import json
from datetime import datetime, date
from django.core.paginator import Paginator
2024-06-18 20:59:35 +08:00
from django.http import Http404
2024-06-14 16:47:43 +08:00
from django.shortcuts import render
2024-06-06 18:02:55 +08:00
from django.template.loader import render_to_string
2024-06-04 16:50:30 +08:00
from django.urls import reverse
2024-06-18 21:59:27 +08:00
from django.views.decorators.http import require_http_methods
2024-05-15 09:23:16 +08:00
2024-06-07 03:47:15 +08:00
from application.hrm_mgnt.forms import *
2024-05-31 20:17:40 +08:00
from application.hrm_mgnt.models import *
from application.org_mgnt.models import SecondaryDepartment
2024-06-14 16:47:43 +08:00
from common.auth import custom_permission_required
2024-05-31 20:17:40 +08:00
from common.utils.page_helper import paginate_query_and_assign_numbers
2024-06-14 16:47:56 +08:00
from django.http import JsonResponse
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_employeeinformation')
2024-06-04 16:50:30 +08:00
def emp_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-人员基本信息表-列表视图
"""
2024-06-04 16:50:30 +08:00
# 声明查询集
query_set = EmployeeInformation.objects.filter().order_by('-employee_id')
# 获取查询参数
name = request.GET.get('name', '')
department = request.GET.get('department', '')
sort_field = request.GET.get('sort', '')
sort_order = request.GET.get('order', 'asc')
2024-06-04 16:50:30 +08:00
# 根据提供的参数进行筛选
2024-06-06 14:18:42 +08:00
if name:
query_set = query_set.filter(name__icontains=name)
if department:
2024-06-06 21:27:24 +08:00
query_set = query_set.filter(primary_department=department)
2024-06-04 16:50:30 +08:00
# 根据排序参数对查询集进行排序
if sort_field:
if sort_order == 'desc':
query_set = query_set.order_by(f'-{sort_field}')
else:
query_set = query_set.order_by(sort_field)
2024-06-04 16:50:30 +08:00
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&name={}'.format(name) + '&department={}'.format(department) + '&sort={}'.format(
sort_field) + '&order={}'.format(sort_order)
2024-06-04 16:50:30 +08:00
2024-06-06 14:18:42 +08:00
# Excel上传模板
template_name = "人力资源管理-人员基本信息-Excel上传模板.xlsx"
2024-06-04 16:50:30 +08:00
# 构建上下文
context = {
2024-06-06 14:18:42 +08:00
"model_config": "hrm_mgnt.EmployeeInformation",
2024-06-04 16:50:30 +08:00
"items": items,
2024-06-06 14:18:42 +08:00
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "人员基本信息表", "name": "emt_list"}
],
"filters": [
{
"type": "text",
"id": "name",
"name": "name",
"label": "姓名",
"placeholder": "请输入姓名"
},
{
"type": "text",
"id": "rank",
"name": "rank",
"label": "职级",
"placeholder": "请输入职级"
},
2024-06-06 14:18:42 +08:00
{
"type": "select",
"id": "department",
"name": "department",
"label": "一级部门",
"options": [
{"value": "天信", "display": "天信"},
{"value": "混改", "display": "混改"},
{"value": "艾力芬特", "display": "艾力芬特"},
{"value": "星河", "display": "星河"},
{"value": "星海", "display": "星海"}
]
},
{
"type": "select",
"id": "education",
"name": "education",
"label": "学历",
"options": [
{"value": "高中", "display": "高中"},
{"value": "大专", "display": "大专"},
{"value": "本科", "display": "本科"},
{"value": "硕士研究生", "display": "硕士研究生"},
{"value": "博士研究生", "display": "博士研究生"},
{"value": "其他", "display": "其他"}
]
2024-06-06 14:18:42 +08:00
}
],
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-06 14:18:42 +08:00
},
2024-06-04 16:50:30 +08:00
"query_params": query_params,
2024-06-06 18:02:55 +08:00
"table_exclude_field_name": ['employee_id'],
"form_action_url": reverse("emp_list"),
2024-06-04 16:50:30 +08:00
"modify_url": reverse("emp_list_modify"),
"add_url": reverse("emp_list_add"),
"delete_url": reverse("emp_list_delete"),
2024-06-18 05:01:50 +08:00
"add_button": True,
"import_excel_button": True,
"report_excel_button": True,
2024-06-04 16:50:30 +08:00
}
return render(request, 'emp_list_inherit.html', context)
2024-06-04 16:50:30 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.add_employeeinformation')
2024-06-04 16:50:30 +08:00
def emp_list_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-人员基本信息表-新增视图
"""
2024-06-04 16:50:30 +08:00
if request.method == 'POST':
form = EmployeeInformationForm(request.POST, is_edit=False)
2024-06-06 18:02:55 +08:00
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
form = EmployeeInformationForm(is_edit=False)
2024-06-06 18:02:55 +08:00
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-04 16:50:30 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.change_employeeinformation')
2024-06-04 16:50:30 +08:00
def emp_list_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-人员基本信息表-修改视图
"""
2024-06-04 16:50:30 +08:00
if request.method == 'POST':
current_base_salary = None
2024-06-06 18:02:55 +08:00
if 'id' in request.POST:
2024-06-06 21:27:24 +08:00
instance = EmployeeInformation.objects.get(employee_id=request.POST['id'])
current_base_salary = instance.base_salary # 获取当前基本工资
form = EmployeeInformationForm(request.POST, instance=instance, is_edit=True)
2024-06-06 18:02:55 +08:00
else:
form = EmployeeInformationForm(request.POST, is_edit=True)
2024-06-06 18:02:55 +08:00
if form.is_valid():
employee = form.save()
new_base_salary = form.cleaned_data.get('base_salary')
# 判断基本工资是否有变化
if 'id' in request.POST and current_base_salary != new_base_salary:
SalaryChangeRecord.objects.create(
employee=employee,
2024-06-13 13:43:51 +08:00
change_date=datetime.datetime.now(),
previous_value=current_base_salary if current_base_salary else 0,
new_value=new_base_salary,
approved_by=request.user.username
)
employee.resignation_type = form.cleaned_data.get('resignation_type')
employee.resignation_date = form.cleaned_data.get('resignation_date')
employee.resignation_reason = form.cleaned_data.get('resignation_reason')
employee.save()
2024-06-06 18:02:55 +08:00
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = EmployeeInformation.objects.get(employee_id=request.GET['id'])
form = EmployeeInformationForm(instance=instance, is_edit=True)
form.fields['secondary_department'].choices = [
(dept.secondary_department_name, dept.secondary_department_name) for dept in
SecondaryDepartment.objects.filter(primary_department__department_name=instance.primary_department)]
2024-06-06 18:02:55 +08:00
except EmployeeInformation.DoesNotExist:
raise Http404("对象不存在")
else:
form = EmployeeInformationForm(is_edit=True)
2024-06-06 18:02:55 +08:00
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-04 16:50:30 +08:00
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.delete_employeeinformation')
2024-06-04 16:50:30 +08:00
def emp_list_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-人员基本信息表-删除视图
"""
2024-06-18 21:59:27 +08:00
employee_id = request.POST.get('id')
if employee_id:
2024-06-04 16:50:30 +08:00
EmployeeInformation.objects.filter(employee_id=employee_id).delete()
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)
2024-06-06 14:18:42 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_salarychangerecord')
def get_salary_change_records(request, employee_id):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-人员基本信息表-获取薪资变动记录
"""
records = SalaryChangeRecord.objects.filter(employee_id=employee_id).values(
'change_date', 'previous_value', 'new_value', 'approved_by')
return JsonResponse(list(records), safe=False)
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_employeeattendancerecord')
2024-06-06 15:33:22 +08:00
def attd_rec_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工考勤记录表-列表视图
"""
2024-06-06 15:33:22 +08:00
# 声明查询集
query_set = EmployeeAttendanceRecord.objects.filter().order_by('-record_id')
# 获取查询参数
employee = request.GET.get('employee', '')
year_month = request.GET.get('year_month', '')
primary_department = request.GET.get('primary_department', '')
# 根据提供的参数进行筛选
if employee:
query_set = query_set.filter(employee__name__icontains=employee)
if year_month:
query_set = query_set.filter(year_month__icontains=year_month)
if primary_department:
query_set = query_set.filter(employee__primary_department__icontains=primary_department)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&employee={}'.format(employee) + '&year_month={}'.format(
year_month) + '&primary_department={}'.format(primary_department)
2024-06-06 20:56:06 +08:00
# Excel上传模板
2024-06-14 16:47:56 +08:00
template_name = "人力资源管理-员工考勤记录-Excel上传模板.xlsx"
2024-06-06 15:33:22 +08:00
# 构建上下文
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'hrm_mgnt.EmployeeAttendanceRecord',
2024-06-06 15:33:22 +08:00
"items": items,
2024-06-06 20:56:06 +08:00
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "员工考勤记录表", "name": "attd_rec_list"}
],
2024-06-06 15:33:22 +08:00
"filters": [
{"type": "text", "id": "employee", "name": "employee", "label": "员工", "placeholder": "请输入员工姓名"},
{"type": "month", "id": "year_month", "name": "year_month", "label": "年月"},
{"type": "select", "id": "primary_department", "name": "primary_department", "label": "一级部门",
"options": [{"value": "天信", "display": "天信"}, {"value": "混改", "display": "混改"},
{"value": "艾力芬特", "display": "艾力芬特"}, {"value": "星河", "display": "星河"},
{"value": "星海", "display": "星海"}]}
],
2024-06-06 20:56:06 +08:00
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-06 20:56:06 +08:00
},
"query_params": query_params,
"form_action_url": reverse('attd_rec_list'),
2024-06-06 20:56:06 +08:00
"modify_url": reverse("attd_rec_list_modify"),
"add_url": reverse("attd_rec_list_add"),
"delete_url": reverse("attd_rec_list_delete"),
2024-06-14 16:47:56 +08:00
"table_exclude_field_name": ['record_id'],
"add_button": True,
"import_excel_button": True
2024-06-06 15:33:22 +08:00
}
return render(request, 'attd_list_inherit.html', context)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.add_employeeattendancerecord')
2024-06-06 15:33:22 +08:00
def attd_rec_list_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工考勤记录表-添加视图
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
data = request.POST.copy()
if 'year_month' in data:
year_month_str = data['year_month']
try:
year_month_date = datetime.datetime.strptime(year_month_str, "%Y-%m").date()
data['year_month'] = year_month_date
except ValueError:
return JsonResponse({"message": "无效的日期格式"}, status=400)
form = EmployeeAttendanceRecordForm(data)
2024-06-07 03:47:15 +08:00
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
form = EmployeeAttendanceRecordForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.change_employeeattendancerecord')
2024-06-06 15:33:22 +08:00
def attd_rec_list_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工考勤记录表-修改视图
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
data = request.POST.copy()
# 处理 year_month 字段,将 'YYYY-MM' 转换为 DateField 期望的格式
if 'year_month' in data:
year_month_str = data['year_month']
try:
year_month_date = datetime.datetime.strptime(year_month_str, "%Y-%m").date()
data['year_month'] = year_month_date
except ValueError:
return JsonResponse({"message": "无效的日期格式"}, status=400)
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = EmployeeAttendanceRecord.objects.get(record_id=request.POST['id'])
form = EmployeeAttendanceRecordForm(data, instance=instance)
2024-06-07 03:47:15 +08:00
else:
form = EmployeeAttendanceRecordForm(data)
2024-06-07 03:47:15 +08:00
if form.is_valid():
form.save()
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = EmployeeAttendanceRecord.objects.get(record_id=request.GET['id'])
form = EmployeeAttendanceRecordForm(instance=instance)
form.fields['year_month'].initial = instance.year_month.strftime('%Y-%m')
2024-06-07 03:47:15 +08:00
except EmployeeAttendanceRecord.DoesNotExist:
raise Http404("对象不存在")
else:
form = EmployeeAttendanceRecordForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.delete_employeeattendancerecord')
2024-06-06 15:33:22 +08:00
def attd_rec_list_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工考勤记录表-删除视图
"""
2024-06-18 21:59:27 +08:00
record_id = request.POST.get('id')
if record_id:
2024-06-07 03:47:15 +08:00
EmployeeAttendanceRecord.objects.filter(record_id=record_id).delete()
2024-06-06 15:33:22 +08:00
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_otherleavedetails')
def get_other_leave_details(request, attendance_record_id):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工考勤记录表-获取其他请假明细
"""
records = OtherLeaveDetails.objects.filter(attendance_record_id=attendance_record_id).values(
'leave_type', 'days', 'description')
return JsonResponse(list(records), safe=False)
@custom_permission_required('hrm_mgnt.add_otherleavedetails')
def add_other_leave_detail(request):
"""
基础数据-人力资源管理-其他请假详细记录-新增接口
"""
try:
data = json.loads(request.body) # 解析JSON格式的请求体
form = OtherLeaveDetailsForm(data) # 使用解析后的数据创建表单
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"}, status=201)
else:
return JsonResponse({"errors": form.errors}, status=400)
except json.JSONDecodeError:
return JsonResponse({"message": "请求体不是有效的JSON格式"}, status=400)
@custom_permission_required('hrm_mgnt.change_otherleavedetails')
def edit_other_leave_detail(request, record_id):
"""
基础数据-人力资源管理-其他请假详细记录-编辑接口
"""
try:
instance = OtherLeaveDetails.objects.get(record_id=record_id)
except OtherLeaveDetails.DoesNotExist:
return JsonResponse({"message": "记录不存在"}, status=404)
if request.method == 'POST':
form = OtherLeaveDetailsForm(request.POST, instance=instance)
if form.is_valid():
form.save()
return JsonResponse({"message": "编辑成功"}, status=200)
else:
return JsonResponse({"errors": form.errors}, status=400)
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
@custom_permission_required('hrm_mgnt.delete_otherleavedetails')
def delete_other_leave_detail(request, record_id):
"""
基础数据-人力资源管理-其他请假详细记录-删除接口
"""
try:
instance = OtherLeaveDetails.objects.get(record_id=record_id)
except OtherLeaveDetails.DoesNotExist:
return JsonResponse({"message": "记录不存在"}, status=404)
if request.method == 'POST':
instance.delete()
return JsonResponse({"message": "删除成功"}, status=200)
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_annualleaverecord')
2024-06-06 15:33:22 +08:00
def alv_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-年假使用记录表-列表视图
"""
2024-06-06 15:33:22 +08:00
# 声明查询集
query_set = AnnualLeaveRecord.objects.filter().order_by('-record_id')
# 获取查询参数
employee_name = request.GET.get('employee_name', '')
year = request.GET.get('year', '')
# 根据提供的参数进行筛选
if employee_name:
query_set = query_set.filter(employee_name__icontains=employee_name)
if year:
query_set = query_set.filter(year__icontains=year)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&employee_name={}'.format(employee_name) + '&year={}'.format(year)
2024-06-06 20:56:06 +08:00
# Excel上传模板
template_name = "人力资源管理-年假使用记录-Excel上传模板.xlsx"
2024-06-06 15:33:22 +08:00
# 构建上下文
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'hrm_mgnt.AnnualLeaveRecord',
2024-06-06 15:33:22 +08:00
"items": items,
2024-06-06 20:56:06 +08:00
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "年假使用记录", "name": "alv_list"}
],
2024-06-06 15:33:22 +08:00
"filters": [
{"type": "text", "id": "employee_name", "name": "employee_name", "label": "姓名",
"placeholder": "请输入姓名"},
{"type": "select", "id": "year", "name": "year", "label": "年度",
"options": [{"value": "2024", "display": "2024"}, {"value": "2023", "display": "2023"},
{"value": "2022", "display": "2022"}, {"value": "2021", "display": "2021"},
{"value": "2020", "display": "2020"}]}
],
2024-06-06 20:56:06 +08:00
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-06 20:56:06 +08:00
},
"query_params": query_params,
"form_action_url": reverse('alv_list'),
2024-06-06 20:56:06 +08:00
"modify_url": reverse("alv_list_modify"),
"add_url": reverse("alv_list_add"),
"delete_url": reverse("alv_list_delete"),
2024-06-14 16:47:56 +08:00
"table_exclude_field_name": ['record_id'],
"add_button": True,
"import_excel_button": True
2024-06-06 15:33:22 +08:00
}
2024-06-07 03:47:15 +08:00
return render(request, 'items_list.html', context)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.add_annualleaverecord')
2024-06-06 15:33:22 +08:00
def alv_list_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-年假使用记录表-添加
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = AnnualLeaveRecordForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
form = AnnualLeaveRecordForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.change_annualleaverecord')
2024-06-06 15:33:22 +08:00
def alv_list_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-年假使用记录表-修改
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = AnnualLeaveRecord.objects.get(record_id=request.POST['id'])
form = AnnualLeaveRecordForm(request.POST, instance=instance)
else:
form = AnnualLeaveRecordForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = AnnualLeaveRecord.objects.get(record_id=request.GET['id'])
form = AnnualLeaveRecordForm(instance=instance)
except AnnualLeaveRecord.DoesNotExist:
raise Http404("对象不存在")
else:
form = AnnualLeaveRecordForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.delete_annualleaverecord')
2024-06-06 15:33:22 +08:00
def alv_list_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-年假使用记录表-删除
"""
2024-06-18 21:59:27 +08:00
record_id = request.post.get('id')
if record_id:
2024-06-07 03:47:15 +08:00
AnnualLeaveRecord.objects.filter(record_id=record_id).delete()
2024-06-06 15:33:22 +08:00
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_rank')
2024-06-06 15:33:22 +08:00
def rk_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-职级表-查看
"""
2024-06-06 15:33:22 +08:00
# 声明查询集
query_set = Rank.objects.filter().order_by('-rank_id')
# 获取查询参数
rank_name = request.GET.get('rank_name', '')
# 根据提供的参数进行筛选
if rank_name:
query_set = query_set.filter(rank_name__icontains=rank_name)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&rank_name={}'.format(rank_name)
2024-06-06 20:56:06 +08:00
# Excel上传模板
template_name = "人力资源管理-职级表-Excel上传模板.xlsx"
2024-06-06 15:33:22 +08:00
2024-06-06 20:56:06 +08:00
# 构建上下文
2024-06-06 15:33:22 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'hrm_mgnt.Rank',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "职级表", "name": "rk_list"}
],
"filters": [{"type": "text", "id": "rank_name", "name": "rank_name", "label": "职级名称",
2024-06-06 15:33:22 +08:00
"placeholder": "请输入职级名称"}],
2024-06-06 20:56:06 +08:00
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-06 20:56:06 +08:00
},
"query_params": query_params,
"form_action_url": reverse('rk_list'),
2024-06-06 20:56:06 +08:00
"modify_url": reverse("rk_list_modify"),
"add_url": reverse("rk_list_add"),
"delete_url": reverse("rk_list_delete"),
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['rank_id'],
"add_button": True,
# "import_excel_button": True
2024-06-06 15:33:22 +08:00
}
2024-06-07 03:47:15 +08:00
return render(request, 'items_list.html', context)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.add_rank')
2024-06-06 15:33:22 +08:00
def rk_list_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-职级表-添加
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = RankForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
form = RankForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.change_rank')
2024-06-06 15:33:22 +08:00
def rk_list_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-职级表-修改
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = Rank.objects.get(rank_id=request.POST['id'])
form = RankForm(request.POST, instance=instance)
else:
form = RankForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = Rank.objects.get(rank_id=request.GET['id'])
form = RankForm(instance=instance)
except Rank.DoesNotExist:
raise Http404("对象不存在")
else:
form = RankForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.delete_rank')
2024-06-06 15:33:22 +08:00
def rk_list_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-职级表-删除
"""
2024-06-18 21:59:27 +08:00
rank_id = request.post.get('id')
if rank_id:
2024-06-07 03:47:15 +08:00
Rank.objects.filter(rank_id=rank_id).delete()
2024-06-06 15:33:22 +08:00
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.view_position')
2024-06-06 15:33:22 +08:00
def pst_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-岗位表-查看
"""
2024-06-06 15:33:22 +08:00
# 声明查询集
query_set = Position.objects.filter().order_by('-position_id')
# 获取查询参数
position_name = request.GET.get('position_name', '')
# 根据提供的参数进行筛选
if position_name:
query_set = query_set.filter(position_name__icontains=position_name)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&position_name={}'.format(position_name)
2024-06-06 20:56:06 +08:00
# Excel上传模板
template_name = "人力资源管理-岗位表-Excel上传模板.xlsx"
2024-06-06 15:33:22 +08:00
2024-06-06 20:56:06 +08:00
# 构建上下文
2024-06-06 15:33:22 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'hrm_mgnt.Position',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "岗位表", "name": "pst_list"}
],
"filters": [
{"type": "text", "id": "position_name", "name": "position_name", "label": "岗位名称",
"placeholder": "请输入岗位名称"}
],
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-06 20:56:06 +08:00
},
"query_params": query_params,
"form_action_url": reverse('pst_list'),
2024-06-06 20:56:06 +08:00
"modify_url": reverse("pst_list_modify"),
"add_url": reverse("pst_list_add"),
"delete_url": reverse("pst_list_delete"),
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['position_id'],
"add_button": True,
2024-06-06 15:33:22 +08:00
}
2024-06-07 03:47:15 +08:00
return render(request, 'items_list.html', context)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.add_position')
2024-06-06 15:33:22 +08:00
def pst_list_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-岗位表-添加
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = PositionForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
form = PositionForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.change_position')
2024-06-06 15:33:22 +08:00
def pst_list_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-岗位表-修改
"""
2024-06-06 15:33:22 +08:00
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = Position.objects.get(position_id=request.POST['id'])
form = PositionForm(request.POST, instance=instance)
else:
form = PositionForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = Position.objects.get(position_id=request.GET['id'])
form = PositionForm(instance=instance)
except Position.DoesNotExist:
raise Http404("对象不存在")
else:
form = PositionForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-06 15:33:22 +08:00
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-14 16:47:43 +08:00
@custom_permission_required('hrm_mgnt.delete_position')
2024-06-06 15:33:22 +08:00
def pst_list_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-岗位表-删除
"""
2024-06-18 21:59:27 +08:00
position_id = request.POST.get('id')
if position_id:
2024-06-07 03:47:15 +08:00
Position.objects.filter(position_id=position_id).delete()
2024-06-06 15:33:22 +08:00
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)
2024-06-09 21:23:41 +08:00
def emp_list_for_create_account_profile(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工信息表-创建账号-获取员工信息列表
"""
2024-06-09 21:23:41 +08:00
# 查询还没有创建AccountProfile的员工信息
query_set = EmployeeInformation.objects.exclude(account_profile__isnull=False).order_by('-employee_id')
# 获取查询参数
name = request.GET.get('name', '')
# 根据提供的参数进行筛选
if name:
query_set = query_set.filter(name__icontains=name)
# 对查询结果进行分页
paginator = Paginator(query_set, 10) # 每页显示10条记录
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
# 创建员工信息的列表,包含需要的字段
employees = [
{
'employee_id': emp.employee_id,
'name': emp.name,
'email': emp.email,
'mobile_number': emp.mobile_number,
'primary_department': emp.primary_department if emp.primary_department else '',
'position': emp.position if emp.position else ''
}
for emp in page_obj.object_list
]
2024-06-09 21:23:41 +08:00
# 返回JSON响应
return JsonResponse({
'success': True,
'employees': employees,
'has_previous': page_obj.has_previous(),
'has_next': page_obj.has_next(),
'num_pages': paginator.num_pages,
'current_page': page_obj.number
})
2024-06-13 00:12:17 +08:00
2024-06-18 20:59:35 +08:00
@custom_permission_required('hrm_mgnt.view_performanceevaluation')
2024-06-13 00:12:17 +08:00
def performance_list_view(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工绩效表-查看
"""
2024-06-13 00:12:17 +08:00
# 声明查询集
query_set = PerformanceEvaluation.objects.filter().order_by('-performance_id')
2024-06-13 00:12:17 +08:00
# 获取查询参数
name = request.GET.get('name', '')
department = request.GET.get('department', '')
# 根据提供的参数进行筛选
if name:
query_set = query_set.filter(employee__name__icontains=name)
if department:
query_set = query_set.filter(employee__primary_department=department)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&name={}'.format(name) + '&department={}'.format(department)
2024-06-14 16:47:56 +08:00
# Excel上传模板
template_name = "人力资源管理-员工绩效-Excel上传模板.xlsx"
2024-06-13 00:12:17 +08:00
# 构建上下文
context = {
"model_config": "hrm_mgnt.PerformanceEvaluation",
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "人力资源管理", "name": "index"},
{"title": "员工绩效表", "name": "performance_list"}
],
"filters": [
{
"type": "text",
"id": "name",
"name": "name",
"label": "姓名",
"placeholder": "请输入姓名"
},
{
"type": "select",
"id": "department",
"name": "department",
"label": "一级部门",
"options": [
{"value": "天信", "display": "天信"},
{"value": "混改", "display": "混改"},
{"value": "艾力芬特", "display": "艾力芬特"},
{"value": "星河", "display": "星河"},
{"value": "星海", "display": "星海"}
]
}
],
"table_exclude_field_name": ['performance_id'],
2024-06-14 16:47:56 +08:00
"excel_upload_config": {
2024-06-17 20:14:28 +08:00
"template_name": template_name,
2024-06-17 19:38:02 +08:00
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
2024-06-17 20:14:28 +08:00
"parse_url": reverse("ep_common_parse"),
"save_url": reverse("save_excel_table_data")
2024-06-14 16:47:56 +08:00
},
"query_params": query_params,
2024-06-13 00:12:17 +08:00
"form_action_url": "performance_list",
"modify_url": reverse("performance_modify"),
"add_url": reverse("performance_add"),
"delete_url": reverse("performance_delete"),
"add_button": True,
"import_excel_button": True,
2024-06-13 00:12:17 +08:00
}
return render(request, 'performance_list_inherit.html', context)
2024-06-13 00:12:17 +08:00
2024-06-18 20:59:35 +08:00
@custom_permission_required('hrm_mgnt.add_performanceevaluation')
2024-06-13 00:12:17 +08:00
def performance_add(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工绩效表-添加
"""
2024-06-13 00:12:17 +08:00
if request.method == 'POST':
2024-06-19 10:39:14 +08:00
form = PerformanceEvaluationForm(request.POST)
2024-06-13 00:12:17 +08:00
if form.is_valid():
form.save()
return JsonResponse({"message": "添加成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
2024-06-19 10:39:14 +08:00
form = PerformanceEvaluationForm()
2024-06-13 00:12:17 +08:00
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-18 20:59:35 +08:00
@custom_permission_required('hrm_mgnt.change_performanceevaluation')
2024-06-13 00:12:17 +08:00
def performance_modify(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工绩效表-修改
"""
2024-06-13 00:12:17 +08:00
if request.method == 'POST':
if 'id' in request.POST:
instance = PerformanceEvaluation.objects.get(performance_id=request.POST['id'])
form = PerformanceEvaluationForm(request.POST, instance=instance)
else:
form = PerformanceEvaluationForm(request.POST)
if form.is_valid():
form.save()
return JsonResponse({"message": "保存成功"})
else:
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
elif request.method == 'GET':
if 'id' in request.GET:
try:
instance = PerformanceEvaluation.objects.get(performance_id=request.GET['id'])
form = PerformanceEvaluationForm(instance=instance)
except PerformanceEvaluation.DoesNotExist:
raise Http404("对象不存在")
else:
form = PerformanceEvaluationForm()
form_html = render_to_string('form_partial.html', {'form': form}, request)
return JsonResponse({"form_html": form_html})
else:
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-06-18 21:59:27 +08:00
@require_http_methods(["POST"])
2024-06-18 20:59:35 +08:00
@custom_permission_required('hrm_mgnt.delete_performanceevaluation')
2024-06-13 00:12:17 +08:00
def performance_delete(request):
2024-06-18 20:59:35 +08:00
"""
基础数据-人力资源管理-员工绩效表-删除
"""
2024-06-18 21:59:27 +08:00
performance_id = request.POST.get('id')
if performance_id:
2024-06-13 00:12:17 +08:00
PerformanceEvaluation.objects.filter(performance_id=performance_id).delete()
return JsonResponse({"message": "删除成功"})
2024-06-18 21:59:27 +08:00
else:
return JsonResponse({"message": "请求参数错误"}, status=400)