From c1d5ef86f11465e2434918ed573e010ca2d378f8 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 4 Mar 2024 14:58:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20correct=5Ftuihuo=5Flog=E7=9F=AB=E6=AD=A3?= =?UTF-8?q?=E9=80=80=E7=81=AB=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/correct.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 apps/wpm/correct.py diff --git a/apps/wpm/correct.py b/apps/wpm/correct.py new file mode 100644 index 00000000..c76efdc5 --- /dev/null +++ b/apps/wpm/correct.py @@ -0,0 +1,26 @@ +from apps.wpm.models import Mlog, WMaterial +from django.db import transaction + + +def correct_tuihuo_log(): + """ + 矫正退火错误日志数据 + """ + mlogs = Mlog.objects.filter(mgroup__name='管料退火', count_use=0) + for mlog in mlogs: + try: + with transaction.atomic(): + count_use = mlog.count_ok + mlog.count_notok + material_has = WMaterial.objects.get( + batch=mlog.batch, material=mlog.material_in, belong_dept=mlog.mgroup.belong_dept) + material_has.count = material_has.count - count_use + if material_has.count >= 0: + if material_has.count == 0: + material_has.delete() + else: + material_has.save() + mlog.count_real = count_use + mlog.count_use = count_use + print(f'{mlog.id}-矫正成功') + except Exception as e: + print(f'{mlog.id}-矫正出错:{e}')