feat: handoverbw的处理2

This commit is contained in:
caoqianming 2025-01-06 11:34:03 +08:00
parent 26c7652095
commit 49d1b95968
2 changed files with 17 additions and 7 deletions

View File

@ -645,6 +645,7 @@ class Handoverbwserializer(CustomModelSerializer):
model = Handoverbw model = Handoverbw
fields = '__all__' fields = '__all__'
read_only_fields = EXCLUDE_FIELDS_BASE + ["handoverb"] read_only_fields = EXCLUDE_FIELDS_BASE + ["handoverb"]
extra_kwargs = {'wpr': {'required': True}}
class HandoverbSerializer(CustomModelSerializer): class HandoverbSerializer(CustomModelSerializer):
batch = serializers.CharField(source='wm.batch', read_only=True) batch = serializers.CharField(source='wm.batch', read_only=True)
@ -776,7 +777,8 @@ class HandoverSerializer(CustomModelSerializer):
if count == wm.count: if count == wm.count:
Handoverbw.objects.filter(handoverb=hb).delete() Handoverbw.objects.filter(handoverb=hb).delete()
for item in Wpr.get_qs_by_wm(wm): for item in Wpr.get_qs_by_wm(wm):
Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb) Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb,
defaults={"number": item.number})
elif handoverbw: elif handoverbw:
raise ParseError("暂不支持") raise ParseError("暂不支持")
else: else:

View File

@ -11,7 +11,7 @@ from apps.system.models import User
from apps.pm.models import Mtask from apps.pm.models import Mtask
from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Srule from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Srule
from .models import SfLog, WMaterial, Mlog, Mlogb, Mlogbw, Handover, Handoverb from .models import SfLog, WMaterial, Mlog, Mlogb, Mlogbw, Handover, Handoverb, Handoverbw
from apps.mtm.services import cal_material_count from apps.mtm.services import cal_material_count
from apps.wf.models import Ticket from apps.wf.models import Ticket
from apps.utils.thread import MyThread from apps.utils.thread import MyThread
@ -575,23 +575,23 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
now = timezone.now() now = timezone.now()
handoverb_qs = Handoverb.objects.filter(handover=handover) handoverb_qs = Handoverb.objects.filter(handover=handover)
need_add = True need_add = True
material = handover.material material:Material = handover.material
if '混料' in material.name: # hard code if '混料' in material.name: # hard code
need_add = False need_add = False
if handoverb_qs.exists(): if handoverb_qs.exists():
handoverb_list = [(item.wm, item.count) for item in handoverb_qs] handoverb_list = [(item.wm, item.count, item) for item in handoverb_qs]
else: else:
handoverb_list = [(handover.wm, handover.count)] handoverb_list = [(handover.wm, handover.count, handover)]
recive_mgroup = handover.recive_mgroup recive_mgroup = handover.recive_mgroup
recive_dept = handover.recive_dept recive_dept = handover.recive_dept
batches = [] batches = []
for item in handoverb_list: for item in handoverb_list:
wm_from, xcount = item wm_from, xcount, handover_or_b = item
batch = wm_from.batch batch = wm_from.batch
if wm_from is None: if wm_from is None:
raise ParseError('找不到车间库存') raise ParseError('找不到车间库存')
batches.append(batch) batches.append(batch)
count_x = wm_from.count - xcount count_x = wm_from.count - xcount
@ -600,6 +600,7 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
else: else:
wm_from.count = count_x wm_from.count = count_x
wm_from.save() wm_from.save()
if need_add: if need_add:
# 开始变动 # 开始变动
if handover.type == Handover.H_NORMAL: if handover.type == Handover.H_NORMAL:
@ -670,6 +671,13 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
wm_to.count = wm_to.count + xcount wm_to.count = wm_to.count + xcount
wm_to.count_eweight = handover.count_eweight # 这行代码有隐患 wm_to.count_eweight = handover.count_eweight # 这行代码有隐患
wm_to.save() wm_to.save()
if material.tracking == Material.MA_TRACKING_SINGLE:
handoverbws = Handoverbw.objects.filter(handoverb=handover_or_b)
if handoverbws.count() != xcount:
raise ParseError("交接与明细数量不一致,操作失败")
for item in handoverbws:
Wpr.change_or_new(wpr=item.wpr, wm=wm_to)
handover.submit_user = user handover.submit_user = user
handover.submit_time = now handover.submit_time = now
handover.save() handover.save()