产品生产工艺流程增加删除

This commit is contained in:
caoqianming 2021-08-26 14:01:59 +08:00
parent faf524604b
commit 70b1305bb7
4 changed files with 59 additions and 8 deletions

View File

@ -86,6 +86,7 @@ class StepOperationItem(CommonAModel):
help_text='当为布尔类型时候,可以支持自定义显示形式。{"1":"","0":""}或{"1":"需要","0":"不需要"},注意数字也需要引号') help_text='当为布尔类型时候,可以支持自定义显示形式。{"1":"","0":""}或{"1":"需要","0":"不需要"},注意数字也需要引号')
field_choice = models.JSONField('radio、checkbox、select的选项', default=dict, blank=True, field_choice = models.JSONField('radio、checkbox、select的选项', default=dict, blank=True,
help_text='radio,checkbox,select,multiselect类型可供选择的选项格式为json如:{"1":"中国", "2":"美国"},注意数字也需要引号') help_text='radio,checkbox,select,multiselect类型可供选择的选项格式为json如:{"1":"中国", "2":"美国"},注意数字也需要引号')
sort = models.IntegerField('排序号', default=1)
class Meta: class Meta:
verbose_name = '操作记录条目' verbose_name = '操作记录条目'
verbose_name_plural = verbose_name verbose_name_plural = verbose_name

View File

@ -1,6 +1,6 @@
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from .models import Material, Process, Step from .models import Material, Process, ProductProcess, Step
from apps.system.serializers import FileSimpleSerializer from apps.system.serializers import FileSimpleSerializer
@ -9,14 +9,35 @@ class MaterialSerializer(ModelSerializer):
model = Material model = Material
fields = '__all__' fields = '__all__'
class MaterialSimpleSerializer(ModelSerializer):
class Meta:
model = Material
fields = ['id', 'name', 'number']
class ProcessSerializer(ModelSerializer): class ProcessSerializer(ModelSerializer):
instruction_ = FileSimpleSerializer(source='instruction', read_only=True) instruction_ = FileSimpleSerializer(source='instruction', read_only=True)
class Meta: class Meta:
model = Process model = Process
fields = '__all__' fields = '__all__'
class ProcessSimpleSerializer(ModelSerializer):
class Meta:
model = Process
fields = ['id', 'name', 'number']
class StepSerializer(ModelSerializer): class StepSerializer(ModelSerializer):
class Meta: class Meta:
model = Step model = Step
fields = '__all__' fields = '__all__'
class ProductProcessListSerializer(ModelSerializer):
process_ = ProcessSimpleSerializer(source='process', read_only=True)
product_ = MaterialSimpleSerializer(source='product', read_only=True)
class Meta:
model = ProductProcess
fields = '__all__'
class ProductProcessUpdateSerializer(ModelSerializer):
class Meta:
model = ProductProcess
fields = ['sort']

View File

@ -1,12 +1,13 @@
from django.db.models import base from django.db.models import base
from rest_framework import urlpatterns from rest_framework import urlpatterns
from apps.mtm.views import MaterialViewSet, ProcessViewSet, StepViewSet from apps.mtm.views import MaterialViewSet, ProcessViewSet, ProductProcessViewSet, StepViewSet
from django.urls import path, include from django.urls import path, include
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
router = DefaultRouter() router = DefaultRouter()
router.register('material', MaterialViewSet, basename='material') router.register('material', MaterialViewSet, basename='material')
router.register('process', ProcessViewSet, basename='process') router.register('process', ProcessViewSet, basename='process')
router.register('productprocess', ProductProcessViewSet, basename='productprocess')
router.register('step', StepViewSet, basename='step') router.register('step', StepViewSet, basename='step')
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), path('', include(router.urls)),

View File

@ -1,9 +1,9 @@
from django.shortcuts import render from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet, GenericViewSet from rest_framework.viewsets import ModelViewSet, GenericViewSet
from rest_framework.mixins import CreateModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin
from apps.mtm.models import Material, Process, Step from apps.mtm.models import Material, Process, ProductProcess, Step
from apps.mtm.serializers import MaterialSerializer, ProcessSerializer, StepSerializer from apps.mtm.serializers import MaterialSerializer, ProductProcessListSerializer, ProductProcessUpdateSerializer, ProcessSerializer, StepSerializer
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
@ -23,6 +23,16 @@ class MaterialViewSet(CreateUpdateModelAMixin, ModelViewSet):
ordering_fields = ['number', 'sort_str'] ordering_fields = ['number', 'sort_str']
ordering = ['number'] ordering = ['number']
@action(methods=['get'], detail=True, perms_map={'get':'*'}, pagination_class=None, serializer_class=StepSerializer)
def steps(self, request, pk=None):
"""
工序下的子工序
"""
process = self.get_object()
serializer = self.serializer_class(instance=Step.objects.filter(process=process, is_deleted=False), many=True)
return Response(serializer.data)
class ProcessViewSet(CreateUpdateModelAMixin, ModelViewSet): class ProcessViewSet(CreateUpdateModelAMixin, ModelViewSet):
""" """
工序表-增删改查 工序表-增删改查
@ -46,9 +56,27 @@ class ProcessViewSet(CreateUpdateModelAMixin, ModelViewSet):
return Response(serializer.data) return Response(serializer.data)
class StepViewSet(CreateModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin, GenericViewSet): class StepViewSet(CreateModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin, GenericViewSet):
"""
"""
perms_map = {'*':'process_update'} perms_map = {'*':'process_update'}
queryset = Step.objects.all() queryset = Step.objects.all()
serializer_class = StepSerializer serializer_class = StepSerializer
search_fields = ['name', 'number'] search_fields = ['name', 'number']
filterset_fields = ['process'] filterset_fields = ['process']
ordering = ['sort'] ordering = ['sort']
class ProductProcessViewSet(CreateModelMixin, UpdateModelMixin, ListModelMixin, DestroyModelMixin, GenericViewSet):
"""
产品生产工艺流程增删改查
"""
perms_map={'*':'*'}
queryset = ProductProcess.objects.select_related('process', 'product').all()
filterset_fields = ['process', 'product']
serializer_class = ProductProcessListSerializer
ordering = ['sort']
def get_serializer_class(self):
if self.action == 'update':
return ProductProcessUpdateSerializer
return super().get_serializer_class()