2024-05-16 21:23:15 +08:00
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
2024-06-06 15:08:38 +08:00
|
|
|
|
from common.utils.page_helper import paginate_query_and_assign_numbers
|
|
|
|
|
from .models import DepartmentExpenseData
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def department_expense_data_list_view(request):
|
|
|
|
|
# 声明查询集
|
|
|
|
|
query_set = DepartmentExpenseData.objects.all().order_by('-year_month')
|
|
|
|
|
|
|
|
|
|
# 获取查询参数
|
|
|
|
|
year_month = request.GET.get('year_month', '')
|
|
|
|
|
primary_department = request.GET.get('primary_department', '')
|
|
|
|
|
|
|
|
|
|
# 根据提供的参数进行筛选
|
|
|
|
|
if year_month:
|
|
|
|
|
query_set = query_set.filter(year_month__icontains=year_month)
|
|
|
|
|
if primary_department:
|
|
|
|
|
query_set = query_set.filter(primary_department__icontains=primary_department)
|
|
|
|
|
|
|
|
|
|
# 对查询结果进行分页,每页10条记录
|
|
|
|
|
items = paginate_query_and_assign_numbers(
|
|
|
|
|
request=request,
|
|
|
|
|
queryset=query_set,
|
|
|
|
|
per_page=10
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 构建上下文查询参数字符串
|
|
|
|
|
query_params = '&year_month={}&primary_department={}'.format(year_month, primary_department)
|
|
|
|
|
|
|
|
|
|
fields = [
|
|
|
|
|
{"label": "一级部门", "field": "primary_department", "type": "text", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "年月", "field": "year_month", "type": "text", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "费用类型", "field": "expense_type", "type": "text", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "费用明细", "field": "expense_detail", "type": "text", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "费用限额", "field": "budget_limit", "type": "number", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "已报销额度", "field": "reimbursed_amount", "type": "number", "is_show": 1, "is_add": 1},
|
|
|
|
|
{"label": "可用额度", "field": "available_budget", "type": "number", "is_show": 1, "is_add": 1},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# 准备上下文
|
|
|
|
|
context = {
|
|
|
|
|
'items': items,
|
|
|
|
|
'id_name': 'year_month',
|
|
|
|
|
'query_params': query_params,
|
2024-06-06 18:02:55 +08:00
|
|
|
|
'model_config': {"app_label": "your_app_label", "model_name": "DepartmentExpenseData"},
|
|
|
|
|
'form_action_url': 'department_expense_data_list',
|
2024-06-06 15:08:38 +08:00
|
|
|
|
'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "费用管理", "name": "index"},
|
|
|
|
|
{"title": "各部门费用情况", "name": "department_expense_data_list"}],
|
|
|
|
|
'filters': [
|
|
|
|
|
{"type": "text", "id": "year_month", "name": "year_month", "label": "年月", "placeholder": "请输入年月"},
|
|
|
|
|
{"type": "text", "id": "primary_department", "name": "primary_department", "label": "一级部门",
|
|
|
|
|
"placeholder": "请输入一级部门"}
|
|
|
|
|
],
|
|
|
|
|
'table_columns': fields,
|
|
|
|
|
'show_button': {"add": True, "modify": True, "download": True, "upload": True},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return render(request, 'ops_tbl/fd_list.html', context)
|