fix: handoverb支持编辑
This commit is contained in:
parent
ee7b7a526c
commit
789ffe53d3
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue