feat: handoverbw的处理
This commit is contained in:
parent
fc56ecea08
commit
26c7652095
|
|
@ -20,6 +20,7 @@ from django.core.cache import cache
|
||||||
from django.utils.timezone import localdate
|
from django.utils.timezone import localdate
|
||||||
from apps.qm.models import NotOkOption
|
from apps.qm.models import NotOkOption
|
||||||
from apps.wf.serializers import TicketSimpleSerializer
|
from apps.wf.serializers import TicketSimpleSerializer
|
||||||
|
from apps.wpmw.models import Wpr
|
||||||
import logging
|
import logging
|
||||||
mylogger = logging.getLogger("log")
|
mylogger = logging.getLogger("log")
|
||||||
|
|
||||||
|
|
@ -648,7 +649,7 @@ class Handoverbwserializer(CustomModelSerializer):
|
||||||
class HandoverbSerializer(CustomModelSerializer):
|
class HandoverbSerializer(CustomModelSerializer):
|
||||||
batch = serializers.CharField(source='wm.batch', read_only=True)
|
batch = serializers.CharField(source='wm.batch', read_only=True)
|
||||||
notok_sign = serializers.CharField(source='wm.notok_sign', read_only=True)
|
notok_sign = serializers.CharField(source='wm.notok_sign', read_only=True)
|
||||||
handoverb = Handoverbwserializer(many=True, required=False)
|
handoverbw = Handoverbwserializer(many=True, required=False)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Handoverb
|
model = Handoverb
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
@ -744,7 +745,18 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
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"])
|
wm = item["wm"]
|
||||||
|
count = item["count"]
|
||||||
|
handoverbw = item.pop("handoverbw", [])
|
||||||
|
handoverb, _ = Handoverb.objects.get_or_create(handover=ins, wm=wm, count=count)
|
||||||
|
if wm.material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
if count == wm.count:
|
||||||
|
for item in Wpr.get_qs_by_wm(wm):
|
||||||
|
Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb)
|
||||||
|
elif handoverbw:
|
||||||
|
raise ParseError("暂不支持")
|
||||||
|
else:
|
||||||
|
raise ParseError(f'请提供交接物料明细编号')
|
||||||
return ins
|
return ins
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
|
@ -753,10 +765,22 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
super().update(instance, validated_data)
|
super().update(instance, validated_data)
|
||||||
wmIds = []
|
wmIds = []
|
||||||
for item in handoverb:
|
for item in handoverb:
|
||||||
|
wm = item["wm"]
|
||||||
|
count = item["count"]
|
||||||
|
handoverbw = item.pop("handoverbw", [])
|
||||||
wmIds.append(item["wm"].id)
|
wmIds.append(item["wm"].id)
|
||||||
hb, _ = Handoverb.objects.get_or_create(handover=instance, wm=item["wm"])
|
hb, _ = Handoverb.objects.get_or_create(handover=instance, wm=wm)
|
||||||
hb.count = item["count"]
|
hb.count = count
|
||||||
hb.save()
|
hb.save()
|
||||||
|
if wm.material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
if count == wm.count:
|
||||||
|
Handoverbw.objects.filter(handoverb=hb).delete()
|
||||||
|
for item in Wpr.get_qs_by_wm(wm):
|
||||||
|
Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb)
|
||||||
|
elif handoverbw:
|
||||||
|
raise ParseError("暂不支持")
|
||||||
|
else:
|
||||||
|
raise ParseError(f'请提供交接物料明细编号')
|
||||||
Handoverb.objects.filter(handover=instance).exclude(wm__in=wmIds).delete()
|
Handoverb.objects.filter(handover=instance).exclude(wm__in=wmIds).delete()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue