From 789ffe53d34c880d73cf89af6c92c2f1a9df0c63 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 5 Sep 2024 17:02:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20handoverb=E6=94=AF=E6=8C=81=E7=BC=96?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 17144e96..6cd931a4 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -580,7 +580,6 @@ class HandoverSerializer(CustomModelSerializer): wm:WMaterial = attrs.get('wm', None) handoverb = attrs.get('handoverb', []) if wm: - material = wm.material attrs['handoverb'] = [{"wm": wm, "count": attrs["count"] }] handoverb = attrs['handoverb'] elif handoverb: @@ -615,6 +614,11 @@ class HandoverSerializer(CustomModelSerializer): attrs['recive_mgroup'] = attrs['send_mgroup'] attrs['recive_dept'] = attrs['send_dept'] attrs['recive_user'] = attrs['send_user'] + if attrs['type'] == Handover.H_REPAIR: + recive_mgroup = attrs.get("recive_mgroup", None) + if recive_mgroup is None: + raise ParseError('返工交接需指定工段') + attrs['material_changed'] = find_material_can_change(attrs['material'], recive_mgroup) return attrs class Meta: @@ -634,18 +638,25 @@ class HandoverSerializer(CustomModelSerializer): } def create(self, validated_data): - type = validated_data['type'] handoverb = validated_data.pop('handoverb', []) - if type == Handover.H_REPAIR: - recive_mgroup = validated_data.get("recive_mgroup", None) - if recive_mgroup is None: - raise ParseError('返工交接需指定工段') - validated_data['material_changed'] = find_material_can_change(validated_data['material'], recive_mgroup) with transaction.atomic(): ins = super().create(validated_data) for item in handoverb: Handoverb.objects.get_or_create(handover=ins, wm=item["wm"], count=item["count"]) return ins + + def update(self, instance, validated_data): + handoverb = validated_data.pop('handoverb', []) + with transaction.atomic(): + super().update(instance, validated_data) + wmIds = [] + for item in handoverb: + wmIds.append(item["wm"].id) + hb, _ = Handoverb.objects.get_or_create(handover=instance, wm=item["wm"]) + hb.count = item["count"] + hb.save() + Handoverb.objects.filter(handover=instance).exclude(wm__in=wmIds).delete() + return instance class HandoverUpdateSerializer(CustomModelSerializer): class Meta: