fix: 优化cal_material_count
This commit is contained in:
parent
b18f39d95d
commit
8872d63aae
|
@ -10,20 +10,23 @@ from apps.wpm.services import get_sflog
|
||||||
from apps.wpm.tasks import cal_exp_duration_sec
|
from apps.wpm.tasks import cal_exp_duration_sec
|
||||||
from apps.wf.models import Ticket
|
from apps.wf.models import Ticket
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
|
from typing import List
|
||||||
|
|
||||||
def cal_material_count(materialId_list: list = []):
|
def cal_material_count(materialId_list: List[str]=None):
|
||||||
"""
|
"""
|
||||||
计算物料总数量
|
计算物料总数量
|
||||||
"""
|
"""
|
||||||
from apps.inm.models import MaterialBatch
|
from apps.inm.models import MaterialBatch
|
||||||
from apps.wpm.models import WMaterial
|
from apps.wpm.models import WMaterial
|
||||||
|
if materialId_list is None:
|
||||||
|
materialId_list = []
|
||||||
if materialId_list:
|
if materialId_list:
|
||||||
objs = Material.objects.filter(id__in=set(materialId_list))
|
objs = Material.objects.filter(id__in=set(materialId_list))
|
||||||
else:
|
else:
|
||||||
objs = Material.objects.all()
|
objs = Material.objects.all()
|
||||||
for material in objs:
|
for material in objs:
|
||||||
mb_count = MaterialBatch.objects.filter(material=material).aggregate(total=Sum("count"))["total"]
|
mb_count = MaterialBatch.objects.filter(material=material).aggregate(total=Sum("count"))["total"] or 0
|
||||||
wm_count = WMaterial.objects.filter(material=material).aggregate(total=Sum("count"))["total"]
|
wm_count = WMaterial.objects.filter(material=material).aggregate(total=Sum("count"))["total"] or 0
|
||||||
if mb_count is None:
|
if mb_count is None:
|
||||||
mb_count = 0
|
mb_count = 0
|
||||||
if wm_count is None:
|
if wm_count is None:
|
||||||
|
|
Loading…
Reference in New Issue