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