优化案件模块
This commit is contained in:
18
User/migrations/0002_approval_rejection_reason.py
Normal file
18
User/migrations/0002_approval_rejection_reason.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.25 on 2026-01-22 08:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('User', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='approval',
|
||||
name='rejection_reason',
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -59,6 +59,7 @@ class Approval(models.Model):
|
||||
state = models.CharField(max_length=100) # 状态
|
||||
type = models.CharField(max_length=100) # 类别
|
||||
user_id = models.CharField(max_length=100) # 事件id
|
||||
rejection_reason = models.TextField(null=True, blank=True) # 不通过原因(审核不通过时填写)
|
||||
is_deleted = models.BooleanField(default=False) # 软删除标记
|
||||
|
||||
|
||||
|
||||
@@ -568,7 +568,7 @@ def get_approvers_from_record(business_record, approval=None):
|
||||
|
||||
|
||||
def process_approval_flow(approval, business_record, current_approver, state,
|
||||
approval_type, final_state_map=None):
|
||||
approval_type, final_state_map=None, rejection_reason=None):
|
||||
"""
|
||||
统一的审核流程处理函数
|
||||
|
||||
@@ -586,6 +586,7 @@ def process_approval_flow(approval, business_record, current_approver, state,
|
||||
state: 审核状态("已通过" 或 "未通过")
|
||||
approval_type: 审批类型(如"待办"、"报销申请"等)
|
||||
final_state_map: 状态映射字典,格式:{"已通过": "已完成", "未通过": "未通过"}
|
||||
rejection_reason: 不通过原因(审核不通过时填写)
|
||||
|
||||
Returns:
|
||||
tuple: (是否完成, 错误信息)
|
||||
@@ -599,7 +600,10 @@ def process_approval_flow(approval, business_record, current_approver, state,
|
||||
# 如果审核不通过,直接结束
|
||||
if state == "未通过":
|
||||
approval.state = "未通过"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
|
||||
if business_record and hasattr(business_record, 'state'):
|
||||
business_record.state = final_state_map.get("未通过", "未通过")
|
||||
@@ -620,7 +624,10 @@ def process_approval_flow(approval, business_record, current_approver, state,
|
||||
business_record.save(update_fields=['state'])
|
||||
elif state == "未通过":
|
||||
approval.state = "未通过"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
|
||||
if business_record and hasattr(business_record, 'state'):
|
||||
business_record.state = final_state_map.get("未通过", "未通过")
|
||||
|
||||
104
User/views.py
104
User/views.py
@@ -1298,6 +1298,7 @@ class roxyExhibition(APIView):
|
||||
"personincharge": info.personincharge,
|
||||
"type": info.type,
|
||||
"status": approval_status, # 优化后的状态:审批中、已完成
|
||||
"rejection_reason": info.rejection_reason if info.rejection_reason else None, # 不通过原因(审核不通过时填写)
|
||||
}
|
||||
|
||||
# 如果是离职财务登记类型,从content中解析结算工资
|
||||
@@ -1408,10 +1409,19 @@ class approvalProcessing(APIView):
|
||||
state = request.data.get('state')
|
||||
type = request.data.get('type')
|
||||
id = request.data.get('id')
|
||||
rejection_reason = request.data.get('rejection_reason') # 不通过原因(审核不通过时填写)
|
||||
|
||||
if not all([type, id]):
|
||||
return Response({'status': 'error', 'message': '缺少参数type或id', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 如果审核不通过,必须填写不通过原因
|
||||
if state == "未通过" and not rejection_reason:
|
||||
return Response({
|
||||
'status': 'error',
|
||||
'message': '审核不通过时必须填写不通过原因',
|
||||
'code': 1
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
approval = Approval.objects.get(id=id, is_deleted=False)
|
||||
except Approval.DoesNotExist:
|
||||
@@ -1442,7 +1452,10 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
user.state = "异常"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
user.save(update_fields=['state'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -1464,7 +1477,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="入职财务登记",
|
||||
final_state_map={"已通过": "在职", "未通过": "异常"}
|
||||
final_state_map={"已通过": "在职", "未通过": "异常"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
# 刷新审批记录,查看更新后的状态
|
||||
@@ -1500,8 +1514,11 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
invoice.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
invoice.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数
|
||||
@@ -1517,7 +1534,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="开票",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1538,8 +1556,11 @@ class approvalProcessing(APIView):
|
||||
if state == "未通过":
|
||||
approval.state = "未通过"
|
||||
income.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
income.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
else:
|
||||
# 财务查看通过(默认或不传state),直接完成
|
||||
@@ -1621,7 +1642,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="收入确认",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1642,8 +1664,11 @@ class approvalProcessing(APIView):
|
||||
if state == "未通过":
|
||||
approval.state = "未通过"
|
||||
account.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
account.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
else:
|
||||
# 财务查看通过(默认或不传state),直接完成
|
||||
@@ -1677,8 +1702,11 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
payment.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
payment.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数(与离职逻辑一样)
|
||||
@@ -1694,7 +1722,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="付款申请",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1720,8 +1749,11 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
reimbursement.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
reimbursement.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数(与付款申请逻辑一样)
|
||||
@@ -1737,7 +1769,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="报销申请",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1763,8 +1796,11 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
bonus.state = "未通过"
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
bonus.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数(与付款申请、报销申请逻辑一样)
|
||||
@@ -1780,7 +1816,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="工资/奖金变更",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1803,7 +1840,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="立项登记",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1826,7 +1864,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="投标登记",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1858,7 +1897,10 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
case.state = "未通过"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
case.save(update_fields=['state'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -1871,7 +1913,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="案件管理",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -1895,7 +1938,10 @@ class approvalProcessing(APIView):
|
||||
if state == "未通过":
|
||||
approval.state = "未通过"
|
||||
change_request.state = "未通过"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
change_request.save(update_fields=['state'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -1952,7 +1998,10 @@ class approvalProcessing(APIView):
|
||||
else:
|
||||
approval.state = "未通过"
|
||||
seal_app.state = "未通过"
|
||||
approval.save(update_fields=['state'])
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
seal_app.save(update_fields=['state'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -1969,7 +2018,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="申请用印",
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已通过", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -2016,8 +2066,11 @@ class approvalProcessing(APIView):
|
||||
# 如果审批未通过,恢复用户状态为"在职"
|
||||
user.state = "在职"
|
||||
user.Dateofdeparture = None
|
||||
# 保存不通过原因
|
||||
if rejection_reason:
|
||||
approval.rejection_reason = rejection_reason
|
||||
user.save(update_fields=['state', 'Dateofdeparture'])
|
||||
approval.save(update_fields=['state'])
|
||||
approval.save(update_fields=['state', 'rejection_reason'])
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
# 使用统一的审核流程处理函数(会同步离职工资信息到下一个审批人)
|
||||
@@ -2029,7 +2082,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="离职财务登记",
|
||||
final_state_map={"已通过": "已离职", "未通过": "在职"}
|
||||
final_state_map={"已通过": "已离职", "未通过": "在职"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
@@ -2064,7 +2118,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="待办",
|
||||
final_state_map={"已通过": "已完成", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已完成", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
# 刷新审批记录,查看更新后的状态
|
||||
@@ -2093,7 +2148,8 @@ class approvalProcessing(APIView):
|
||||
current_approver=current_approver,
|
||||
state=state,
|
||||
approval_type="结案申请",
|
||||
final_state_map={"已通过": "已完成", "未通过": "未通过"}
|
||||
final_state_map={"已通过": "已完成", "未通过": "未通过"},
|
||||
rejection_reason=rejection_reason
|
||||
)
|
||||
|
||||
if error:
|
||||
|
||||
Reference in New Issue
Block a user