1
0
forked from erp-dev/erp

feat: printing module

This commit is contained in:
2025-11-13 18:22:42 +08:00
parent 8097d6941c
commit f071e5fff9
35 changed files with 5537 additions and 440 deletions

View File

@@ -148,6 +148,37 @@ def reset_business_object_progress(business_object: 'models.BusinessObject') ->
reset_order_progress = reset_business_object_progress
def step_back_one_state(business_object: 'models.BusinessObject', user) -> Tuple[bool, str]:
"""
回退一步(撤销最后一次完成的状态)
这是 advance_to_next_state 的逆向操作
返回: (是否成功, 消息)
"""
from django.utils import timezone
with transaction.atomic():
# 获取最后一条有效的状态流转记录(按完成时间倒序)
last_record = (
business_object.state_logs
.filter(is_cancelled=False)
.order_by('-completed_at', '-id')
.first()
)
# 如果没有任何有效记录,说明当前没有任何状态流转,无需回退
if not last_record:
return False, "当前没有任何状态流转记录,无法回退"
# 标记最后一条记录为已撤销
last_record.is_cancelled = True
last_record.cancelled_at = timezone.now()
last_record.save(update_fields=['is_cancelled', 'cancelled_at'])
return True, f"已回退状态: {last_record.state.name}"
def get_current_state_parameters(business_object: 'models.BusinessObject') -> List['models.StateParameter']:
"""获取订单当前状态的参数列表"""
current_state = get_business_object_current_state(business_object)