This commit is contained in:
27942
2026-01-14 11:01:02 +08:00
parent 38c2e4267d
commit 875d5c88b4
7 changed files with 89 additions and 48 deletions

View File

@@ -1339,6 +1339,24 @@ class approvalProcessing(APIView):
except User.DoesNotExist:
return Response({'status': 'error', 'message': '用户记录不存在或已被删除', 'code': 1}, status=status.HTTP_404_NOT_FOUND)
# 接收离职工资参数(可选,审批人可以填写)
settlement_salary = request.data.get('settlement_salary')
# 如果审批人填写了离职工资更新审批记录的content字段
if settlement_salary:
# 更新审批内容中的结算工资信息
content = approval.content
# 替换或添加结算工资信息
if "结算工资:" in content:
# 使用正则表达式替换结算工资部分
import re
content = re.sub(r'结算工资:[^]*', f'结算工资:{settlement_salary}', content)
else:
# 如果content中没有结算工资信息添加到末尾
content = content + f",结算工资:{settlement_salary}"
approval.content = content
approval.save(update_fields=['content'])
# 检查当前是否已经是财务审核
if approval.personincharge == "财务" and approval.state == "已抄送财务":
# 财务部审核逻辑:财务部只需要一个人审核完即可完成
@@ -1354,7 +1372,7 @@ class approvalProcessing(APIView):
approval.save(update_fields=['state'])
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
# 使用统一的审核流程处理函数
# 使用统一的审核流程处理函数(会同步离职工资信息到下一个审批人)
from User.utils import process_approval_flow
current_approver = approval.personincharge
is_completed, error = process_approval_flow(

View File

@@ -2093,6 +2093,8 @@ class UserDeparture(APIView):
def post(self, request, *args, **kwargs):
"""
离职财务登记
优化后:只需填写姓名和离职时间,其余字段从人事管理中同步
离职工资由审批人填写
如果用户有案件(作为承办人员),需要先转移案件才能完成离职登记
:param request:
:param args:
@@ -2107,8 +2109,9 @@ class UserDeparture(APIView):
if personincharge and not approvers:
approvers = [personincharge] if personincharge else None
# 只验证必填字段:姓名和离职时间
if not all([username, Dateofdeparture]):
return Response({'status': 'error', 'message': '缺少参数:用户名和离职时间不能为空', 'code': 1},
return Response({'status': 'error', 'message': '缺少参数:名和离职时间不能为空', 'code': 1},
status=status.HTTP_400_BAD_REQUEST)
try:
@@ -2159,7 +2162,7 @@ class UserDeparture(APIView):
# 根据团队类型判断是否需要审批
# 规则:
# - 个人团队personal/独立律师):不触发审批
# - 团队team/团队律师):需要审批,直接选择某个人,审批人需要指定结算工资
# - 团队team/团队律师):需要审批,审批人需要指定结算工资
from User.models import Team
# 获取用户的团队信息
@@ -2178,16 +2181,33 @@ class UserDeparture(APIView):
today = datetime.datetime.now()
formatted_date = today.strftime("%Y-%m-%d")
settlement_salary = request.data.get('settlement_salary') # 结算工资(可选,审批人可以后续填写)
# 从人事管理同步用户信息,构建审批内容
# 包含用户的基本信息:姓名、岗位、部门、团队等
content_parts = [f"{user.username}{Dateofdeparture}办理离职登记"]
content = f"{username}{Dateofdeparture}办理离职"
if settlement_salary:
content += f",结算工资{settlement_salary}"
# 同步岗位信息
if user.position:
content_parts.append(f"岗位{user.position}")
# 同步部门信息
departments = user.department.filter(is_deleted=False)
if departments.exists():
dept_names = [dept.username for dept in departments]
content_parts.append(f"部门:{', '.join(dept_names)}")
# 同步团队信息
if user.team:
content_parts.append(f"团队:{user.team}")
# 离职工资由审批人填写,初始状态为"待审批人指定"
content_parts.append("结算工资:待审批人指定")
content = "".join(content_parts)
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
team_name=team_name,
approvers=approvers,
title=username + "离职财务登记",
title=user.username + "离职财务登记",
content=content,
approval_type="离职财务登记",
user_id=str(user.id),
@@ -2225,33 +2245,16 @@ class UserDeparture(APIView):
remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}(个人团队,无需审批)'
)
else:
# 构建审批内容,包含结算工资信息(如果已提供)
content_parts = [f"{username}{Dateofdeparture}办理离职登记"]
if settlement_salary:
content_parts.append(f"结算工资:{settlement_salary}")
else:
content_parts.append("结算工资:待审批人指定")
content = "".join(content_parts)
approval = Approval.objects.create(
title=username + "离职财务登记",
content=content,
times=formatted_date,
personincharge=personincharge, # 直接使用审批人用户名
state='审核中',
type="离职财务登记",
user_id=str(user.id)
)
# 记录操作日志
# 如果创建了审批记录,记录操作日志
if approval:
new_data = {
'user_id': user.id,
'username': user.username,
'Dateofdeparture': Dateofdeparture,
'state': user.state,
'approver': personincharge,
'settlement_salary': settlement_salary if settlement_salary else '待审批人指定'
'position': user.position,
'team': user.team,
'settlement_salary': '待审批人指定'
}
log_operation(
request=request,

View File

@@ -1,2 +1,6 @@
import pymysql
# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求
# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()

View File

@@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
# 使用 PyMySQL 替代 mysqlclient必须在导入 Django 之前)
import pymysql
# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求
# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()
import os

View File

@@ -12,6 +12,10 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
# 使用 PyMySQL 替代 mysqlclient必须在导入其他模块之前
import pymysql
# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求
# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()
from pathlib import Path

View File

@@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
# 使用 PyMySQL 替代 mysqlclient必须在导入 Django 之前)
import pymysql
# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求
# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()
import os

View File

@@ -2,6 +2,10 @@
"""Django's command-line utility for administrative tasks."""
# 使用 PyMySQL 替代 mysqlclient必须在导入 Django 之前)
import pymysql
# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求
# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()
import os