优化案件模块

This commit is contained in:
27942
2026-01-20 14:11:27 +08:00
parent 8e621572af
commit 2629303e7f
5 changed files with 136 additions and 25 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.2.25 on 2026-01-20 06:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('finance', '0002_add_missing_approvers_order'),
]
operations = [
migrations.AddField(
model_name='invoice',
name='approvers_order',
field=models.TextField(blank=True, null=True),
),
]

View File

@@ -13,6 +13,7 @@ class Invoice(models.Model):
state = models.CharField(max_length=100) # 状态
username = models.CharField(max_length=100) # 谁提交的
times = models.TextField() # 提交时间
approvers_order = models.TextField(null=True, blank=True) # 审核人顺序JSON格式存储["张三","李四","王五"]
is_deleted = models.BooleanField(default=False) # 软删除标记

View File

@@ -691,6 +691,26 @@ class issueAnInvoice(APIView):
today = datetime.datetime.now()
formatted_date = today.strftime("%Y-%m-%d")
# 获取提交人的团队信息(用于审核流程)
from User.models import Team
team_name = user.team
team = None
if team_name:
try:
team = Team.objects.get(name=team_name, is_deleted=False)
except Team.DoesNotExist:
pass
# 审核人列表可选多人团队时需要推荐用户ID数组如[1,2,3],兼容:用户名数组)
approvers = request.data.get('approvers')
# 兼容旧接口:如果传了 personincharge转换为 approvers
personincharge_param = request.data.get('personincharge')
approvers = normalize_approvers_param(approvers, personincharge_param)
# 根据团队类型决定初始状态
# 如果是团队类型且需要审核,状态为"审核中";否则为"待财务处理"
initial_state = "审核中" if (team and team.team_type == 'team') else "待财务处理"
invoice = Invoice.objects.create(
ContractNo=ContractNo,
@@ -701,11 +721,55 @@ class issueAnInvoice(APIView):
number=number,
address_telephone=address_telephone,
bank=bank,
state="审核中",
state=initial_state,
username=username,
times=formatted_date,
)
# 已删除:不再创建开票待办事项
# 创建开票待办事项
from User.utils import create_approval_with_team_logic, build_missing_approvers_message
# 构建审批内容
content_parts = [
f"{username}{formatted_date}提交了开票申请",
f"合同编号:{ContractNo}",
f"负责人:{personincharge}",
f"开票金额:{amount}",
f"开票类型:{type}",
f"开票单位:{unit}"
]
content = "".join(content_parts)
# 使用统一的审核流程函数
try:
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=str(invoice.id),
business_record=invoice,
today=formatted_date
)
except Exception as e:
# 记录异常并返回错误信息
import logging
logger = logging.getLogger(__name__)
logger.error(f"创建开票审批失败: {str(e)}", exc_info=True)
return Response({
'status': 'error',
'message': f'创建审批流程失败: {str(e)},请检查团队配置和审核人信息',
'code': 1
}, status=status.HTTP_400_BAD_REQUEST)
# 如果返回None且需要审核说明缺少审核人
if approval is None and needs_approval:
return Response({
'status': 'error',
'message': build_missing_approvers_message(team_name, approvers),
'code': 1
}, status=status.HTTP_400_BAD_REQUEST)
# 记录操作日志
new_data = {
@@ -736,6 +800,9 @@ class issueAnInvoice(APIView):
'id': invoice.id,
'ContractNo': invoice.ContractNo,
'personincharge': invoice.personincharge,
'state': invoice.state,
'approval_id': approval.id if approval else None,
'needs_approval': team is None or team.team_type != 'personal'
}
}, status=status.HTTP_200_OK)