haha
This commit is contained in:
@@ -1339,6 +1339,24 @@ class approvalProcessing(APIView):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return Response({'status': 'error', 'message': '用户记录不存在或已被删除', 'code': 1}, status=status.HTTP_404_NOT_FOUND)
|
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 == "已抄送财务":
|
if approval.personincharge == "财务" and approval.state == "已抄送财务":
|
||||||
# 财务部审核逻辑:财务部只需要一个人审核完即可完成
|
# 财务部审核逻辑:财务部只需要一个人审核完即可完成
|
||||||
@@ -1354,7 +1372,7 @@ class approvalProcessing(APIView):
|
|||||||
approval.save(update_fields=['state'])
|
approval.save(update_fields=['state'])
|
||||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
# 使用统一的审核流程处理函数
|
# 使用统一的审核流程处理函数(会同步离职工资信息到下一个审批人)
|
||||||
from User.utils import process_approval_flow
|
from User.utils import process_approval_flow
|
||||||
current_approver = approval.personincharge
|
current_approver = approval.personincharge
|
||||||
is_completed, error = process_approval_flow(
|
is_completed, error = process_approval_flow(
|
||||||
|
|||||||
@@ -2093,6 +2093,8 @@ class UserDeparture(APIView):
|
|||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
离职财务登记
|
离职财务登记
|
||||||
|
优化后:只需填写姓名和离职时间,其余字段从人事管理中同步
|
||||||
|
离职工资由审批人填写
|
||||||
如果用户有案件(作为承办人员),需要先转移案件才能完成离职登记
|
如果用户有案件(作为承办人员),需要先转移案件才能完成离职登记
|
||||||
:param request:
|
:param request:
|
||||||
:param args:
|
:param args:
|
||||||
@@ -2107,8 +2109,9 @@ class UserDeparture(APIView):
|
|||||||
if personincharge and not approvers:
|
if personincharge and not approvers:
|
||||||
approvers = [personincharge] if personincharge else None
|
approvers = [personincharge] if personincharge else None
|
||||||
|
|
||||||
|
# 只验证必填字段:姓名和离职时间
|
||||||
if not all([username, Dateofdeparture]):
|
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)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -2159,7 +2162,7 @@ class UserDeparture(APIView):
|
|||||||
# 根据团队类型判断是否需要审批
|
# 根据团队类型判断是否需要审批
|
||||||
# 规则:
|
# 规则:
|
||||||
# - 个人团队(personal/独立律师):不触发审批
|
# - 个人团队(personal/独立律师):不触发审批
|
||||||
# - 团队(team/团队律师):需要审批,直接选择某个人,审批人需要指定结算工资
|
# - 团队(team/团队律师):需要审批,审批人需要指定结算工资
|
||||||
from User.models import Team
|
from User.models import Team
|
||||||
|
|
||||||
# 获取用户的团队信息
|
# 获取用户的团队信息
|
||||||
@@ -2178,16 +2181,33 @@ class UserDeparture(APIView):
|
|||||||
today = datetime.datetime.now()
|
today = datetime.datetime.now()
|
||||||
formatted_date = today.strftime("%Y-%m-%d")
|
formatted_date = today.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
settlement_salary = request.data.get('settlement_salary') # 结算工资(可选,审批人可以后续填写)
|
# 从人事管理同步用户信息,构建审批内容
|
||||||
|
# 包含用户的基本信息:姓名、岗位、部门、团队等
|
||||||
content = f"{username}在{Dateofdeparture}办理离职"
|
content_parts = [f"{user.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(
|
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
|
||||||
team_name=team_name,
|
team_name=team_name,
|
||||||
approvers=approvers,
|
approvers=approvers,
|
||||||
title=username + "离职财务登记",
|
title=user.username + "离职财务登记",
|
||||||
content=content,
|
content=content,
|
||||||
approval_type="离职财务登记",
|
approval_type="离职财务登记",
|
||||||
user_id=str(user.id),
|
user_id=str(user.id),
|
||||||
@@ -2225,45 +2245,28 @@ class UserDeparture(APIView):
|
|||||||
remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}(个人团队,无需审批)'
|
remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}(个人团队,无需审批)'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# 如果创建了审批记录,记录操作日志
|
||||||
# 构建审批内容,包含结算工资信息(如果已提供)
|
if approval:
|
||||||
content_parts = [f"{username}在{Dateofdeparture}办理离职登记"]
|
new_data = {
|
||||||
if settlement_salary:
|
'user_id': user.id,
|
||||||
content_parts.append(f"结算工资:{settlement_salary}元")
|
'username': user.username,
|
||||||
else:
|
'Dateofdeparture': Dateofdeparture,
|
||||||
content_parts.append("结算工资:待审批人指定")
|
'state': user.state,
|
||||||
content = ",".join(content_parts)
|
'position': user.position,
|
||||||
|
'team': user.team,
|
||||||
approval = Approval.objects.create(
|
'settlement_salary': '待审批人指定'
|
||||||
title=username + "离职财务登记",
|
}
|
||||||
content=content,
|
log_operation(
|
||||||
times=formatted_date,
|
request=request,
|
||||||
personincharge=personincharge, # 直接使用审批人用户名
|
operation_type='CREATE',
|
||||||
state='审核中',
|
module='Finance',
|
||||||
type="离职财务登记",
|
action='新增离职财务登记',
|
||||||
user_id=str(user.id)
|
target_type='User',
|
||||||
)
|
target_id=user.id,
|
||||||
|
target_name=user.username,
|
||||||
# 记录操作日志
|
new_data=new_data,
|
||||||
new_data = {
|
remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}'
|
||||||
'user_id': user.id,
|
)
|
||||||
'username': user.username,
|
|
||||||
'Dateofdeparture': Dateofdeparture,
|
|
||||||
'state': user.state,
|
|
||||||
'approver': personincharge,
|
|
||||||
'settlement_salary': settlement_salary if settlement_salary else '待审批人指定'
|
|
||||||
}
|
|
||||||
log_operation(
|
|
||||||
request=request,
|
|
||||||
operation_type='CREATE',
|
|
||||||
module='Finance',
|
|
||||||
action='新增离职财务登记',
|
|
||||||
target_type='User',
|
|
||||||
target_id=user.id,
|
|
||||||
target_name=user.username,
|
|
||||||
new_data=new_data,
|
|
||||||
remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}'
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
'message': '离职登记成功',
|
'message': '离职登记成功',
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
import pymysql
|
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()
|
pymysql.install_as_MySQLdb()
|
||||||
@@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
|||||||
|
|
||||||
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
||||||
import pymysql
|
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()
|
pymysql.install_as_MySQLdb()
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
|
|||||||
|
|
||||||
# 使用 PyMySQL 替代 mysqlclient(必须在导入其他模块之前)
|
# 使用 PyMySQL 替代 mysqlclient(必须在导入其他模块之前)
|
||||||
import pymysql
|
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()
|
pymysql.install_as_MySQLdb()
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
|||||||
|
|
||||||
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
||||||
import pymysql
|
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()
|
pymysql.install_as_MySQLdb()
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
"""Django's command-line utility for administrative tasks."""
|
"""Django's command-line utility for administrative tasks."""
|
||||||
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
# 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前)
|
||||||
import pymysql
|
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()
|
pymysql.install_as_MySQLdb()
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
Reference in New Issue
Block a user