fix: handoverb支持编辑
This commit is contained in:
parent
ee7b7a526c
commit
789ffe53d3
|
|
@ -580,7 +580,6 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
wm:WMaterial = attrs.get('wm', None)
|
wm:WMaterial = attrs.get('wm', None)
|
||||||
handoverb = attrs.get('handoverb', [])
|
handoverb = attrs.get('handoverb', [])
|
||||||
if wm:
|
if wm:
|
||||||
material = wm.material
|
|
||||||
attrs['handoverb'] = [{"wm": wm, "count": attrs["count"] }]
|
attrs['handoverb'] = [{"wm": wm, "count": attrs["count"] }]
|
||||||
handoverb = attrs['handoverb']
|
handoverb = attrs['handoverb']
|
||||||
elif handoverb:
|
elif handoverb:
|
||||||
|
|
@ -615,6 +614,11 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
attrs['recive_mgroup'] = attrs['send_mgroup']
|
attrs['recive_mgroup'] = attrs['send_mgroup']
|
||||||
attrs['recive_dept'] = attrs['send_dept']
|
attrs['recive_dept'] = attrs['send_dept']
|
||||||
attrs['recive_user'] = attrs['send_user']
|
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
|
return attrs
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -634,19 +638,26 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
}
|
}
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
type = validated_data['type']
|
|
||||||
handoverb = validated_data.pop('handoverb', [])
|
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():
|
with transaction.atomic():
|
||||||
ins = super().create(validated_data)
|
ins = super().create(validated_data)
|
||||||
for item in handoverb:
|
for item in handoverb:
|
||||||
Handoverb.objects.get_or_create(handover=ins, wm=item["wm"], count=item["count"])
|
Handoverb.objects.get_or_create(handover=ins, wm=item["wm"], count=item["count"])
|
||||||
return ins
|
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 HandoverUpdateSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Handover
|
model = Handover
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue