fix: cal_material_count 挪到单独文件里
This commit is contained in:
parent
56d49b4d26
commit
b062d7ef6b
|
@ -5,7 +5,7 @@ from rest_framework.exceptions import ParseError
|
||||||
from apps.mtm.models import Material, Process
|
from apps.mtm.models import Material, Process
|
||||||
from apps.utils.tools import ranstr
|
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_2 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
|
from apps.wpm.services_2 import get_alldata_with_batch_and_store
|
||||||
from apps.wpmw.models import Wpr
|
from apps.wpmw.models import Wpr
|
||||||
|
|
|
@ -11,30 +11,6 @@ from typing import List
|
||||||
from apps.utils.snowflake import idWorker
|
from apps.utils.snowflake import idWorker
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
def cal_material_count(materialId_list: List[str]=None):
|
|
||||||
"""
|
|
||||||
计算物料总数量
|
|
||||||
"""
|
|
||||||
from apps.inm.models import MaterialBatch
|
|
||||||
from apps.wpm.models import WMaterial
|
|
||||||
if materialId_list is None:
|
|
||||||
materialId_list = []
|
|
||||||
if materialId_list:
|
|
||||||
objs = Material.objects.filter(id__in=set(materialId_list))
|
|
||||||
else:
|
|
||||||
objs = Material.objects.all()
|
|
||||||
for material in objs:
|
|
||||||
mb_count = MaterialBatch.objects.filter(material=material, state=10).aggregate(total=Sum("count"))["total"] or 0
|
|
||||||
wm_count = WMaterial.objects.filter(material=material, state=10).aggregate(total=Sum("count"))["total"] or 0
|
|
||||||
if mb_count is None:
|
|
||||||
mb_count = 0
|
|
||||||
if wm_count is None:
|
|
||||||
wm_count = 0
|
|
||||||
Material.objects.filter(id=material.id).update(
|
|
||||||
count_wm=wm_count,
|
|
||||||
count_mb=mb_count,
|
|
||||||
count=mb_count + wm_count)
|
|
||||||
|
|
||||||
def get_mgroup_goals(mgroupId, year, reload=False):
|
def get_mgroup_goals(mgroupId, year, reload=False):
|
||||||
"""
|
"""
|
||||||
获取工段某年的全部目标值, 以字典形式返回, 带缓存
|
获取工段某年的全部目标值, 以字典形式返回, 带缓存
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
from apps.mtm.models import Material
|
||||||
|
from typing import List
|
||||||
|
from django.db.models import Sum
|
||||||
|
from apps.inm.models import MaterialBatch
|
||||||
|
from apps.wpm.models import WMaterial
|
||||||
|
|
||||||
|
def cal_material_count(materialId_list: List[str]=None):
|
||||||
|
"""
|
||||||
|
计算物料总数量
|
||||||
|
"""
|
||||||
|
if materialId_list is None:
|
||||||
|
materialId_list = []
|
||||||
|
if materialId_list:
|
||||||
|
objs = Material.objects.filter(id__in=set(materialId_list))
|
||||||
|
else:
|
||||||
|
objs = Material.objects.all()
|
||||||
|
for material in objs:
|
||||||
|
mb_count = MaterialBatch.objects.filter(material=material, state=10).aggregate(total=Sum("count"))["total"] or 0
|
||||||
|
wm_count = WMaterial.objects.filter(material=material, state=10).aggregate(total=Sum("count"))["total"] or 0
|
||||||
|
if mb_count is None:
|
||||||
|
mb_count = 0
|
||||||
|
if wm_count is None:
|
||||||
|
wm_count = 0
|
||||||
|
Material.objects.filter(id=material.id).update(
|
||||||
|
count_wm=wm_count,
|
||||||
|
count_mb=mb_count,
|
||||||
|
count=mb_count + wm_count)
|
|
@ -12,7 +12,7 @@ from apps.pm.models import Mtask
|
||||||
from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Srule
|
from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Srule
|
||||||
|
|
||||||
from .models import SfLog, WMaterial, Mlog, Mlogb, Mlogbw, Handover, Handoverb, Handoverbw
|
from .models import SfLog, WMaterial, Mlog, Mlogb, Mlogbw, Handover, Handoverb, Handoverbw
|
||||||
from apps.mtm.services import cal_material_count
|
from apps.mtm.services_2 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
|
||||||
|
|
Loading…
Reference in New Issue