feat: 按个选入消耗时统计mlog数据优化
This commit is contained in:
parent
28acc48768
commit
45647d2149
|
@ -506,10 +506,10 @@ class Mlogbw(BaseModel):
|
||||||
if mlogb.material_in:
|
if mlogb.material_in:
|
||||||
mlogb.count_use = count
|
mlogb.count_use = count
|
||||||
mlogb.save(update_fields=["count_use"])
|
mlogb.save(update_fields=["count_use"])
|
||||||
mlogb.cal_count_notok(cal_mlog=True)
|
|
||||||
elif mlogb.material_out:
|
elif mlogb.material_out:
|
||||||
mlogb.count_real = count
|
mlogb.count_real = count
|
||||||
count_notok = 0
|
count_notok = 0
|
||||||
|
count_notok_full = 0
|
||||||
tqs = Mlogbw.objects.filter(mlogb=mlogb, ftest__is_ok=False)
|
tqs = Mlogbw.objects.filter(mlogb=mlogb, ftest__is_ok=False)
|
||||||
tqs_a = Mlogbw.objects.filter(mlogb=mlogb, ftest__is_ok=False).values("ftest__defect_main").annotate(xcount=Count('id'))
|
tqs_a = Mlogbw.objects.filter(mlogb=mlogb, ftest__is_ok=False).values("ftest__defect_main").annotate(xcount=Count('id'))
|
||||||
defects = {defect.id: defect for defect in Defect.objects.filter(id__in=tqs.values_list("ftest__defect_main", flat=True))}
|
defects = {defect.id: defect for defect in Defect.objects.filter(id__in=tqs.values_list("ftest__defect_main", flat=True))}
|
||||||
|
@ -520,11 +520,13 @@ class Mlogbw(BaseModel):
|
||||||
md.save()
|
md.save()
|
||||||
md_ids.append(md.id)
|
md_ids.append(md.id)
|
||||||
count_notok += t["xcount"]
|
count_notok += t["xcount"]
|
||||||
|
if defects[t["ftest__defect_main"]].okcate != 10:
|
||||||
|
count_notok_full += t["xcount"]
|
||||||
MlogbDefect.objects.filter(mlogb=mlogb).exclude(id__in=md_ids).delete()
|
MlogbDefect.objects.filter(mlogb=mlogb).exclude(id__in=md_ids).delete()
|
||||||
mlogb.count_notok = count_notok
|
mlogb.count_notok = count_notok
|
||||||
mlogb.count_ok = count - mlogb.count_notok
|
mlogb.count_ok = count - mlogb.count_notok
|
||||||
|
mlogb.count_ok_full = count - count_notok_full
|
||||||
mlogb.save()
|
mlogb.save()
|
||||||
mlogb.cal_count_notok(cal_mlog=True)
|
|
||||||
|
|
||||||
class Handover(CommonADModel):
|
class Handover(CommonADModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -808,12 +808,13 @@ class MlogbwViewSet(CustomModelViewSet):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
ins:Mlogbw = serializer.save()
|
ins:Mlogbw = serializer.save()
|
||||||
|
mlog = ins.mlogb.mlog
|
||||||
if isinstance(ins, list):
|
if isinstance(ins, list):
|
||||||
insx = ins
|
insx = ins
|
||||||
else:
|
else:
|
||||||
insx = [ins]
|
insx = [ins]
|
||||||
for ins in insx:
|
for ins in insx:
|
||||||
route:Route = ins.mlogb.mlog.route
|
route:Route = ins.mlogb.route
|
||||||
mlogb:Mlogb = ins.mlogb
|
mlogb:Mlogb = ins.mlogb
|
||||||
Mlogbw.cal_count_notok(mlogb)
|
Mlogbw.cal_count_notok(mlogb)
|
||||||
# 如果是输入且输出追踪到个,需同步创建
|
# 如果是输入且输出追踪到个,需同步创建
|
||||||
|
@ -859,11 +860,14 @@ class MlogbwViewSet(CustomModelViewSet):
|
||||||
for i in range(route.div_number):
|
for i in range(route.div_number):
|
||||||
Mlogbw.objects.get_or_create(mlogb=mlogb, number=f'{ins.number}-{i+1}', defaults={"mlogbw_from": ins})
|
Mlogbw.objects.get_or_create(mlogb=mlogb, number=f'{ins.number}-{i+1}', defaults={"mlogbw_from": ins})
|
||||||
Mlogbw.cal_count_notok(mlogb)
|
Mlogbw.cal_count_notok(mlogb)
|
||||||
|
mlog.cal_mlog_count_from_mlogb()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def perform_update(self, serializer):
|
def perform_update(self, serializer):
|
||||||
mlogbw = serializer.save()
|
mlogbw = serializer.save()
|
||||||
Mlogbw.cal_count_notok(mlogbw.mlogb)
|
Mlogbw.cal_count_notok(mlogbw.mlogb)
|
||||||
|
mlog = mlogbw.mlogb.mlog
|
||||||
|
mlog.cal_mlog_count_from_mlogb()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def perform_destroy(self, instance:Mlogbw):
|
def perform_destroy(self, instance:Mlogbw):
|
||||||
|
@ -891,6 +895,9 @@ class MlogbwViewSet(CustomModelViewSet):
|
||||||
mlogb_qs = Mlogb.objects.filter(id__in=mlogbIds)
|
mlogb_qs = Mlogb.objects.filter(id__in=mlogbIds)
|
||||||
for mlogb in mlogb_qs:
|
for mlogb in mlogb_qs:
|
||||||
Mlogbw.cal_count_notok(mlogb)
|
Mlogbw.cal_count_notok(mlogb)
|
||||||
|
|
||||||
|
mlog = mlogb.mlog
|
||||||
|
mlog.cal_mlog_count_from_mlogb()
|
||||||
|
|
||||||
class MlogUserViewSet(BulkCreateModelMixin, ListModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
class MlogUserViewSet(BulkCreateModelMixin, ListModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
||||||
perms_map = {"get": "*", "post": "mlog.update", "delete": "mlog.update"}
|
perms_map = {"get": "*", "post": "mlog.update", "delete": "mlog.update"}
|
||||||
|
|
Loading…
Reference in New Issue