haha
This commit is contained in:
@@ -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 = f"{username}在{Dateofdeparture}办理离职"
|
||||
if settlement_salary:
|
||||
content += f",结算工资:{settlement_salary}"
|
||||
# 从人事管理同步用户信息,构建审批内容
|
||||
# 包含用户的基本信息:姓名、岗位、部门、团队等
|
||||
content_parts = [f"{user.username}在{Dateofdeparture}办理离职登记"]
|
||||
|
||||
# 同步岗位信息
|
||||
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,45 +2245,28 @@ 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)
|
||||
)
|
||||
|
||||
# 记录操作日志
|
||||
new_data = {
|
||||
'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}'
|
||||
)
|
||||
# 如果创建了审批记录,记录操作日志
|
||||
if approval:
|
||||
new_data = {
|
||||
'user_id': user.id,
|
||||
'username': user.username,
|
||||
'Dateofdeparture': Dateofdeparture,
|
||||
'state': user.state,
|
||||
'position': user.position,
|
||||
'team': user.team,
|
||||
'settlement_salary': '待审批人指定'
|
||||
}
|
||||
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({
|
||||
'message': '离职登记成功',
|
||||
|
||||
Reference in New Issue
Block a user