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.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

View File

@ -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

View File

@ -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('该日志已提交!')

View File

@ -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):
"""