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

@@ -475,6 +475,12 @@ class PrintingJobCreateUpdateSerializer(serializers.ModelSerializer):
def update(self, instance, validated_data):
"""更新任务,使用 service 层"""
# 不允许修改 printing_order 绑定关系(避免业务对象流程不一致)
if 'printing_order' in validated_data:
new_order = validated_data.get('printing_order')
if new_order and new_order.id != getattr(instance, 'printing_order_id', None):
raise serializers.ValidationError({'printing_order': '不允许修改印染订单绑定关系'})
user = self.context['request'].user
success, message, updated_instance = PrintingJobService.update_printing_job(
instance, validated_data, user
@@ -772,6 +778,27 @@ class PlateOrderCreateUpdateSerializer(serializers.ModelSerializer):
return super().create(validated_data)
def update(self, instance, validated_data):
# 若更新涉及 process 变更,需要重建并重新绑定 BusinessObject若有未撤销进度则拒绝
new_process_id = validated_data.get('process', None)
if new_process_id is not None and new_process_id != getattr(instance, 'process', None):
from stateflow.models import Process
from stateflow.services import relink_business_object_for_instance
try:
new_process = Process.objects.get(id=new_process_id)
except Process.DoesNotExist:
# 理论上 validate_process 已校验;这里兜底
raise serializers.ValidationError({'process': '流程不存在'})
relinked = relink_business_object_for_instance(
instance=instance,
new_process=new_process,
default_name=f"PlateOrder-{instance.pk}",
default_description=f"开版订单 {instance.pk} 的流程实例",
)
if relinked is None:
raise serializers.ValidationError({'process': '该订单流程已存在有效进度,无法修改流程'})
plate_images = validated_data.pop('plate_image', None)
if plate_images is not None:
validated_data['plate_image'] = _build_plate_image_payload(plate_images, self._request_user)