feat: 针对加工前不良的处理2
This commit is contained in:
parent
330d44e2a3
commit
456f05a83e
|
|
@ -380,8 +380,7 @@ class Mlogb(BaseModel):
|
||||||
mqs = MlogbDefect.get_defect_qs_from_mlogb(self, ftype="in")
|
mqs = MlogbDefect.get_defect_qs_from_mlogb(self, ftype="in")
|
||||||
count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0
|
count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0
|
||||||
self.count_pn_jgqbl = count_pn_jgqbl
|
self.count_pn_jgqbl = count_pn_jgqbl
|
||||||
self.count_real = self.count_use - self.count_pn_jgqbl
|
self.save(update_fields=["count_pn_jgqbl"])
|
||||||
self.save(update_fields=["count_pn_jgqbl", "count_real"])
|
|
||||||
mlog = self.mlog
|
mlog = self.mlog
|
||||||
if mlog:
|
if mlog:
|
||||||
count_pn_jgqbl = MlogbDefect.get_defect_qs_from_mlog(mlog, ftype="in").aggregate(total=Sum("count"))["total"] or 0
|
count_pn_jgqbl = MlogbDefect.get_defect_qs_from_mlog(mlog, ftype="in").aggregate(total=Sum("count"))["total"] or 0
|
||||||
|
|
|
||||||
|
|
@ -156,18 +156,21 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
raise ParseError('不可提交未来的日志')
|
raise ParseError('不可提交未来的日志')
|
||||||
|
|
||||||
mgroup = mlog.mgroup
|
mgroup = mlog.mgroup
|
||||||
|
process = mgroup.process
|
||||||
|
into_wm_mgroup = process.into_wm_mgroup
|
||||||
|
need_store_notok = process.store_notok
|
||||||
belong_dept = mgroup.belong_dept
|
belong_dept = mgroup.belong_dept
|
||||||
material_out: Material = mlog.material_out
|
material_out: Material = mlog.material_out
|
||||||
material_in: Material = mlog.material_in
|
material_in: Material = mlog.material_in
|
||||||
supplier = mlog.supplier # 外协
|
supplier = mlog.supplier # 外协
|
||||||
is_fix = mlog.is_fix
|
is_fix = mlog.is_fix
|
||||||
m_ins_list = []
|
m_ins_list = []
|
||||||
|
m_ins_bl_list = []
|
||||||
if material_in or is_fix: # 需要进行车间库存管理
|
if material_in or is_fix: # 需要进行车间库存管理
|
||||||
m_ins_list = []
|
m_ins_list = []
|
||||||
m_ins_bl_list = []
|
|
||||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||||
if m_ins.exists():
|
if m_ins.exists():
|
||||||
m_ins_list = [(mi.material_in, mi.batch if mi.batch else mi.batch, mi.count_use-mi.count_pn_jgqbl, None, mi) for mi in m_ins.all()]
|
m_ins_list = [(mi.material_in, mi.batch if mi.batch else mi.batch, mi.count_use, None, mi) for mi in m_ins.all()]
|
||||||
for item in m_ins:
|
for item in m_ins:
|
||||||
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
||||||
for itemx in mbd_qs:
|
for itemx in mbd_qs:
|
||||||
|
|
@ -213,26 +216,24 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
Wpr.change_or_new(wpr=item.wpr, old_wm=wm)
|
Wpr.change_or_new(wpr=item.wpr, old_wm=wm)
|
||||||
|
|
||||||
# 针对加工前不良的暂时额外处理
|
# 针对加工前不良的暂时额外处理
|
||||||
for item in m_ins_bl_list:
|
if need_store_notok:
|
||||||
material, batch, count, defect, mi_ = item
|
for item in m_ins_bl_list:
|
||||||
if count> 0:
|
material, batch, count, defect, mi_ = item
|
||||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
if count> 0:
|
||||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
||||||
wm.count = wm.count + count
|
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
||||||
if is_create:
|
wm.count = wm.count + count
|
||||||
wm.create_by = user
|
if is_create:
|
||||||
wm.batch_ofrom = mi_.batch_ofrom
|
wm.create_by = user
|
||||||
wm.material_ofrom = mi_.material_ofrom
|
wm.batch_ofrom = mi_.batch_ofrom
|
||||||
wm.update_by = user
|
wm.material_ofrom = mi_.material_ofrom
|
||||||
wm.save()
|
wm.update_by = user
|
||||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
wm.save()
|
||||||
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
||||||
|
|
||||||
|
|
||||||
if material_out or is_fix: # 需要入车间库存
|
if material_out or is_fix: # 需要入车间库存
|
||||||
process = mgroup.process
|
|
||||||
into_wm_mgroup = process.into_wm_mgroup
|
|
||||||
need_store_notok = process.store_notok
|
|
||||||
mlogb_out_qs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
mlogb_out_qs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
stored_notok = need_store_notok
|
stored_notok = need_store_notok
|
||||||
stored_mgroup = need_store_notok
|
stored_mgroup = need_store_notok
|
||||||
|
|
@ -464,7 +465,7 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||||
if m_ins.exists():
|
if m_ins.exists():
|
||||||
for mi in m_ins.all():
|
for mi in m_ins.all():
|
||||||
m_ins_list.append((mi.material_in, mi.batch, mi.count_use-mi.count_pn_jgqbl, None, mi))
|
m_ins_list.append((mi.material_in, mi.batch, mi.count_use, None, mi))
|
||||||
for item in m_ins:
|
for item in m_ins:
|
||||||
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
||||||
for itemx in mbd_qs:
|
for itemx in mbd_qs:
|
||||||
|
|
@ -502,21 +503,22 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
item.save()
|
item.save()
|
||||||
|
|
||||||
# 针对加工前不良的暂时额外处理
|
# 针对加工前不良的暂时额外处理
|
||||||
for item in m_ins_bl_list:
|
if stored_notok:
|
||||||
material, batch, count, defect, mi_ = item
|
for item in m_ins_bl_list:
|
||||||
if count> 0:
|
material, batch, count, defect, mi_ = item
|
||||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': 'jgqbl', 'state': WMaterial.WM_NOTOK}
|
if count> 0:
|
||||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': 'jgqbl', 'state': WMaterial.WM_NOTOK}
|
||||||
wm.count = wm.count - count
|
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
||||||
if wm.count < 0:
|
wm.count = wm.count - count
|
||||||
raise ParseError('加工前不良数量大于库存量')
|
if wm.count < 0:
|
||||||
if is_create:
|
raise ParseError('加工前不良数量大于库存量')
|
||||||
wm.create_by = user
|
if is_create:
|
||||||
else:
|
wm.create_by = user
|
||||||
wm.update_by = user
|
else:
|
||||||
wm.save()
|
wm.update_by = user
|
||||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
wm.save()
|
||||||
raise ParseError("加工前不良的物料暂不支持单件回退")
|
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
raise ParseError("加工前不良的物料暂不支持单件回退")
|
||||||
|
|
||||||
mlog.submit_time = None
|
mlog.submit_time = None
|
||||||
mlog.submit_user = None
|
mlog.submit_user = None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue