hberp/hb_server/apps/srm/services.py

25 lines
1.1 KiB
Python

from apps.mtm.models import Material
from apps.wpm.models import WProduct, WproductFlow
class SrmServices:
"""
数据统计分析
"""
@classmethod
def get_wp_product_count(cls, datetime_start, datetime_end):
"""
根据生产情况统计相关数量
"""
objs = WproductFlow.objects.filter(is_lastlog=True, material__type=Material.MA_TYPE_GOOD)
if datetime_start:
objs = objs.filter(create_time__gte=datetime_start)
if datetime_end:
objs = objs.filter(create_time__lte=datetime_end)
count = objs.count()
count_ok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM,
WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).count()
count_notok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).count()
count_selled = objs.filter(act_state=WProduct.WPR_ACT_STATE_SELLED).count()
count_mtestok = objs.filter(is_mtestok=True).count()
return dict(count=count,count_ok=count_ok, count_notok=count_notok, count_selled=count_selled, count_mtestok=count_mtestok)