增加iproduct查询条件/甘特图plan接口

This commit is contained in:
caoqianming 2021-12-13 13:50:14 +08:00
parent 30dbc5a6cd
commit 87eb8f1f1c
6 changed files with 57 additions and 6 deletions

View File

@ -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']
fields = ['material', 'warehouse', 'batch', 'order', 'is_mtested', 'is_mtestok', 'material__type']

View File

@ -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('计划完工日期')

View File

@ -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

View File

@ -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)),
]

View File

@ -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):
"""
订单-计划-子计划甘特图
计划-子计划甘特图
"""
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']

View File

@ -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()),