feat: mlogbin时从单个拆分为多个批次
This commit is contained in:
parent
f295956c69
commit
85cc38c842
|
|
@ -686,6 +686,13 @@ class MlogbInSerializer(CustomModelSerializer):
|
||||||
raise ParseError('生产日志已提交不可编辑')
|
raise ParseError('生产日志已提交不可编辑')
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
ins:Mlogb = super().create(validated_data)
|
ins:Mlogb = super().create(validated_data)
|
||||||
|
if mlog.is_fix:
|
||||||
|
if mlog.material_in is None:
|
||||||
|
mlog.material_in = ins.material_in
|
||||||
|
mlog.save(update_fields="material_in")
|
||||||
|
elif mlog.material_in != ins.material_in:
|
||||||
|
raise ParseError('返修记录必须使用同一物料')
|
||||||
|
|
||||||
if mlogbdefect is not None and ins.material_in.tracking == Material.MA_TRACKING_BATCH:
|
if mlogbdefect is not None and ins.material_in.tracking == Material.MA_TRACKING_BATCH:
|
||||||
mlogb_defect_objects = [
|
mlogb_defect_objects = [
|
||||||
MlogbDefect(**{**item, "mlogb": ins, "id": idWorker.get_id()})
|
MlogbDefect(**{**item, "mlogb": ins, "id": idWorker.get_id()})
|
||||||
|
|
|
||||||
|
|
@ -565,8 +565,9 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
||||||
mlogbin: Mlogb = serializer.save()
|
mlogbin: Mlogb = serializer.save()
|
||||||
mlog:Mlog = mlogbin.mlog
|
mlog:Mlog = mlogbin.mlog
|
||||||
route:Route = mlog.route
|
route:Route = mlog.route
|
||||||
mgroup:Mgroup = mlog.mgroup
|
mtype = route.process.mtype if route else None
|
||||||
is_fix = mlog.is_fix
|
is_fix = mlog.is_fix
|
||||||
|
qct = mlog.qct
|
||||||
# 以及mlogbw
|
# 以及mlogbw
|
||||||
material_in:Material = mlogbin.material_in
|
material_in:Material = mlogbin.material_in
|
||||||
# 如果是返修,则输出和输入相同
|
# 如果是返修,则输出和输入相同
|
||||||
|
|
@ -583,58 +584,53 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
||||||
}
|
}
|
||||||
m_dict['batch'] = generate_new_batch(mlogbin.batch, mlog)
|
m_dict['batch'] = generate_new_batch(mlogbin.batch, mlog)
|
||||||
wm_in: WMaterial = mlogbin.wm_in
|
wm_in: WMaterial = mlogbin.wm_in
|
||||||
mlogbout, is_create = Mlogb.objects.get_or_create(**m_dict, defaults=
|
|
||||||
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom})
|
|
||||||
if is_create:
|
|
||||||
d_count_real = 0
|
|
||||||
d_count_ok = 0
|
|
||||||
if route:
|
|
||||||
if route.process.mtype == Process.PRO_NORMAL:
|
|
||||||
d_count_real = mlogbin.count_use
|
|
||||||
d_count_ok = mlogbin.count_use
|
|
||||||
elif route.process.mtype == Process.PRO_DIV:
|
|
||||||
xcount = mlogbin.count_use * route.div_number
|
|
||||||
d_count_real = xcount
|
|
||||||
d_count_ok = xcount
|
|
||||||
elif route.process.mtype == Process.PRO_MERGE:
|
|
||||||
xcount = math.floor( mlogbin.count_use / route.div_number)
|
|
||||||
d_count_real = xcount
|
|
||||||
d_count_ok = xcount
|
|
||||||
elif is_fix:
|
|
||||||
d_count_real = mlogbin.count_use
|
|
||||||
d_count_ok = mlogbin.count_use
|
|
||||||
# 找寻质检表
|
|
||||||
if is_fix and mgroup.process.type == Process.PRO_PROD:
|
|
||||||
# 如果是生产返修,则忽略质检
|
|
||||||
pass
|
|
||||||
elif mlogbout.qct is None:
|
|
||||||
mlogbout.qct = Qct.get(mlogbout.material_out, "process") if mlog.qct is None else mlog.qct
|
|
||||||
if mlogbout.qct is not None and mlog.qct is None:
|
|
||||||
mlog.qct = mlogbout.qct
|
|
||||||
mlog.save(update_fields=["qct"])
|
|
||||||
mlogbout.count_real = d_count_real
|
|
||||||
mlogbout.count_ok = d_count_ok
|
|
||||||
mlogbout.save()
|
|
||||||
mlogbin.mlogb_to = mlogbout
|
|
||||||
mlogbin.save()
|
|
||||||
if material_in.tracking == Material.MA_TRACKING_SINGLE:
|
if material_in.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
m_out_t = material_out.tracking
|
|
||||||
if mlogbin.count_use == wm_in.count: # 自动创建mlogbw
|
if mlogbin.count_use == wm_in.count: # 自动创建mlogbw
|
||||||
for wpr in Wpr.objects.filter(wm=wm_in).order_by("number"):
|
for wpr in Wpr.objects.filter(wm=wm_in).order_by("number"):
|
||||||
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbin, defaults={"number": wpr.number})
|
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbin, defaults={"number": wpr.number})
|
||||||
if m_out_t == Material.MA_TRACKING_SINGLE:
|
else:
|
||||||
if route:
|
raise ParseError("请提供消耗物料详细编号")
|
||||||
if route.process.mtype == Process.PRO_NORMAL:
|
|
||||||
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number})
|
if qct is None and not (is_fix and mtype == Process.PRO_PROD):
|
||||||
elif route.process.mtype == Process.PRO_DIV:
|
mlog.qct = Qct.get(material_out, "process")
|
||||||
for i in range(route.div_number):
|
mlog.save(update_fields = ["qct"])
|
||||||
Mlogbw.objects.get_or_create(mlogb=mlogbout, number=f'{wpr.number}-{i+1}')
|
|
||||||
else:
|
if mtype == Process.PRO_NORMAL:
|
||||||
raise ParseError("不支持的生产类型")
|
d_count_real = mlogbin.count_use
|
||||||
elif is_fix:
|
d_count_ok = mlogbin.count_use
|
||||||
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number})
|
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
|
||||||
else:
|
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok, "qct": qct})
|
||||||
raise ParseError("不支持的生产类型1")
|
elif mtype == Process.PRO_DIV:
|
||||||
|
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
|
||||||
|
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
|
||||||
|
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok, "qct": qct})
|
||||||
|
elif mtype == Process.PRO_MERGE:
|
||||||
|
xcount = math.floor( mlogbin.count_use / route.div_number)
|
||||||
|
d_count_real = xcount
|
||||||
|
d_count_ok = xcount
|
||||||
|
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
|
||||||
|
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok, "qct": qct})
|
||||||
|
elif is_fix:
|
||||||
|
d_count_real = mlogbin.count_use
|
||||||
|
d_count_ok = mlogbin.count_use
|
||||||
|
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
|
||||||
|
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok, "qct": qct})
|
||||||
|
else:
|
||||||
|
raise ParseError("不支持生成产出物料!")
|
||||||
|
|
||||||
|
if material_out.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
|
||||||
|
wpr = mlogbwin.wpr
|
||||||
|
if mtype == Process.PRO_NORMAL:
|
||||||
|
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number})
|
||||||
|
elif mtype == Process.PRO_DIV:
|
||||||
|
for i in range(route.div_number):
|
||||||
|
Mlogbw.objects.get_or_create(mlogb=mlogbout, number=f'{wpr.number}-{i+1}')
|
||||||
|
elif is_fix:
|
||||||
|
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number})
|
||||||
|
else:
|
||||||
|
raise ParseError("不支持的生产类型1")
|
||||||
|
|
||||||
|
|
||||||
class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
|
class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue