From 87eb8f1f1cdd9ca6fb91bad61674433b76ea0120 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 13 Dec 2021 13:50:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0iproduct=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6/=E7=94=98=E7=89=B9=E5=9B=BEplan=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/inm/filters.py | 2 +- hb_server/apps/pm/models.py | 9 ++++++++- hb_server/apps/srm/serializers.py | 22 ++++++++++++++++++++++ hb_server/apps/srm/urls.py | 13 +++++++++++++ hb_server/apps/srm/views.py | 15 ++++++++++++--- hb_server/server/urls.py | 2 +- 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 hb_server/apps/srm/serializers.py create mode 100644 hb_server/apps/srm/urls.py diff --git a/hb_server/apps/inm/filters.py b/hb_server/apps/inm/filters.py index 2ff12aa..09f8777 100644 --- a/hb_server/apps/inm/filters.py +++ b/hb_server/apps/inm/filters.py @@ -14,4 +14,4 @@ class IProductFilterSet(filters.FilterSet): order = filters.NumberFilter(field_name="wproduct__subproduction_plan__production_plan__order") class Meta: model = IProduct - fields = ['material', 'warehouse', 'batch', 'order', 'is_mtested', 'is_mtestok'] \ No newline at end of file + fields = ['material', 'warehouse', 'batch', 'order', 'is_mtested', 'is_mtestok', 'material__type'] \ No newline at end of file diff --git a/hb_server/apps/pm/models.py b/hb_server/apps/pm/models.py index 6a06c29..346428f 100644 --- a/hb_server/apps/pm/models.py +++ b/hb_server/apps/pm/models.py @@ -14,6 +14,13 @@ class ProductionPlan(CommonAModel): """ 生产计划 """ + # PLAN_STATE_WAIT = 6 + # PLAN_STATE_WORKING = 10 + # PLAN_STATE_DONE = 20 + # state_choices = ( + # (PLAN_STATE_WORKING, '进行中'), + # (PLAN_STATE_DONE, '已完成') + # ) number = models.CharField('编号', max_length=50, unique=True) order = models.ForeignKey(Order, verbose_name='关联订单', null=True, blank=True, on_delete=models.SET_NULL) product = models.ForeignKey(Material, verbose_name='生产产品', on_delete=models.CASCADE) @@ -47,7 +54,7 @@ class SubProductionPlan(CommonAModel): (SUBPLAN_STATE_DONE, '已完成') ) number = models.CharField('子计划编号', max_length=50, unique=True, null=True, blank=True) - production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE) + production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE, related_name='subplan_plan') subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='subplan_subprod') start_date = models.DateField('计划开工日期') end_date = models.DateField('计划完工日期') diff --git a/hb_server/apps/srm/serializers.py b/hb_server/apps/srm/serializers.py new file mode 100644 index 0000000..a142348 --- /dev/null +++ b/hb_server/apps/srm/serializers.py @@ -0,0 +1,22 @@ +from rest_framework import serializers +from apps.pm.models import ProductionPlan, SubProductionPlan +from apps.mtm.serializers import ProcessSimpleSerializer + +class SubplanGanttSerializer(serializers.ModelSerializer): + count = serializers.IntegerField(source='main_count') + count_real = serializers.IntegerField(source='main_count_real') + count_ok = serializers.IntegerField(source='main_count_ok') + process_ = ProcessSimpleSerializer(source='process', read_only=True) + class Meta: + model = SubProductionPlan + fields = ['id', 'number', 'start_date', 'end_date', 'count', 'count_real', 'count_ok', 'start_date_real', 'end_date_real', 'process_'] + +class PlanGanttSerializer(serializers.ModelSerializer): + children = serializers.SerializerMethodField() + class Meta: + model = ProductionPlan + fields = ['id', 'number', 'start_date', 'end_date', 'children', 'count', 'count_real', 'count_ok'] + + def get_children(self, obj): + subplans = SubProductionPlan.objects.filter(production_plan=obj).order_by('process__number') + return SubplanGanttSerializer(instance=subplans, many=True).data \ No newline at end of file diff --git a/hb_server/apps/srm/urls.py b/hb_server/apps/srm/urls.py new file mode 100644 index 0000000..cbaf2ed --- /dev/null +++ b/hb_server/apps/srm/urls.py @@ -0,0 +1,13 @@ +from django.db.models import base +from rest_framework import urlpatterns +from django.urls import path, include +from rest_framework.routers import DefaultRouter + +from apps.srm.views import GanttPlan + +router = DefaultRouter() +urlpatterns = [ + path('gantt/plan/', GanttPlan.as_view()), + path('', include(router.urls)), +] + diff --git a/hb_server/apps/srm/views.py b/hb_server/apps/srm/views.py index 59607d6..a739725 100644 --- a/hb_server/apps/srm/views.py +++ b/hb_server/apps/srm/views.py @@ -1,8 +1,17 @@ from django.shortcuts import render +from rest_framework import serializers from rest_framework.generics import ListAPIView +from rest_framework.response import Response +from apps.pm.models import ProductionPlan, SubProductionPlan +from apps.srm.serializers import PlanGanttSerializer # Create your views here. -class GanttOrder(ListAPIView): +class GanttPlan(ListAPIView): """ - 订单-计划-子计划甘特图 - """ \ No newline at end of file + 计划-子计划甘特图 + """ + perms_map = {'get':'*'} + serializer_class = PlanGanttSerializer + queryset = ProductionPlan.objects.filter(is_deleted=False, is_planed=True).prefetch_related('subplan_plan', 'subplan_plan__process') + ordering = ['-id'] + diff --git a/hb_server/server/urls.py b/hb_server/server/urls.py index 3db8e36..b1893f2 100644 --- a/hb_server/server/urls.py +++ b/hb_server/server/urls.py @@ -69,7 +69,7 @@ urlpatterns = [ path('api/qm/', include('apps.qm.urls')), path('api/pm/', include('apps.pm.urls')), path('api/wpm/', include('apps.wpm.urls')), - + path('api/srm/', include('apps.srm.urls')), # 工具 path('api/utils/signature/', GenSignature.as_view()), path('api/utils/develop/', UpdateDevelop.as_view()),