feat: mioitem处理事务处理
This commit is contained in:
parent
f151f4f2ec
commit
7a3988d6bd
|
@ -171,59 +171,59 @@ class MIOItemCreateSerializer(CustomModelSerializer):
|
|||
mis = MIOItem.objects.filter(batch=batch, material=material, mio__type__in=[MIO.MIO_TYPE_PUR_IN, MIO.MIO_TYPE_DO_IN, MIO.MIO_TYPE_OTHER_IN])
|
||||
if mis.exists() and (not mis.exclude(test_date=None).exists()):
|
||||
raise ParseError('该批次的物料未经检验')
|
||||
with transaction.atomic():
|
||||
count = validated_data["count"]
|
||||
batch = validated_data["batch"]
|
||||
mioitemw = validated_data.pop('mioitemw', [])
|
||||
instance:MIOItem = super().create(validated_data)
|
||||
assemb_dict = {}
|
||||
for i in assemb:
|
||||
assemb_dict[i['material'].id] = i
|
||||
if material.is_assemb and '_in' in mio.type: # 仅入库且是组合件的时候需要填写下一级
|
||||
components = material.components
|
||||
for k, v in components.items():
|
||||
if k in assemb_dict:
|
||||
mia = assemb_dict[k]
|
||||
MIOItemA.objects.create(
|
||||
mioitem=instance, rate=v, **mia)
|
||||
|
||||
count = validated_data["count"]
|
||||
batch = validated_data["batch"]
|
||||
mioitemw = validated_data.pop('mioitemw', [])
|
||||
instance:MIOItem = super().create(validated_data)
|
||||
assemb_dict = {}
|
||||
for i in assemb:
|
||||
assemb_dict[i['material'].id] = i
|
||||
if material.is_assemb and '_in' in mio.type: # 仅入库且是组合件的时候需要填写下一级
|
||||
components = material.components
|
||||
for k, v in components.items():
|
||||
if k in assemb_dict:
|
||||
mia = assemb_dict[k]
|
||||
MIOItemA.objects.create(
|
||||
mioitem=instance, rate=v, **mia)
|
||||
else:
|
||||
raise ParseError('缺少组合件')
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
if len(mioitemw) == 0:
|
||||
if mb:
|
||||
wpr_qs = Wpr.get_qs_by_mb(mb)
|
||||
if wpr_qs.count() == validated_data["count"]:
|
||||
for item in wpr_qs:
|
||||
MIOItemw.objects.create(mioitem=instance, number=item.number, wpr=item)
|
||||
else:
|
||||
raise ParseError('缺少组合件')
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
if len(mioitemw) == 0:
|
||||
if mb:
|
||||
wpr_qs = Wpr.get_qs_by_mb(mb)
|
||||
if wpr_qs.count() == validated_data["count"]:
|
||||
for item in wpr_qs:
|
||||
MIOItemw.objects.create(mioitem=instance, number=item.number, wpr=item)
|
||||
else:
|
||||
raise ParseError('请提供产品明细编号')
|
||||
elif wm:
|
||||
wpr_qs = Wpr.get_qs_by_wm(wm)
|
||||
if wpr_qs.count() == validated_data["count"]:
|
||||
for item in wpr_qs:
|
||||
MIOItemw.objects.create(mioitem=instance, number=item.number, wpr=item)
|
||||
else:
|
||||
raise ParseError('请提供产品明细编号')
|
||||
elif mio.type in [MIO.MIO_TYPE_PUR_IN, MIO.MIO_TYPE_OTHER_IN] and count==1:
|
||||
MIOItemw.objects.create(mioitem=instance, number=batch)
|
||||
raise ParseError('请提供产品明细编号')
|
||||
elif wm:
|
||||
wpr_qs = Wpr.get_qs_by_wm(wm)
|
||||
if wpr_qs.count() == validated_data["count"]:
|
||||
for item in wpr_qs:
|
||||
MIOItemw.objects.create(mioitem=instance, number=item.number, wpr=item)
|
||||
else:
|
||||
raise ParseError('不支持自动生成请提供产品明细')
|
||||
elif len(mioitemw) >= 1:
|
||||
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:
|
||||
if item.get("wpr", None) is None and mio_type != "pur_in" and mio_type != "other_in":
|
||||
raise ParseError(f'{item["number"]}_请提供产品明细ID')
|
||||
elif item.get("number_out", None) is not None and mio_type != MIO.MIO_TYPE_SALE_OUT:
|
||||
raise ParseError(f'{item["number"]}_非销售出库不可赋予产品对外编号')
|
||||
else:
|
||||
MIOItemw.objects.create(mioitem=instance, **item)
|
||||
raise ParseError('请提供产品明细编号')
|
||||
elif mio.type in [MIO.MIO_TYPE_PUR_IN, MIO.MIO_TYPE_OTHER_IN] and count==1:
|
||||
MIOItemw.objects.create(mioitem=instance, number=batch)
|
||||
else:
|
||||
raise ParseError('不支持自动生成请提供产品明细')
|
||||
elif len(mioitemw) >= 1:
|
||||
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:
|
||||
if item.get("wpr", None) is None and mio_type != "pur_in" and mio_type != "other_in":
|
||||
raise ParseError(f'{item["number"]}_请提供产品明细ID')
|
||||
elif item.get("number_out", None) is not None and mio_type != MIO.MIO_TYPE_SALE_OUT:
|
||||
raise ParseError(f'{item["number"]}_非销售出库不可赋予产品对外编号')
|
||||
else:
|
||||
MIOItemw.objects.create(mioitem=instance, **item)
|
||||
return instance
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue