1
0
forked from erp-dev/erp

fix: process id change when plate_order and printing_order update

This commit is contained in:
2026-01-15 16:35:46 +08:00
parent 9a367caab7
commit ea9f378de9
9 changed files with 384 additions and 8 deletions

View File

@@ -70,10 +70,40 @@ class PrintingOrderService:
Returns:
(success, message, updated_order)
"""
# 如果要修改 process需要验证
# 如果要修改 process需要验证并同步 relink 所有 jobs 的 BusinessObject
if 'process' in data and data['process'] != printing_order.process:
new_process = data.get('process')
if new_process is None:
return False, '流程不能为空,无法修改流程', printing_order
# 只要存在任意 job 已开始(有未撤销进度)则拒绝
if not printing_order.can_change_process():
return False, '存在已开始的印染任务,无法修改流程', printing_order
from stateflow.services import relink_business_object_for_instance
try:
with transaction.atomic():
# relink 所有 jobsjobs 未开始,允许重建并重新绑定 BO
for job in printing_order.printing_jobs.select_related('business_object').all():
relinked = relink_business_object_for_instance(
instance=job,
new_process=new_process,
default_name=f"PrintingJob-{job.pk}",
default_description=f"印染任务 {job.pk} 的流程实例",
)
if relinked is None:
raise RuntimeError(f'印染任务 {job.pk} 已存在有效进度,无法修改流程')
# 最后更新订单流程
printing_order.process = new_process
printing_order.save(update_fields=['process'])
except RuntimeError as e:
return False, str(e), printing_order
# process 已处理完毕,避免后续通用字段更新再次覆盖
data = {k: v for k, v in data.items() if k != 'process'}
# 更新字段
for field, value in data.items():