fix: handoverb支持编辑

This commit is contained in:
caoqianming 2024-09-05 17:02:06 +08:00
parent ee7b7a526c
commit 789ffe53d3
1 changed files with 18 additions and 7 deletions

View File

@ -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,19 +638,26 @@ 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:
model = Handover