feat: 出入库记录和交接记录提交处理时都进行单个的强校验
This commit is contained in:
parent
6b423c80eb
commit
d42bc29d2c
|
@ -175,7 +175,7 @@ class MIOItemCreateSerializer(CustomModelSerializer):
|
||||||
count = validated_data["count"]
|
count = validated_data["count"]
|
||||||
batch = validated_data["batch"]
|
batch = validated_data["batch"]
|
||||||
mioitemw = validated_data.pop('mioitemw', [])
|
mioitemw = validated_data.pop('mioitemw', [])
|
||||||
instance = super().create(validated_data)
|
instance:MIOItem = super().create(validated_data)
|
||||||
assemb_dict = {}
|
assemb_dict = {}
|
||||||
for i in assemb:
|
for i in assemb:
|
||||||
assemb_dict[i['material'].id] = i
|
assemb_dict[i['material'].id] = i
|
||||||
|
@ -210,6 +210,13 @@ class MIOItemCreateSerializer(CustomModelSerializer):
|
||||||
raise ParseError('不支持自动生成请提供产品明细')
|
raise ParseError('不支持自动生成请提供产品明细')
|
||||||
elif len(mioitemw) >= 1:
|
elif len(mioitemw) >= 1:
|
||||||
mio_type = mio.type
|
mio_type = mio.type
|
||||||
|
if mio_type != "pur_in" and mio_type != "other_in":
|
||||||
|
wprIds = [i["wpr"].id for i in mioitemw]
|
||||||
|
mb_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("mb__id", flat=True).distinct())
|
||||||
|
if len(mb_ids) == 1 and mb_ids[0] == instance.mb.id:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ParseError(f'{batch}物料明细中存在{len(mb_ids)}个不同物料批次')
|
||||||
for item in mioitemw:
|
for item in mioitemw:
|
||||||
if item.get("wpr", None) is None and mio_type != "pur_in" and mio_type != "other_in":
|
if item.get("wpr", None) is None and mio_type != "pur_in" and mio_type != "other_in":
|
||||||
raise ParseError(f'{item["number"]}_请提供产品明细ID')
|
raise ParseError(f'{item["number"]}_请提供产品明细ID')
|
||||||
|
|
|
@ -117,6 +117,12 @@ def do_out(item: MIOItem):
|
||||||
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
||||||
if mioitemws.count() != item.count:
|
if mioitemws.count() != item.count:
|
||||||
raise ParseError("出入库与明细数量不一致,操作失败")
|
raise ParseError("出入库与明细数量不一致,操作失败")
|
||||||
|
wprIds = [i["wpr"].id for i in mioitemws]
|
||||||
|
mb_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("mb__id", flat=True).distinct())
|
||||||
|
if len(mb_ids) == 1 and mb_ids[0] == mb.id:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ParseError(f'{xbatch}物料明细中存在{len(mb_ids)}个不同物料批次')
|
||||||
for mioitemw in mioitemws:
|
for mioitemw in mioitemws:
|
||||||
Wpr.change_or_new(wpr=mioitemw.wpr, wm=wm, old_mb=mb)
|
Wpr.change_or_new(wpr=mioitemw.wpr, wm=wm, old_mb=mb)
|
||||||
|
|
||||||
|
@ -229,6 +235,12 @@ def do_in(item: MIOItem):
|
||||||
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
||||||
if mioitemws.count() != item.count:
|
if mioitemws.count() != item.count:
|
||||||
raise ParseError("出入库与明细数量不一致,操作失败")
|
raise ParseError("出入库与明细数量不一致,操作失败")
|
||||||
|
wprIds = [i["wpr"].id for i in mioitemws]
|
||||||
|
wm_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("wm__id", flat=True).distinct())
|
||||||
|
if len(wm_ids) == 1 and wm_ids[0] == wm.id:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ParseError(f'{xbatch}物料明细中存在{len(wm_ids)}个不同物料批次')
|
||||||
for mioitemw in mioitemws:
|
for mioitemw in mioitemws:
|
||||||
Wpr.change_or_new(wpr=mioitemw.wpr, mb=mb, old_wm=wm)
|
Wpr.change_or_new(wpr=mioitemw.wpr, mb=mb, old_wm=wm)
|
||||||
|
|
||||||
|
|
|
@ -1280,7 +1280,7 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
if len(wm_ids) == 1 and wm_ids[0] == wm.id:
|
if len(wm_ids) == 1 and wm_ids[0] == wm.id:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise ParseError(f'第{ind+1}行-物料明细与批次不匹配')
|
raise ParseError(f'{wm.batch}物料明细中存在{len(wm_ids)}个不同物料批次')
|
||||||
|
|
||||||
elif wm.count == item["count"]:
|
elif wm.count == item["count"]:
|
||||||
t_count += item["count"]
|
t_count += item["count"]
|
||||||
|
|
|
@ -756,7 +756,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
raise ParseError('拆批请选择车间库存')
|
raise ParseError('拆批请选择车间库存')
|
||||||
batches_to_limit = BatchLog.batches_to(batch=handover.wm.batch)["batches"]
|
batches_to_limit = BatchLog.batches_to(batch=handover.wm.batch)["batches"]
|
||||||
source_b, _ = BatchSt.g_create(batch=handover.wm.batch)
|
source_b, _ = BatchSt.g_create(batch=handover.wm.batch)
|
||||||
for item in handoverb_list:
|
for indx, item in enumerate(handoverb_list):
|
||||||
wmId, xcount, handover_or_b = item
|
wmId, xcount, handover_or_b = item
|
||||||
if xcount <= 0:
|
if xcount <= 0:
|
||||||
raise ParseError("存在非正数!")
|
raise ParseError("存在非正数!")
|
||||||
|
@ -926,6 +926,12 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
handoverbws = Handoverbw.objects.filter(handoverb=handover_or_b)
|
handoverbws = Handoverbw.objects.filter(handoverb=handover_or_b)
|
||||||
if handoverbws.count() != xcount:
|
if handoverbws.count() != xcount:
|
||||||
raise ParseError("交接与明细数量不一致,操作失败")
|
raise ParseError("交接与明细数量不一致,操作失败")
|
||||||
|
wprIds = [i["wpr"].id for i in handoverbws]
|
||||||
|
wm_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("wm_id", flat=True).distinct())
|
||||||
|
if len(wm_ids) == 1 and wm_ids[0] == wm_from.id:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ParseError(f'{batch}物料明细中存在{len(wm_ids)}个不同物料批次')
|
||||||
for item in handoverbws:
|
for item in handoverbws:
|
||||||
wpr:Wpr = item.wpr
|
wpr:Wpr = item.wpr
|
||||||
Wpr.change_or_new(wpr=wpr, wm=wm_to, old_wm=wpr.wm, old_mb=wpr.mb)
|
Wpr.change_or_new(wpr=wpr, wm=wm_to, old_wm=wpr.wm, old_mb=wpr.mb)
|
||||||
|
|
Loading…
Reference in New Issue