feat: 触发批次分析统计

This commit is contained in:
caoqianming 2024-12-03 18:07:23 +08:00
parent 67be714355
commit b93c4bddeb
4 changed files with 64 additions and 13 deletions

View File

@ -5,6 +5,7 @@ from apps.utils.tools import ranstr
from apps.utils.thread import MyThread from apps.utils.thread import MyThread
from apps.mtm.services import cal_material_count from apps.mtm.services import cal_material_count
from apps.wpm.models import WMaterial from apps.wpm.models import WMaterial
from apps.wpm.services_2 import get_alldata_with_batch_and_store
def do_out(item: MIOItem): def do_out(item: MIOItem):
""" """
@ -46,11 +47,12 @@ def do_out(item: MIOItem):
else: else:
mb.save() mb.save()
xbatches = []
for al in action_list: for al in action_list:
xmaterial:Material = al[0] xmaterial:Material = al[0]
xbatch:str = al[1] xbatch:str = al[1]
xcount:str = al[2] xcount:str = al[2]
xbatches.append(xbatch)
mb = None mb = None
if not is_zhj: if not is_zhj:
try: try:
@ -79,6 +81,12 @@ def do_out(item: MIOItem):
wm.update_by = do_user wm.update_by = do_user
wm.save() 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): def do_in(item: MIOItem):
""" """
@ -105,9 +113,11 @@ def do_in(item: MIOItem):
action_list = [[item.material, item.batch, item.count]] action_list = [[item.material, item.batch, item.count]]
production_dept = None production_dept = None
xbatchs = []
for al in action_list: for al in action_list:
xmaterial, xbatch, xcount = al xmaterial, xbatch, xcount = al
xbatchs.append(xbatch)
# 扣减车间库存 # 扣减车间库存
wm_qs = WMaterial.objects.filter( wm_qs = WMaterial.objects.filter(
batch=xbatch, batch=xbatch,
@ -165,7 +175,12 @@ def do_in(item: MIOItem):
raise ParseError("该批次组合件已存在") raise ParseError("该批次组合件已存在")
for mia in mias: for mia in mias:
MaterialBatchA.objects.create(mb=mb, material=mia.material, batch=mia.batch, rate=mia.rate) 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: class InmService:
@classmethod @classmethod

View File

@ -18,6 +18,8 @@ from apps.qm.filters import QuaStatFilter, TestItemFilter, FtestWorkFilter
from django.db import transaction from django.db import transaction
from apps.qm.models import NotOkOption from apps.qm.models import NotOkOption
from apps.qm.services import ftestwork_submit 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. # Create your views here.
class NotOkOptionView(APIView): class NotOkOptionView(APIView):
@ -144,13 +146,28 @@ class FtestWorkViewSet(CustomModelViewSet):
ins:FtestWork = self.get_object() ins:FtestWork = self.get_object()
if ins.submit_time is not None: if ins.submit_time is not None:
raise ParseError('已提交无法修改') 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): def destroy(self, request, *args, **kwargs):
ins:FtestWork = self.get_object() ins:FtestWork = self.get_object()
if ins.submit_time is not None: if ins.submit_time is not None:
raise ParseError('已提交无法删除') 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) @action(methods=['post'], detail=True, perms_map={'post': 'ftestwork.submit'}, serializer_class=Serializer)
@transaction.atomic @transaction.atomic

View File

@ -16,6 +16,7 @@ from apps.mtm.services import cal_material_count
from apps.wf.models import Ticket from apps.wf.models import Ticket
from apps.utils.thread import MyThread from apps.utils.thread import MyThread
import logging import logging
from apps.wpm.services_2 import get_alldata_with_batch_and_store
myLogger = logging.getLogger('log') myLogger = logging.getLogger('log')
def generate_new_batch(old_batch: str, mlog: Mlog): 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.stored_mgroup = stored_mgroup
mlog.save() 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]): 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: if update_mtaskIds:
Mtask.objects.filter(id__in=update_mtaskIds, state=Mtask.MTASK_SUBMIT).update(state=Mtask.MTASK_ASSGINED) 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): 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_mgroup = handover.recive_mgroup
recive_dept = handover.recive_dept recive_dept = handover.recive_dept
batches = []
for item in handoverb_list: for item in handoverb_list:
wm_from, xcount = item wm_from, xcount = item
batch = wm_from.batch batch = wm_from.batch
if wm_from is None: if wm_from is None:
raise ParseError('找不到车间库存') raise ParseError('找不到车间库存')
batches.append(batch)
count_x = wm_from.count - xcount count_x = wm_from.count - xcount
if count_x < 0: if count_x < 0:
@ -631,6 +643,11 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
handover.submit_time = now handover.submit_time = now
handover.save() 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): def mlog_submit_validate(ins: Mlog):
if ins.submit_time: if ins.submit_time:
raise ParseError('该日志已提交!') raise ParseError('该日志已提交!')

View File

@ -5,18 +5,20 @@ from apps.inm.models import MIOItem
from apps.qm.models import FtestWork from apps.qm.models import FtestWork
from django.utils import timezone from django.utils import timezone
from datetime import datetime from datetime import datetime
from server.conf import BASE_PROJECT_CODE
def get_alldata_with_batch_and_store(batch: str): def get_alldata_with_batch_and_store(batch: str):
""" """
获取某个批次某个仓库的整体生产数据并保存 获取某个批次的整体生产数据并保存
""" """
last_time, data = get_alldata_with_batch(batch) if BASE_PROJECT_CODE == "gzerp":
bobj, _ = BatchSt.objects.get_or_create(batch=batch, defaults={ last_time, data = get_alldata_with_batch(batch)
"last_time": last_time bobj, _ = BatchSt.objects.get_or_create(batch=batch, defaults={
}) "last_time": last_time
bobj.last_time = last_time })
bobj.data = data bobj.last_time = last_time
bobj.save() bobj.data = data
bobj.save()
def get_alldata_with_batch(batch: str): def get_alldata_with_batch(batch: str):
""" """