优化案件模块
This commit is contained in:
@@ -1472,7 +1472,27 @@ class approvalProcessing(APIView):
|
||||
except BonusChange.DoesNotExist:
|
||||
return Response({'status': 'error', 'message': '工资/奖金变更记录不存在或已被删除', 'code': 1}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# 使用统一的审核流程处理函数
|
||||
# 检查当前是否已经是财务审核
|
||||
if is_finance_personincharge(approval.personincharge) and approval.state == "已抄送财务":
|
||||
# 财务部审核逻辑:如果只传了type和id,不传state,则默认为"已通过"
|
||||
if not state:
|
||||
state = "已通过"
|
||||
|
||||
if state == "已通过":
|
||||
approval.state = "已通过"
|
||||
bonus.state = "已通过"
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
bonus.state = "未通过"
|
||||
bonus.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数(与付款申请、报销申请逻辑一样)
|
||||
# 非财务查看时,state参数是必填的
|
||||
if not state:
|
||||
return Response({'status': 'error', 'message': '缺少参数state(审核状态:已通过/未通过)', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
from User.utils import process_approval_flow
|
||||
current_approver = approval.personincharge
|
||||
is_completed, error = process_approval_flow(
|
||||
|
||||
@@ -2676,42 +2676,61 @@ class Change(APIView):
|
||||
if not all([username, type, Instructions]):
|
||||
return Response({'status': 'error', 'message': '缺少参数', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 获取提交人信息
|
||||
submitter = '未知用户'
|
||||
try:
|
||||
user = User.objects.get(token=token, is_deleted=False)
|
||||
submitter = user.username
|
||||
except User.DoesNotExist:
|
||||
# 如果token无效,使用username作为提交人(兼容旧逻辑)
|
||||
# 获取提交人信息:优先从token获取,确保明确记录是谁提交的
|
||||
submitter = None
|
||||
user = None
|
||||
if token:
|
||||
try:
|
||||
user = User.objects.get(token=token, is_deleted=False)
|
||||
submitter = user.username
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
# 如果token无效或未提供,使用username作为提交人(兼容旧逻辑)
|
||||
if not submitter:
|
||||
submitter = username
|
||||
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
date_string = now.strftime("%Y-%m-%d")
|
||||
|
||||
# 获取用户的团队信息
|
||||
team_name = user.team if user else None
|
||||
team = None
|
||||
if team_name:
|
||||
from User.models import Team
|
||||
try:
|
||||
team = Team.objects.get(name=team_name, is_deleted=False)
|
||||
except Team.DoesNotExist:
|
||||
pass
|
||||
|
||||
# 根据团队类型决定初始状态
|
||||
# 如果是团队类型且需要审核,状态为"审核中";否则为"已通过"(直接抄送财务)
|
||||
initial_state = "审核中" if (team and team.team_type == 'team') else "已通过"
|
||||
|
||||
bonus = BonusChange.objects.create(
|
||||
username=username,
|
||||
type=type,
|
||||
Instructions=Instructions,
|
||||
times=now.strftime("%Y-%m-%d"),
|
||||
state="审核中",
|
||||
times=date_string,
|
||||
state=initial_state,
|
||||
submitter=submitter # 记录提交人
|
||||
)
|
||||
|
||||
# 获取用户的团队信息
|
||||
team_name = user.team if user else None
|
||||
from User.utils import create_approval_with_team_logic
|
||||
|
||||
content = f"{submitter}在{now.strftime('%Y-%m-%d')}提交了工资/奖金变更,类型:{type},调整说明:{Instructions}"
|
||||
content = f"{submitter}在{date_string}提交了工资/奖金变更,类型:{type},调整说明:{Instructions}"
|
||||
|
||||
# 使用统一的审核流程函数
|
||||
# 使用统一的审核流程函数(与付款申请、报销申请逻辑一样)
|
||||
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
|
||||
team_name=team_name,
|
||||
approvers=approvers,
|
||||
title=username + "工资/奖金变更",
|
||||
content=content,
|
||||
approval_type="工资/奖金变更",
|
||||
user_id=bonus.id,
|
||||
user_id=str(bonus.id),
|
||||
business_record=bonus,
|
||||
today=now.strftime("%Y-%m-%d")
|
||||
today=date_string
|
||||
)
|
||||
|
||||
# 如果返回None且需要审核,说明缺少审核人
|
||||
@@ -2746,7 +2765,13 @@ class Change(APIView):
|
||||
'code': 0,
|
||||
'data': {
|
||||
'id': bonus.id,
|
||||
'submitter': bonus.submitter
|
||||
'username': bonus.username, # 变更对象(被变更工资/奖金的人员)
|
||||
'submitter': bonus.submitter, # 提交人(明确是谁提交的申请)
|
||||
'state': bonus.state,
|
||||
'approval_id': approval.id if approval else None,
|
||||
'needs_approval': team is None or team.team_type != 'personal', # 是否需要审批(前端用这个字段判断是团队还是个人)
|
||||
'team_type': team.team_type if team else None, # 团队类型:personal/team(前端用这个字段判断)
|
||||
'team_name': team_name # 团队名称
|
||||
}
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -2807,13 +2832,17 @@ class ChangeDetail(APIView):
|
||||
user_agents_page = paginator.page(paginator.num_pages)
|
||||
data = []
|
||||
for info in user_agents_page.object_list:
|
||||
# 明确展示提交人:优先使用submitter字段,如果没有则使用username作为备选
|
||||
submitter_name = info.submitter if info.submitter else info.username
|
||||
|
||||
itme = {
|
||||
"id": info.id,
|
||||
"times": info.times,
|
||||
"type": info.type,
|
||||
"Instructions": info.Instructions,
|
||||
"username": info.username,
|
||||
"submitter": info.submitter if info.submitter else info.username, # 提交人,如果没有则使用username
|
||||
"username": info.username, # 变更对象(被变更工资/奖金的人员)
|
||||
"submitter": submitter_name, # 提交人(明确是谁提交的申请)
|
||||
"state": info.state, # 状态
|
||||
}
|
||||
data.append(itme)
|
||||
return Response({'message': '展示成功', "total": total, 'data': data, 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
Reference in New Issue
Block a user