diff --git a/hb_server/apps/pm/filters.py b/hb_server/apps/pm/filters.py new file mode 100644 index 0000000..d025611 --- /dev/null +++ b/hb_server/apps/pm/filters.py @@ -0,0 +1,22 @@ +from django_filters import rest_framework as filters +from apps.pm.models import SubProductionProgress +from apps.wpm.models import Operation, WProduct + +from apps.wpm.services import WpmServies + + +class SubproductionProgressFilterSet(filters.FilterSet): + + operation = filters.NumberFilter(method='filter_operation') + class Meta: + model = SubProductionProgress + fields = ['material', 'subproduction_plan', 'operation', 'type'] + + def filter_operation(self, queryset, name, value): + operation = Operation.objects.get(pk=value) + wproducts = WProduct.objects.filter(ow_wproduct__operation=value) + if wproducts.exists(): + subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts) + else: + subplans = WpmServies.get_subplans_queyset_from_step(operation.step) + return queryset.filter(subproduction_plan__in=subplans) \ No newline at end of file diff --git a/hb_server/apps/pm/urls.py b/hb_server/apps/pm/urls.py index f6f6279..1d3f1eb 100644 --- a/hb_server/apps/pm/urls.py +++ b/hb_server/apps/pm/urls.py @@ -1,4 +1,4 @@ -from apps.pm.views import ProductionPlanViewSet, ResourceViewSet, SubProductionPlanViewSet +from apps.pm.views import ProductionPlanViewSet, ResourceViewSet, SubProductionPlanViewSet, SubProductionProgressViewSet from django.db.models import base from rest_framework import urlpatterns from django.urls import path, include @@ -7,6 +7,7 @@ from rest_framework.routers import DefaultRouter router = DefaultRouter() router.register('production_plan', ProductionPlanViewSet, basename='production_plan') router.register('subproduction_plan', SubProductionPlanViewSet, basename='subproduction_plan') +router.register('subproduction_progress', SubProductionProgressViewSet, basename='subproduction_progress') router.register('resource', ResourceViewSet, basename='resource') urlpatterns = [ path('', include(router.urls)), diff --git a/hb_server/apps/pm/views.py b/hb_server/apps/pm/views.py index 56446bf..aa02784 100644 --- a/hb_server/apps/pm/views.py +++ b/hb_server/apps/pm/views.py @@ -1,4 +1,5 @@ from datetime import timezone +from typing import List from django.db import transaction from rest_framework import serializers from rest_framework.views import APIView @@ -7,6 +8,7 @@ from apps.em.serializers import EquipmentSerializer from apps.inm.models import MaterialBatch from apps.inm.serializers import MaterialBatchSerializer from apps.mtm.models import Step, SubProduction, SubprodctionMaterial, UsedStep +from apps.pm.filters import SubproductionProgressFilterSet from apps.system.mixins import CreateUpdateModelAMixin from apps.pm.serializers import GenSubPlanSerializer, PickNeedSerializer, PlanDestorySerializer, ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer, ResourceCalListSerializer, ResourceCalSerializer, SubProductionPlanListSerializer, SubProductionPlanUpdateSerializer, SubProductionProgressSerializer from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin @@ -67,7 +69,7 @@ class ProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, CreateModel return Response() @action(methods=['post'], detail=False, perms_map={'post':'*'}, serializer_class=PlanDestorySerializer) - def destory(self, request, pk=None): + def deletes(self, request, pk=None): """ 批量物理删除 """ @@ -178,6 +180,17 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo have = MaterialBatchSerializer(instance=objs, many=True).data return Response({'need':need, 'have':have}) +class SubProductionProgressViewSet(ListModelMixin, GenericViewSet): + """ + 生产进度 + """ + perms_map = {'*': '*'} + queryset = SubProductionProgress.objects.select_related('material', 'subproduction_plan') + search_fields = [] + serializer_class = SubProductionProgressSerializer + filterset_class = SubproductionProgressFilterSet + ordering_fields = ['id'] + ordering = ['id'] class ResourceViewSet(GenericViewSet): diff --git a/hb_server/apps/wpm/filters.py b/hb_server/apps/wpm/filters.py index f14d741..6f96092 100644 --- a/hb_server/apps/wpm/filters.py +++ b/hb_server/apps/wpm/filters.py @@ -1,4 +1,6 @@ from django_filters import rest_framework as filters + +from apps.wpm.services import WpmServies from .models import Operation, WMaterial, WProduct class WMaterialFilterSet(filters.FilterSet): @@ -6,12 +8,13 @@ class WMaterialFilterSet(filters.FilterSet): operation = filters.NumberFilter(method='filter_operation') class Meta: model = WMaterial - fields = ['material', 'subproduction_plan', 'subproduction_plan__process', 'subproduction_plan__workshop'] + fields = ['material', 'subproduction_plan', 'subproduction_plan__process', 'subproduction_plan__workshop', 'operation'] def filter_operation(self, queryset, name, value): operation = Operation.objects.get(pk=value) wproducts = WProduct.objects.filter(ow_wproduct__operation=value) if wproducts.exists(): - pass + subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts) else: - pass \ No newline at end of file + subplans = WpmServies.get_subplans_queyset_from_step(operation.step) + return queryset.filter(subproduction_plan__in=subplans) \ No newline at end of file diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index bc1b8b7..6967399 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -343,8 +343,12 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd opm.save() return Response() - - + @action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=serializers.Serializer) + @transaction.atomic + def submit(self, request, pk=None): + """ + 提交车间操作重要 + """