From 40b012b9625def5efe7218cf1135f3b2e019894e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 2 Sep 2024 15:27:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=B7=A5=E5=89=8D=E4=B8=8D?= =?UTF-8?q?=E8=89=AF=E7=9A=84=E6=97=A5=E5=BF=97=E6=8F=90=E4=BA=A4=E5=92=8C?= =?UTF-8?q?=E6=92=A4=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/services.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 0d31384f..d8f9ada3 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -208,7 +208,12 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): if material_in: # 需要进行车间库存管理 m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False) if m_ins.exists(): - m_ins_list = [(mi.material_in, mi.batch, mi.count_use, mi.wm_in) for mi in m_ins.all()] + m_ins_list = [] + m_ins_bl_list = [] + for mi in m_ins.all(): + m_ins_list.append((mi.material_in, mi.batch, mi.count_use, mi.wm_in)) + if mi.count_n_jgqbl > 0: + m_ins_bl_list.append((mi.material_in, mi.batch, mi.count_n_jgqbl)) else: m_ins_list = [(material_in, mlog.batch, mlog.count_use, mlog.wm_in)] for mi in m_ins_list: @@ -239,6 +244,20 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): wm.count = wm.count - mi_count wm.update_by = user wm.save() + # 针对加工前不良的暂时额外处理 + for item in m_ins_bl_list: + material, batch, count_n_jgqbl = item + if count_n_jgqbl> 0: + lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'notok_sign': 'jgqbl', 'state': WMaterial.WM_NOTOK} + wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept}) + wm.count = wm.count + item.count_n_jgqbl + if is_create: + wm.create_by = user + else: + wm.update_by = user + wm.save() + + if material_out: # 需要入车间库存 into_wm_mgroup = material_out.process.into_wm_mgroup if material_out.process else False need_store_notok = material_out.process.store_notok if material_out.process else False @@ -302,7 +321,12 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): into_wm_mgroup = material_in.process.into_wm_mgroup if material_in.process else False m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False) if m_ins.exists(): - m_ins_list = [(mi.material_in, mi.batch, mi.count_use, mi.wm_in) for mi in m_ins.all()] + m_ins_list = [] + m_ins_bl_list = [] + for mi in m_ins.all(): + m_ins_list.append((mi.material_in, mi.batch, mi.count_use, mi.wm_in)) + if mi.count_n_jgqbl > 0: + m_ins_bl_list.append((mi.material_in, mi.batch, mi.count_n_jgqbl)) else: m_ins_list = [(material_in, mlog.batch, mlog.count_use, mlog.wm_in)] for mi in m_ins_list: @@ -324,6 +348,21 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): wm.count = wm.count + mi_count wm.update_by = user wm.save() + # 针对加工前不良的暂时额外处理 + for item in m_ins_bl_list: + material, batch, count_n_jgqbl = item + if count_n_jgqbl> 0: + lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'notok_sign': 'jgqbl', 'state': WMaterial.WM_NOTOK} + wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept}) + wm.count = wm.count - item.count_n_jgqbl + if wm.count < 0: + raise ParseError('加工前不良数量大于库存量') + if is_create: + wm.create_by = user + else: + wm.update_by = user + wm.save() + if material_out: # 产物退回 # 有多个产物的情况 # 需要考虑不合格品退回的情况