优化收入确认
This commit is contained in:
@@ -867,7 +867,7 @@ def process_approval_flow(approval, business_record, current_approver, state,
|
||||
|
||||
|
||||
def create_approval_with_team_logic(team_name, approvers, title, content, approval_type, user_id,
|
||||
business_record=None, today=None, applicant=None):
|
||||
business_record=None, today=None, applicant=None, force_approval=False):
|
||||
"""
|
||||
根据团队类型创建审批记录(统一逻辑)
|
||||
|
||||
@@ -876,6 +876,7 @@ def create_approval_with_team_logic(team_name, approvers, title, content, approv
|
||||
- 投标登记/立项登记:最后一步给申请人,生成「待查看」待办,申请人查看后完成(不再给财务部)
|
||||
- 其他类型:团队(team)需要审核人,按顺序审核,最后抄送财务
|
||||
- 无团队:直接抄送财务
|
||||
- 强制审批模式(force_approval=True):即使是个人团队也需要审批,用于付款申请、报销、工资/奖金变更等
|
||||
|
||||
注意:personincharge字段统一使用财务部ID(优先)或回退到"财务"字符串
|
||||
|
||||
@@ -889,6 +890,7 @@ def create_approval_with_team_logic(team_name, approvers, title, content, approv
|
||||
business_record: 业务记录对象(可选)
|
||||
today: 日期字符串(可选,格式:YYYY-MM-DD)
|
||||
applicant: 申请人用户名(可选,投标/立项时填,最后一步生成待查看待办给申请人)
|
||||
force_approval: 是否强制审批(默认False)。设为True时,即使是个人团队也需要审批(如付款申请、报销、工资/奖金变更)
|
||||
|
||||
Returns:
|
||||
tuple: (approval对象, approvers_order_json, 是否需要审核)
|
||||
@@ -970,6 +972,47 @@ def create_approval_with_team_logic(team_name, approvers, title, content, approv
|
||||
# 如果没有传入审核人,则根据团队类型判断
|
||||
# 判断团队类型
|
||||
if not team_name or not team or (team and team.team_type == 'personal'):
|
||||
# 强制审批模式(付款申请、报销、工资/奖金变更等):即使是个人团队也需要审批
|
||||
if force_approval:
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info(f"create_approval_with_team_logic: 强制审批模式 - 审批类型={approval_type}, 团队={team_name}")
|
||||
|
||||
# 尝试获取默认审核人:优先律所负责人,然后管委会成员
|
||||
default_approver = get_law_firm_leader(team_name)
|
||||
if not default_approver:
|
||||
# 如果找不到默认审核人,返回错误
|
||||
logger.warning(f"create_approval_with_team_logic: 强制审批模式下找不到默认审核人")
|
||||
return None, None, True # needs_approval = True,表示需要审批但缺少审核人
|
||||
|
||||
# 使用默认审核人创建审批
|
||||
approvers_list = [default_approver]
|
||||
approvers_order_json = json.dumps(approvers_list, ensure_ascii=False)
|
||||
|
||||
# 存储到业务记录
|
||||
if business_record and hasattr(business_record, 'approvers_order'):
|
||||
business_record.approvers_order = approvers_order_json
|
||||
business_record.state = "审核中"
|
||||
business_record.save(update_fields=['approvers_order', 'state'])
|
||||
|
||||
# 创建审批流程内容
|
||||
content_with_flow = f"{content},审批流程:{default_approver} → 财务部(按顺序审批),当前审批人:{default_approver}"
|
||||
|
||||
logger.info(f"create_approval_with_team_logic: 强制审批 - 使用默认审核人 {default_approver}")
|
||||
|
||||
approval = Approval.objects.create(
|
||||
title=title,
|
||||
content=content_with_flow,
|
||||
times=today,
|
||||
personincharge=default_approver,
|
||||
state="审核中",
|
||||
type=approval_type,
|
||||
user_id=str(user_id),
|
||||
applicant=applicant
|
||||
)
|
||||
|
||||
return approval, approvers_order_json, True
|
||||
|
||||
# 投标登记/立项登记/案件变更/结案申请且传入了申请人:最后一步给申请人,生成待查看待办(不再给财务部)
|
||||
if approval_type in ("投标登记", "立项登记", "案件变更", "结案申请") and applicant:
|
||||
content_to_save = content + ",待申请人查看"
|
||||
|
||||
@@ -2291,8 +2291,8 @@ class approvalProcessing(APIView):
|
||||
return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
if type == "结案申请":
|
||||
from business.models import Schedule, Case
|
||||
try:
|
||||
from business.models import Schedule, Case
|
||||
schedule = Schedule.objects.get(id=approval.user_id, is_deleted=False)
|
||||
except Schedule.DoesNotExist:
|
||||
return Response({'status': 'error', 'message': '结案申请记录不存在或已被删除', 'code': 1}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
@@ -2278,9 +2278,8 @@ class PaymentRequest(APIView):
|
||||
# 如果团队不存在,默认按团队类型处理(需要审批)
|
||||
pass
|
||||
|
||||
# 根据团队类型决定初始状态
|
||||
# 如果是团队类型且需要审核,状态为"审核中";否则为"已通过"(直接抄送财务)
|
||||
initial_state = "审核中" if (team and team.team_type == 'team') else "已通过"
|
||||
# 付款申请统一都需要审批(无论团队类型)
|
||||
initial_state = "审核中"
|
||||
|
||||
# 创建付款申请记录
|
||||
pay = Payment.objects.create(
|
||||
@@ -2316,7 +2315,7 @@ class PaymentRequest(APIView):
|
||||
content_parts.insert(3, f"付款日期:{times}")
|
||||
content = ",".join(content_parts)
|
||||
|
||||
# 使用统一的审核流程函数(与离职逻辑一样)
|
||||
# 使用统一的审核流程函数(付款申请统一需要审批,force_approval=True)
|
||||
from User.utils import create_approval_with_team_logic
|
||||
|
||||
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
|
||||
@@ -2327,7 +2326,8 @@ class PaymentRequest(APIView):
|
||||
approval_type="付款申请",
|
||||
user_id=str(pay.id),
|
||||
business_record=pay,
|
||||
today=date_string
|
||||
today=date_string,
|
||||
force_approval=True # 付款申请统一需要审批
|
||||
)
|
||||
|
||||
# 如果返回None且需要审核,说明缺少审核人
|
||||
@@ -2367,7 +2367,7 @@ class PaymentRequest(APIView):
|
||||
'id': pay.id,
|
||||
'state': pay.state,
|
||||
'approval_id': approval.id if approval else None,
|
||||
'needs_approval': team is None or team.team_type != 'personal', # 是否需要审批(前端用这个字段判断是团队还是个人)
|
||||
'needs_approval': True, # 付款申请统一都需要审批
|
||||
'team_type': team.team_type if team else None, # 团队类型:personal/team(前端用这个字段判断)
|
||||
'team_name': team_name # 团队名称
|
||||
}
|
||||
@@ -2653,9 +2653,8 @@ class reimbursement(APIView):
|
||||
now = datetime.now()
|
||||
date_string = now.strftime("%Y-%m-%d")
|
||||
|
||||
# 根据团队类型决定初始状态
|
||||
# 如果是团队类型且需要审核,状态为"审核中";否则为"已通过"(直接抄送财务)
|
||||
initial_state = "审核中" if (team and team.team_type == 'team') else "已通过"
|
||||
# 报销统一都需要审批(无论团队类型)
|
||||
initial_state = "审核中"
|
||||
|
||||
reim = Reimbursement.objects.create(
|
||||
person=person,
|
||||
@@ -2667,7 +2666,7 @@ class reimbursement(APIView):
|
||||
state=initial_state
|
||||
)
|
||||
|
||||
# 使用统一的审核流程函数
|
||||
# 使用统一的审核流程函数(报销统一需要审批,force_approval=True)
|
||||
from User.utils import create_approval_with_team_logic
|
||||
|
||||
content = f"{person}在{times}提交了报销申请,报销理由:{reason},报销金额:{amount},报销日期:{times},费用说明:{FeeDescription}"
|
||||
@@ -2680,7 +2679,8 @@ class reimbursement(APIView):
|
||||
approval_type="报销申请",
|
||||
user_id=str(reim.id),
|
||||
business_record=reim,
|
||||
today=date_string
|
||||
today=date_string,
|
||||
force_approval=True # 报销统一需要审批
|
||||
)
|
||||
|
||||
# 如果返回None且需要审核,说明缺少审核人
|
||||
@@ -2718,7 +2718,7 @@ class reimbursement(APIView):
|
||||
'id': reim.id,
|
||||
'state': reim.state,
|
||||
'approval_id': approval.id if approval else None,
|
||||
'needs_approval': team is None or team.team_type != 'personal', # 是否需要审批(前端用这个字段判断是团队还是个人)
|
||||
'needs_approval': True, # 报销统一都需要审批
|
||||
'team_type': team.team_type if team else None, # 团队类型:personal/team(前端用这个字段判断)
|
||||
'team_name': team_name # 团队名称
|
||||
}
|
||||
@@ -2918,9 +2918,8 @@ class Change(APIView):
|
||||
except Team.DoesNotExist:
|
||||
pass
|
||||
|
||||
# 根据团队类型决定初始状态
|
||||
# 如果是团队类型且需要审核,状态为"审核中";否则为"已通过"(直接抄送财务)
|
||||
initial_state = "审核中" if (team and team.team_type == 'team') else "已通过"
|
||||
# 工资/奖金变更统一都需要审批(无论团队类型)
|
||||
initial_state = "审核中"
|
||||
|
||||
bonus = BonusChange.objects.create(
|
||||
username=username,
|
||||
@@ -2935,7 +2934,7 @@ class Change(APIView):
|
||||
|
||||
content = f"{submitter}在{date_string}提交了工资/奖金变更,类型:{type},调整说明:{Instructions}"
|
||||
|
||||
# 使用统一的审核流程函数(与付款申请、报销申请逻辑一样)
|
||||
# 使用统一的审核流程函数(工资/奖金变更统一需要审批,force_approval=True)
|
||||
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
|
||||
team_name=team_name,
|
||||
approvers=approvers,
|
||||
@@ -2944,7 +2943,8 @@ class Change(APIView):
|
||||
approval_type="工资/奖金变更",
|
||||
user_id=str(bonus.id),
|
||||
business_record=bonus,
|
||||
today=date_string
|
||||
today=date_string,
|
||||
force_approval=True # 工资/奖金变更统一需要审批
|
||||
)
|
||||
|
||||
# 如果返回None且需要审核,说明缺少审核人
|
||||
@@ -2983,7 +2983,7 @@ class Change(APIView):
|
||||
'submitter': bonus.submitter, # 提交人(明确是谁提交的申请)
|
||||
'state': bonus.state,
|
||||
'approval_id': approval.id if approval else None,
|
||||
'needs_approval': team is None or team.team_type != 'personal', # 是否需要审批(前端用这个字段判断是团队还是个人)
|
||||
'needs_approval': True, # 工资/奖金变更统一都需要审批
|
||||
'team_type': team.team_type if team else None, # 团队类型:personal/team(前端用这个字段判断)
|
||||
'team_name': team_name # 团队名称
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user