统计产品生产数量
This commit is contained in:
parent
5327828ae0
commit
4cadeac2d4
|
@ -6,6 +6,8 @@ from apps.sam.models import SalePack, SaleProduct
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.db.models.aggregates import Sum
|
from django.db.models.aggregates import Sum
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from apps.wpm.services import WpmService
|
||||||
logger = logging.getLogger('log')
|
logger = logging.getLogger('log')
|
||||||
|
|
||||||
class InmService:
|
class InmService:
|
||||||
|
@ -133,8 +135,10 @@ class InmService:
|
||||||
|
|
||||||
# 更新动态产品表情况
|
# 更新动态产品表情况
|
||||||
from apps.wpm.models import WProduct
|
from apps.wpm.models import WProduct
|
||||||
WProduct.objects.filter(id__in=ips.values_list('wproduct', flat=True)).update(
|
wps = WProduct.objects.filter(id__in=ips.values_list('wproduct', flat=True))
|
||||||
|
wps.update(
|
||||||
act_state=WProduct.WPR_ACT_STATE_SELLED)
|
act_state=WProduct.WPR_ACT_STATE_SELLED)
|
||||||
|
WpmService.add_wproducts_flow_log(instances=wps, change_str='selled')
|
||||||
|
|
||||||
# 变更销售记录实际发货数
|
# 变更销售记录实际发货数
|
||||||
sale.count_real = ips.count()
|
sale.count_real = ips.count()
|
||||||
|
|
|
@ -25,6 +25,9 @@ class ProcessYieldSerializer(serializers.Serializer):
|
||||||
datetime_start = serializers.DateField(label='开始时间', required=False, allow_null=True)
|
datetime_start = serializers.DateField(label='开始时间', required=False, allow_null=True)
|
||||||
datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True)
|
datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True)
|
||||||
|
|
||||||
|
class ProductCountSerializer(serializers.Serializer):
|
||||||
|
datetime_start = serializers.DateField(label='开始时间', required=False, allow_null=True)
|
||||||
|
datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True)
|
||||||
|
|
||||||
class AtWorkCountSerializer(serializers.Serializer):
|
class AtWorkCountSerializer(serializers.Serializer):
|
||||||
year = serializers.IntegerField(label='年')
|
year = serializers.IntegerField(label='年')
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
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 = WproductFlow.objects.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)
|
|
@ -3,11 +3,12 @@ from rest_framework import urlpatterns
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from apps.srm.views import AtWorkCountView, GanttPlan, ProcessYieldView
|
from apps.srm.views import AtWorkCountView, GanttPlan, ProcessYieldView, ProductCountView
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('gantt/plan/', GanttPlan.as_view()),
|
path('gantt/plan/', GanttPlan.as_view()),
|
||||||
|
path('product/count/', ProductCountView.as_view()),
|
||||||
path('process/yield/', ProcessYieldView.as_view()),
|
path('process/yield/', ProcessYieldView.as_view()),
|
||||||
path('at_work/', AtWorkCountView.as_view()),
|
path('at_work/', AtWorkCountView.as_view()),
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
|
|
|
@ -9,7 +9,8 @@ from rest_framework.response import Response
|
||||||
from apps.hrm.models import ClockRecord
|
from apps.hrm.models import ClockRecord
|
||||||
from apps.mtm.models import Process, Step
|
from apps.mtm.models import Process, Step
|
||||||
from apps.pm.models import ProductionPlan, SubProductionPlan
|
from apps.pm.models import ProductionPlan, SubProductionPlan
|
||||||
from apps.srm.serializers import AtWorkCountSerializer, PlanGanttSerializer, ProcessYieldSerializer
|
from apps.srm.serializers import AtWorkCountSerializer, PlanGanttSerializer, ProcessYieldSerializer, ProductCountSerializer
|
||||||
|
from apps.srm.services import SrmServices
|
||||||
from apps.wpm.models import WProduct, WproductFlow
|
from apps.wpm.models import WProduct, WproductFlow
|
||||||
from django.db.models import Count, F
|
from django.db.models import Count, F
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
@ -23,6 +24,19 @@ class GanttPlan(ListAPIView):
|
||||||
queryset = ProductionPlan.objects.filter(is_deleted=False, is_planed=True).prefetch_related('subplan_plan', 'subplan_plan__process')
|
queryset = ProductionPlan.objects.filter(is_deleted=False, is_planed=True).prefetch_related('subplan_plan', 'subplan_plan__process')
|
||||||
ordering = ['-id']
|
ordering = ['-id']
|
||||||
|
|
||||||
|
class ProductCountView(CreateAPIView):
|
||||||
|
"""
|
||||||
|
产品数量统计
|
||||||
|
"""
|
||||||
|
perms_map = {'post':'*'}
|
||||||
|
serializer_class = ProductCountSerializer
|
||||||
|
def create(self, request, *args, **kwargs):
|
||||||
|
serializer = self.get_serializer(data=request.data)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
vdata = serializer.validated_data
|
||||||
|
res = SrmServices.get_wp_product_count(datetime_start= vdata.get('datetime_start', None), datetime_end= vdata.get('datetime_end', None))
|
||||||
|
return Response(res)
|
||||||
|
|
||||||
class ProcessYieldView(CreateAPIView):
|
class ProcessYieldView(CreateAPIView):
|
||||||
"""
|
"""
|
||||||
工序成品率统计
|
工序成品率统计
|
||||||
|
|
|
@ -167,6 +167,23 @@ class WpmService(object):
|
||||||
ins.change_str = change_str
|
ins.change_str = change_str
|
||||||
ins.save()
|
ins.save()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_wproducts_flow_log(cls, instances, change_str=''):
|
||||||
|
"""
|
||||||
|
批量创建产品变动日志
|
||||||
|
"""
|
||||||
|
WproductFlow.objects.filter(wproduct__in=instances).update(is_lastlog=False)
|
||||||
|
wfw = []
|
||||||
|
for i in instances:
|
||||||
|
ins = WproductFlow()
|
||||||
|
ins.wproduct = i
|
||||||
|
for f in WproductFlow.__meta.fields:
|
||||||
|
if f.name not in ['id', 'wproduct', 'is_lastlog']:
|
||||||
|
setattr(ins, f.name, getattr(i, f.name, None))
|
||||||
|
ins.change_str = change_str
|
||||||
|
wfw.append(ins)
|
||||||
|
WproductFlow.objects.bulk_create(wfw)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_cutting_list_with_operation(cls, op:Operation):
|
def update_cutting_list_with_operation(cls, op:Operation):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue