From b93c4bddeb7c4b4e677b451cb28f08b787c330b1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 3 Dec 2024 18:07:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=A6=E5=8F=91=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E5=88=86=E6=9E=90=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/inm/services.py | 21 ++++++++++++++++++--- apps/qm/views.py | 21 +++++++++++++++++++-- apps/wpm/services.py | 17 +++++++++++++++++ apps/wpm/services_2.py | 18 ++++++++++-------- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/apps/inm/services.py b/apps/inm/services.py index b22d3577..77d6c6fd 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -5,6 +5,7 @@ from apps.utils.tools import ranstr from apps.utils.thread import MyThread from apps.mtm.services import cal_material_count from apps.wpm.models import WMaterial +from apps.wpm.services_2 import get_alldata_with_batch_and_store def do_out(item: MIOItem): """ @@ -46,11 +47,12 @@ def do_out(item: MIOItem): else: mb.save() + xbatches = [] for al in action_list: xmaterial:Material = al[0] xbatch:str = al[1] xcount:str = al[2] - + xbatches.append(xbatch) mb = None if not is_zhj: try: @@ -79,6 +81,12 @@ def do_out(item: MIOItem): wm.update_by = do_user wm.save() + # 触发批次统计分析 + xbatches = list(set(xbatches)) + if xbatches: + for xbatch in xbatches: + MyThread(target=get_alldata_with_batch_and_store, args=(xbatch,)).start() + def do_in(item: MIOItem): """ @@ -105,9 +113,11 @@ def do_in(item: MIOItem): action_list = [[item.material, item.batch, item.count]] production_dept = None + + xbatchs = [] for al in action_list: xmaterial, xbatch, xcount = al - + xbatchs.append(xbatch) # 扣减车间库存 wm_qs = WMaterial.objects.filter( batch=xbatch, @@ -165,7 +175,12 @@ def do_in(item: MIOItem): raise ParseError("该批次组合件已存在") for mia in mias: MaterialBatchA.objects.create(mb=mb, material=mia.material, batch=mia.batch, rate=mia.rate) - + + # 批次统计分析 + xbatchs = list(set(xbatchs)) + for xbatch in xbatchs: + MyThread(target=get_alldata_with_batch_and_store, args=(xbatch,)).start() + class InmService: @classmethod diff --git a/apps/qm/views.py b/apps/qm/views.py index 23192ee3..89370725 100644 --- a/apps/qm/views.py +++ b/apps/qm/views.py @@ -18,6 +18,8 @@ from apps.qm.filters import QuaStatFilter, TestItemFilter, FtestWorkFilter from django.db import transaction from apps.qm.models import NotOkOption from apps.qm.services import ftestwork_submit +from apps.utils.thread import MyThread +from apps.wpm.services_2 import get_alldata_with_batch_and_store # Create your views here. class NotOkOptionView(APIView): @@ -144,13 +146,28 @@ class FtestWorkViewSet(CustomModelViewSet): ins:FtestWork = self.get_object() if ins.submit_time is not None: raise ParseError('已提交无法修改') - return super().update(request, *args, **kwargs) + x = super().update(request, *args, **kwargs) + # 触发批次统计分析 + if ins.batch: + MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start() + return x def destroy(self, request, *args, **kwargs): ins:FtestWork = self.get_object() if ins.submit_time is not None: raise ParseError('已提交无法删除') - return super().destroy(request, *args, **kwargs) + x = super().destroy(request, *args, **kwargs) + # 触发批次统计分析 + if ins.batch: + MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start() + return x + + def perform_create(self, serializer): + ins = serializer.save() + # 触发批次统计分析 + if ins.batch: + MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start() + @action(methods=['post'], detail=True, perms_map={'post': 'ftestwork.submit'}, serializer_class=Serializer) @transaction.atomic diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 4be872f7..9ee4da3f 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -16,6 +16,7 @@ from apps.mtm.services import cal_material_count from apps.wf.models import Ticket from apps.utils.thread import MyThread import logging +from apps.wpm.services_2 import get_alldata_with_batch_and_store myLogger = logging.getLogger('log') def generate_new_batch(old_batch: str, mlog: Mlog): @@ -288,6 +289,10 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): mlog.stored_mgroup = stored_mgroup mlog.save() + # 触发批次统计分析 + if mlog.batch: + MyThread(target=get_alldata_with_batch_and_store, args=(mlog.batch,)).start() + def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): """日志撤回 @@ -405,6 +410,10 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): if update_mtaskIds: Mtask.objects.filter(id__in=update_mtaskIds, state=Mtask.MTASK_SUBMIT).update(state=Mtask.MTASK_ASSGINED) + # 触发批次统计分析 + if mlog.batch: + MyThread(target=get_alldata_with_batch_and_store, args=(mlog.batch,)).start() + def cal_mlog_count_from_mlogb(mlog: Mlog): """ @@ -545,11 +554,14 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime recive_mgroup = handover.recive_mgroup recive_dept = handover.recive_dept + batches = [] for item in handoverb_list: wm_from, xcount = item batch = wm_from.batch if wm_from is None: raise ParseError('找不到车间库存') + + batches.append(batch) count_x = wm_from.count - xcount if count_x < 0: @@ -631,6 +643,11 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime handover.submit_time = now handover.save() + batches = list(set(batches)) + if batches: + for batch in batches: + MyThread(target=get_alldata_with_batch_and_store, args=(batch,)).start() + def mlog_submit_validate(ins: Mlog): if ins.submit_time: raise ParseError('该日志已提交!') diff --git a/apps/wpm/services_2.py b/apps/wpm/services_2.py index 1adbd10a..e3ad071c 100644 --- a/apps/wpm/services_2.py +++ b/apps/wpm/services_2.py @@ -5,18 +5,20 @@ from apps.inm.models import MIOItem from apps.qm.models import FtestWork from django.utils import timezone from datetime import datetime +from server.conf import BASE_PROJECT_CODE def get_alldata_with_batch_and_store(batch: str): """ - 获取某个批次某个仓库的整体生产数据并保存 + 获取某个批次的整体生产数据并保存 """ - last_time, data = get_alldata_with_batch(batch) - bobj, _ = BatchSt.objects.get_or_create(batch=batch, defaults={ - "last_time": last_time - }) - bobj.last_time = last_time - bobj.data = data - bobj.save() + if BASE_PROJECT_CODE == "gzerp": + last_time, data = get_alldata_with_batch(batch) + bobj, _ = BatchSt.objects.get_or_create(batch=batch, defaults={ + "last_time": last_time + }) + bobj.last_time = last_time + bobj.data = data + bobj.save() def get_alldata_with_batch(batch: str): """