forked from erp-dev/erp
feat: added printing module
This commit is contained in:
@@ -83,14 +83,18 @@ def get_progress_percentage(business_object: 'models.BusinessObject') -> float:
|
||||
return (completed_count / total_nodes) * 100
|
||||
|
||||
|
||||
def advance_to_next_state(business_object: 'models.BusinessObject', user: 'User') -> Tuple[bool, str]:
|
||||
def advance_to_next_state(business_object: 'models.BusinessObject', user) -> Tuple[bool, str]:
|
||||
"""
|
||||
将订单推进到下一个状态
|
||||
|
||||
返回: (是否成功, 消息)
|
||||
"""
|
||||
can_advance, reason = can_advance_to_next_state(business_object)
|
||||
if not can_advance:
|
||||
return False, reason
|
||||
|
||||
with transaction.atomic():
|
||||
# 获取当前状态
|
||||
# 获取当前状态(返回第一个未完成的节点)
|
||||
current_state = get_business_object_current_state(business_object)
|
||||
|
||||
# 如果当前状态为 None,说明是初始状态(未开始)
|
||||
@@ -108,10 +112,7 @@ def advance_to_next_state(business_object: 'models.BusinessObject', user: 'User'
|
||||
)
|
||||
return True, f"已完成状态: {first_node.state.name}"
|
||||
|
||||
# 检查当前状态是否已完成(且未撤销)
|
||||
if business_object.state_logs.filter(state=current_state, is_cancelled=False).exists():
|
||||
return False, f"当前状态 '{current_state.name}' 已完成"
|
||||
|
||||
# current_state 不为 None 时,它一定是未完成的节点
|
||||
# 标记当前状态为已完成
|
||||
models.StateFlowRecord.objects.create(
|
||||
business_object=business_object,
|
||||
@@ -128,12 +129,12 @@ def advance_to_next_state(business_object: 'models.BusinessObject', user: 'User'
|
||||
return True, f"已完成状态: {current_state.name}"
|
||||
|
||||
|
||||
def reset_order_progress(business_object: 'models.BusinessObject') -> None:
|
||||
def reset_business_object_progress(business_object: 'models.BusinessObject') -> None:
|
||||
"""
|
||||
重置订单进度
|
||||
重置业务对象进度
|
||||
|
||||
注意:不删除历史记录,而是标记所有记录为已撤销,并记录撤销时间
|
||||
这样可以保留完整的操作历史
|
||||
这样可以保留完整的操作历史,支持审计需求
|
||||
"""
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -143,6 +144,10 @@ def reset_order_progress(business_object: 'models.BusinessObject') -> None:
|
||||
)
|
||||
|
||||
|
||||
# 向后兼容的别名
|
||||
reset_order_progress = reset_business_object_progress
|
||||
|
||||
|
||||
def get_current_state_parameters(business_object: 'models.BusinessObject') -> List['models.StateParameter']:
|
||||
"""获取订单当前状态的参数列表"""
|
||||
current_state = get_business_object_current_state(business_object)
|
||||
@@ -188,10 +193,10 @@ def can_advance_to_next_state(business_object: 'models.BusinessObject') -> Tuple
|
||||
|
||||
current_state = get_business_object_current_state(business_object)
|
||||
|
||||
# 如果当前状态为 None
|
||||
# 如果当前状态为 None,有两种情况:
|
||||
# 1. 没有完成记录 - 未开始
|
||||
# 2. 所有节点已完成 - 已完成
|
||||
if current_state is None:
|
||||
# 检查是否所有状态都已完成
|
||||
total_nodes = business_object.process.process_nodes.count()
|
||||
completed_count = business_object.state_logs.filter(is_cancelled=False).count()
|
||||
|
||||
if completed_count == 0:
|
||||
@@ -201,10 +206,7 @@ def can_advance_to_next_state(business_object: 'models.BusinessObject') -> Tuple
|
||||
# 所有状态都已完成
|
||||
return False, "流程已完成,无法继续推进"
|
||||
|
||||
# 检查当前状态是否已完成
|
||||
if business_object.state_logs.filter(state=current_state, is_cancelled=False).exists():
|
||||
return False, f"当前状态 '{current_state.name}' 已完成,无法重复完成"
|
||||
|
||||
# current_state 不为 None 时,它一定是第一个未完成的节点,可以推进
|
||||
return True, f"可以推进到: {current_state.name}"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user