diff --git a/apps/inm/correct.py b/apps/inm/correct.py index 4ff8fa9f..f65f5ae1 100644 --- a/apps/inm/correct.py +++ b/apps/inm/correct.py @@ -2,7 +2,7 @@ from .models import MaterialBatch, MIOItem from apps.mtm.models import Material, Mgroup from apps.system.models import Dept from rest_framework.exceptions import ParseError -from django.db.models import F +from django.db.models import F, Sum from django.db import transaction from .services import InmService @@ -37,10 +37,17 @@ def correct_mb_count_notok(): ) for mi in mis: count_notok = mi.count_n_zw + mi.count_n_tw + mi.count_n_qp + mi.count_n_wq + mi.count_n_dl + mi.count_n_pb + mi.count_n_dxt + mi.count_n_js + mi.count_n_qx + mi.count_n_zz + mi.count_n_ysq + mi.count_n_hs + mi.count_n_b + mi.count_n_qt - with transaction.atomic(): - MIOItem.objects.filter(id=mi.id).update(count_notok=count_notok) - # 先处理库存 - try: + # 先处理库存 + try: + with transaction.atomic(): + MIOItem.objects.filter(id=mi.id).update(count_notok=count_notok) InmService.update_mb_after_test() - except ParseError as e: - MIOItem.objects.filter(id=mi.id).update(test_date=None) \ No newline at end of file + except ParseError as e: + MIOItem.objects.filter(id=mi.id).update(test_date=None) + + +def correct_material_count(): + """ + 矫正现有物料总数量 + """ + res = MaterialBatch.objects.values('material').aggregate(total=Sum('count')) \ No newline at end of file