From 6584334d00d9f2ababd41976bab1e7c4c60fe759 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 11 Dec 2025 16:56:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=89=A9=E6=96=99=E7=9A=84=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mtm/serializers.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/mtm/serializers.py b/apps/mtm/serializers.py index f7ccf8d8..74eed38b 100644 --- a/apps/mtm/serializers.py +++ b/apps/mtm/serializers.py @@ -211,7 +211,23 @@ class RouteSerializer(CustomModelSerializer): """ material = instance.material process = instance.process - material_out: Material = Material.objects.get_queryset(all=True).filter(type=Material.MA_TYPE_HALFGOOD, parent=material, process=process).first() + + material_out = Material.objects.get_queryset(all=True).filter(name=material.name, + model=material.model, process=process, + specification=material.specification).order_by("type", "-is_hidden", "create_time").first() + if material_out: + material_out.is_deleted = False + if material_out.parent is None: + if material_out.id != material.id: + material_out.parent = material + material_out.cate = material.cate + material_out.tracking = material_out_tracking + material_out.save() + return material_out + + material_out: Material = Material.objects.get_queryset(all=True).filter( + type__in=[Material.MA_TYPE_HALFGOOD, Material.MA_TYPE_GOOD], + parent=material, process=process).order_by("type", "-is_hidden", "create_time").first() if material_out: material_out.is_deleted = False if material_out.parent == material: @@ -222,16 +238,6 @@ class RouteSerializer(CustomModelSerializer): material_out.tracking = material_out_tracking material_out.save() return material_out - material_out = Material.objects.get_queryset(all=True).filter(name=material.name, model=material.model, process=process, specification=material.specification).first() - if material_out: - material_out.is_deleted = False - if material_out.parent is None: - if material_out.id != material.id: - material_out.parent = material - material_out.cate = material.cate - material_out.tracking = material_out_tracking - material_out.save() - return material_out material_out = Material.objects.create(**{'parent': instance.material, 'process': instance.process, 'is_hidden': True, 'name': material.name, 'number': material.number,