feat: handoverbw的处理

This commit is contained in:
caoqianming 2025-01-06 11:02:08 +08:00
parent fc56ecea08
commit 26c7652095
1 changed files with 28 additions and 4 deletions

View File

@ -20,6 +20,7 @@ from django.core.cache import cache
from django.utils.timezone import localdate
from apps.qm.models import NotOkOption
from apps.wf.serializers import TicketSimpleSerializer
from apps.wpmw.models import Wpr
import logging
mylogger = logging.getLogger("log")
@ -648,7 +649,7 @@ class Handoverbwserializer(CustomModelSerializer):
class HandoverbSerializer(CustomModelSerializer):
batch = serializers.CharField(source='wm.batch', 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:
model = Handoverb
fields = "__all__"
@ -744,7 +745,18 @@ class HandoverSerializer(CustomModelSerializer):
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"])
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
def update(self, instance, validated_data):
@ -753,10 +765,22 @@ class HandoverSerializer(CustomModelSerializer):
super().update(instance, validated_data)
wmIds = []
for item in handoverb:
wm = item["wm"]
count = item["count"]
handoverbw = item.pop("handoverbw", [])
wmIds.append(item["wm"].id)
hb, _ = Handoverb.objects.get_or_create(handover=instance, wm=item["wm"])
hb.count = item["count"]
hb, _ = Handoverb.objects.get_or_create(handover=instance, wm=wm)
hb.count = count
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()
return instance