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")
|
||||
count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0
|
||||
self.count_pn_jgqbl = count_pn_jgqbl
|
||||
self.count_real = self.count_use - self.count_pn_jgqbl
|
||||
self.save(update_fields=["count_pn_jgqbl", "count_real"])
|
||||
self.save(update_fields=["count_pn_jgqbl"])
|
||||
mlog = self.mlog
|
||||
if mlog:
|
||||
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('不可提交未来的日志')
|
||||
|
||||
mgroup = mlog.mgroup
|
||||
process = mgroup.process
|
||||
into_wm_mgroup = process.into_wm_mgroup
|
||||
need_store_notok = process.store_notok
|
||||
belong_dept = mgroup.belong_dept
|
||||
material_out: Material = mlog.material_out
|
||||
material_in: Material = mlog.material_in
|
||||
supplier = mlog.supplier # 外协
|
||||
is_fix = mlog.is_fix
|
||||
m_ins_list = []
|
||||
m_ins_bl_list = []
|
||||
if material_in or is_fix: # 需要进行车间库存管理
|
||||
m_ins_list = []
|
||||
m_ins_bl_list = []
|
||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||
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:
|
||||
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
||||
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)
|
||||
|
||||
# 针对加工前不良的暂时额外处理
|
||||
for item in m_ins_bl_list:
|
||||
material, batch, count, defect, mi_ = item
|
||||
if count> 0:
|
||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
||||
wm.count = wm.count + count
|
||||
if is_create:
|
||||
wm.create_by = user
|
||||
wm.batch_ofrom = mi_.batch_ofrom
|
||||
wm.material_ofrom = mi_.material_ofrom
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
||||
if need_store_notok:
|
||||
for item in m_ins_bl_list:
|
||||
material, batch, count, defect, mi_ = item
|
||||
if count> 0:
|
||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
||||
wm.count = wm.count + count
|
||||
if is_create:
|
||||
wm.create_by = user
|
||||
wm.batch_ofrom = mi_.batch_ofrom
|
||||
wm.material_ofrom = mi_.material_ofrom
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
||||
|
||||
|
||||
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)
|
||||
stored_notok = 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)
|
||||
if m_ins.exists():
|
||||
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:
|
||||
mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item)
|
||||
for itemx in mbd_qs:
|
||||
|
@ -502,21 +503,22 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
item.save()
|
||||
|
||||
# 针对加工前不良的暂时额外处理
|
||||
for item in m_ins_bl_list:
|
||||
material, batch, count, defect, mi_ = item
|
||||
if count> 0:
|
||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': 'jgqbl', 'state': WMaterial.WM_NOTOK}
|
||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
||||
wm.count = wm.count - count
|
||||
if wm.count < 0:
|
||||
raise ParseError('加工前不良数量大于库存量')
|
||||
if is_create:
|
||||
wm.create_by = user
|
||||
else:
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
raise ParseError("加工前不良的物料暂不支持单件回退")
|
||||
if stored_notok:
|
||||
for item in m_ins_bl_list:
|
||||
material, batch, count, defect, mi_ = item
|
||||
if count> 0:
|
||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': 'jgqbl', 'state': WMaterial.WM_NOTOK}
|
||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
||||
wm.count = wm.count - count
|
||||
if wm.count < 0:
|
||||
raise ParseError('加工前不良数量大于库存量')
|
||||
if is_create:
|
||||
wm.create_by = user
|
||||
else:
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||
raise ParseError("加工前不良的物料暂不支持单件回退")
|
||||
|
||||
mlog.submit_time = None
|
||||
mlog.submit_user = None
|
||||
|
|
Loading…
Reference in New Issue