import json
import openpyxl
from django import forms
from django.contrib import admin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.core.exceptions import ValidationError
from django.db.models import F
from django.http import JsonResponse, FileResponse
from django.utils.html import format_html
from simpleui.admin import AjaxAdmin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
import wage
from .models import *
import datetime as firstdate
from .functions import monthcalc, verifyIdName
period_list = WagePeriod.objects.values('id', 'period_name')
global options_list
options_list = []
for data in period_list:
temp = {'key': data['id'], 'label': data['period_name']}
options_list.append(temp)
def get_job_status(num):
numbers = {
1: "在职",
2: "离职",
99: "黑名单",
}
return numbers.get(num, None)
# Register your models here.
# 周期表
class WagePeriodAdmin(AjaxAdmin):
list_display = ['period_name']
search_fields = ['period_name']
# 部门表
class WageDeptmentAdmin(AjaxAdmin):
list_display = ['dept_id', 'dept_name', 'dept_short_name', 'dept_base']
search_fields = ['dept_id', 'dept_name', 'dept_base', 'dept_short_name']
list_filter = ['dept_base', 'dept_short_name']
# 岗位表
class WagePositionAdmin(AjaxAdmin):
list_display = ['posi_id', 'posi_name']
search_fields = ['posi_id', 'posi_name']
# list_filter = ['posi_id', 'posi_name']
# 员工表
class WageEmployeeAdmin(AjaxAdmin):
list_display = ['emp_id', 'emp_name', 'emp_dept', 'emp_posi', 'emp_rank', 'glgs', 'emp_entry_date', 'emp_in_date',
'emp_job_type', 'emp_job_status', 'emp_leave_date', 'emp_leave_bl_date', 'emp_job_level', 'emp_dlidl', 'emp_pay_type', 'emp_base']
search_fields = ['emp_id', 'emp_name']
list_filter = ['emp_dept__dept_short_name', 'emp_posi__posi_name', 'emp_job_type', 'emp_job_status', 'emp_rank',
'emp_dept__dept_base', 'emp_job_level', 'emp_dlidl', 'emp_pay_type']
actions = ['download']
def glgs(self, obj):
return obj.emp_dept.dept_base
glgs.short_description = '管理归属'
def get_actions(self, request):
actions = super(WageEmployeeAdmin, self).get_actions(request)
if not request.user.has_perm('wage.can_download_employee'):
del actions['download']
return actions
# 重写显示的数据内容,可根据不同登录用户,显示不同基地的人员信息。
def get_queryset(self, request):
qs = super(WageEmployeeAdmin, self).get_queryset(request)
if not request.user.is_superuser:
myUser = MyUser.objects.get(user_id=request.user.id)
deptIdList = myUser.department.all().values_list('id')
rankId = myUser.rank.all().values_list('id')
return qs.filter(emp_dept_id__in=deptIdList, emp_rank_id__in=rankId)
else:
return qs
def download(self, request, queryset):
wb = openpyxl.Workbook()
ws = wb.active
row1 = ['工号', '姓名', '部门', '岗位', '集团入职日期', '入职日期', '离职结薪日期', '离职办理日期', '在职状态', '在职类型', '合同归属', '管理归属']
ws.append(row1)
for datas in queryset:
row2 = [
str(datas.emp_id) if str(datas.emp_id) != "None" else "", # 工号
str(datas.emp_name) if str(datas.emp_name) != "None" else "", # 姓名
str(datas.emp_dept) if str(datas.emp_dept) != "None" else "", # 部门
str(datas.emp_posi) if str(datas.emp_posi) != "None" else "", # 岗位
str(datas.emp_entry_date) if str(datas.emp_entry_date) != "None" else "", # 集团入职日期
str(datas.emp_in_date) if str(datas.emp_in_date) != "None" else "", # 入职日期
str(datas.emp_leave_date) if str(datas.emp_leave_date) != "None" else "", # 离职结薪日期
str(datas.emp_leave_bl_date) if str(datas.emp_leave_bl_date) != "None" else "", # 离职办理日期
get_job_status(datas.emp_job_status), # 在职状态
str(datas.emp_job_type) if str(datas.emp_job_type) != "None" else "", # 在职类型
str(datas.emp_rank) if str(datas.emp_rank) != "None" else "", # 合同归属
str(datas.emp_dept.dept_base) if str(datas.emp_dept.dept_base) != "None" else "", # 管理归属
]
ws.append(row2)
wb.save('static/download/emp.xlsx')
# 下载
file = open('static/download/emp.xlsx', 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="emp.xlsx"'
return response
# 显示的文本,与django admin一致
download.short_description = '下载数据'
# icon,参考element-ui icon与https://fontawesome.com
# custom_button.icon = 'fas fa-audio-description'
# 指定element-ui的按钮类型,参考https://element.eleme.cn/#/zh-CN/component/button
download.type = 'success'
# 费用项目表
class WageExpenseAdmin(AjaxAdmin):
list_display = ['expense_name']
search_fields = ['expense_name']
# 费用项目引入表
class WageExpenseIntoAdmin(AjaxAdmin):
list_display = ['into_emp', 'into_emp_ids', 'dept', 'position', 'into_periods', 'into_expense', 'into_reason',
'into_calc_elem_1', 'into_calc_elem_2', 'into_calc_elem_other', 'into_money', 'into_effecte_date', 'into_expir_date']
list_display_links = ['into_emp', 'into_emp_ids', 'dept', 'position', 'into_periods', 'into_expense', 'into_reason',
'into_calc_elem_1', 'into_calc_elem_2', 'into_calc_elem_other', 'into_money', 'into_effecte_date', 'into_expir_date']
actions = ['upload_file', 'download_templates', 'download']
list_filter = ['into_emp__emp_dept__dept_short_name', 'into_emp__emp_posi', 'into_periods', 'into_expense']
raw_id_fields = ['into_emp', 'into_expense']
search_fields = ['into_emp__emp_id', 'into_emp__emp_name']
def get_queryset(self, request):
qs = super(WageExpenseIntoAdmin, self).get_queryset(request)
# 是否为管理员,否需要过滤部门基地;是返回全部数据
if not request.user.is_superuser:
myUser = MyUser.objects.get(user_id=request.user.id)
deptIdList = myUser.department.all().values_list('id')
rankId = myUser.rank.all().values_list('id')
# 是否可以查看所有信息,包含别人上传的
if request.user.myuser.is_full is False:
return qs.filter(into_emp__emp_dept_id__in=deptIdList, into_emp__emp_rank_id__in=rankId, into_creater=str(request.user))
else:
return qs.filter(into_emp__emp_dept_id__in=deptIdList, into_emp__emp_rank_id__in=rankId)
else:
return qs
def get_readonly_fields(self, request, obj=None):
if request.user.is_superuser:
return 'into_creater', 'into_create_time'
else:
return 'into_emp', 'dept', 'position', 'into_periods', 'into_expense', 'into_reason', 'into_calc_elem_1', 'into_calc_elem_2', 'into_calc_elem_other', 'into_money', 'into_effecte_date', 'into_expir_date', 'fix_creater', 'fix_create_time'
def into_emp_ids(self, obj):
return obj.into_emp.emp_id
into_emp_ids.short_description = '工号'
def dept(self, obj):
return obj.into_emp.emp_dept.dept_short_name
dept.short_description = '部门'
def position(self, obj):
return obj.into_emp.emp_posi
position.short_description = '岗位'
# 根据登录账号判断显示的按钮
def get_actions(self, request):
actions = super(WageExp
没有合适的资源?快使用搜索试试~ 我知道了~
基于Python写的企业用来导入数据并自动计算工资的智能AI系统源代码.rar
共40个文件
py:19个
xml:9个
html:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 60 浏览量
2023-08-24
06:50:36
上传
评论
收藏 54KB RAR 举报
温馨提示
基于Python写的企业用来导入数据并自动计算工资的智能AI系统源代码.rar
资源推荐
资源详情
资源评论
收起资源包目录
基于Python写的企业用来导入数据并自动计算工资的智能AI系统源代码.rar (40个子文件)
基于Python写的企业用来导入数据并自动计算工资的智能AI系统源代码
.idea
workspace.xml 2KB
misc.xml 294B
inspectionProfiles
profiles_settings.xml 174B
modules.xml 343B
.gitignore 184B
Python导入数据计算工资系统源码.iml 661B
WageCalc-master
db.sqlite3 0B
templates
index.html 123B
.idea
misc.xml 196B
inspectionProfiles
Project_Default.xml 430B
profiles_settings.xml 174B
modules.xml 268B
WageCalc.iml 1KB
.gitignore 176B
encodings.xml 260B
WageCalc
__init__.py 0B
wsgi.py 393B
urls.py 839B
settings.py 7KB
asgi.py 393B
manage.py 664B
wage
__init__.py 0B
tests.py 60B
admin.py 80KB
migrations
__init__.py 0B
apps.py 174B
models.py 34KB
templates
wage
leavewage.html 2KB
error.html 123B
data.html 3KB
urls.py 251B
functions
verifyIdName.py 226B
monthcalc.py 10KB
test.py 2B
views.py 10KB
static
templates
expense.xlsx 5KB
performance.xlsx 10KB
dadmin
templates
dadmin
login.html 3KB
urls.py 245B
forms.py 199B
共 40 条
- 1
资源评论
shengyin714959
- 粉丝: 833
- 资源: 6895
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功