diff --git a/apps/inm/services.py b/apps/inm/services.py index f52d870f..7fc466d3 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -5,7 +5,7 @@ from rest_framework.exceptions import ParseError from apps.mtm.models import Material, Process from apps.utils.tools import ranstr 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.services_2 import get_alldata_with_batch_and_store from apps.wpmw.models import Wpr diff --git a/apps/mtm/services.py b/apps/mtm/services.py index 5bdcdce8..ed238e43 100644 --- a/apps/mtm/services.py +++ b/apps/mtm/services.py @@ -11,30 +11,6 @@ from typing import List from apps.utils.snowflake import idWorker 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): """ 获取工段某年的全部目标值, 以字典形式返回, 带缓存 diff --git a/apps/mtm/services_2.py b/apps/mtm/services_2.py new file mode 100644 index 00000000..f4843a64 --- /dev/null +++ b/apps/mtm/services_2.py @@ -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) \ No newline at end of file diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 13f95968..2979be13 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -12,7 +12,7 @@ from apps.pm.models import Mtask from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Srule 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.utils.thread import MyThread import logging