产品生产子工序表
This commit is contained in:
parent
107891ad6d
commit
2a220e962e
|
@ -18,6 +18,11 @@ class Equipment(CommonBModel):
|
||||||
(0, '停用'),
|
(0, '停用'),
|
||||||
(2, '报废')
|
(2, '报废')
|
||||||
)
|
)
|
||||||
|
type_choices = (
|
||||||
|
(1, '生产设备'),
|
||||||
|
(2, '检验工具')
|
||||||
|
)
|
||||||
|
type = models.IntegerField('类型', choices=type_choices, default=1)
|
||||||
name = models.CharField('设备名称', max_length=50)
|
name = models.CharField('设备名称', max_length=50)
|
||||||
number = models.CharField('设备编号', max_length=50, unique=True)
|
number = models.CharField('设备编号', max_length=50, unique=True)
|
||||||
model = models.CharField('规格型号', max_length=60, null=True, blank=True)
|
model = models.CharField('规格型号', max_length=60, null=True, blank=True)
|
||||||
|
|
|
@ -16,3 +16,8 @@ class EquipmentSerializer(ModelSerializer):
|
||||||
""" Perform necessary eager loading of data. """
|
""" Perform necessary eager loading of data. """
|
||||||
queryset = queryset.select_related('belong_dept','keeper')
|
queryset = queryset.select_related('belong_dept','keeper')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
class EquipmentSimpleSerializer(ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Equipment
|
||||||
|
fields = ['id', 'number', 'name']
|
|
@ -5,6 +5,8 @@ from django.db.models.query import QuerySet
|
||||||
from apps.system.models import CommonAModel, CommonBModel, Organization, User, Dict, File
|
from apps.system.models import CommonAModel, CommonBModel, Organization, User, Dict, File
|
||||||
from utils.model import SoftModel, BaseModel
|
from utils.model import SoftModel, BaseModel
|
||||||
from simple_history.models import HistoricalRecords
|
from simple_history.models import HistoricalRecords
|
||||||
|
from apps.system.models import Organization
|
||||||
|
from apps.em.models import Equipment
|
||||||
|
|
||||||
class Material(CommonAModel):
|
class Material(CommonAModel):
|
||||||
"""
|
"""
|
||||||
|
@ -41,6 +43,7 @@ class Process(CommonAModel):
|
||||||
number = models.CharField('编号', max_length=100, unique=True)
|
number = models.CharField('编号', max_length=100, unique=True)
|
||||||
instruction = models.ForeignKey(File, verbose_name='指导书', on_delete=models.SET_NULL, null=True, blank=True)
|
instruction = models.ForeignKey(File, verbose_name='指导书', on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
instruction_content = models.TextField('指导书内容', null=True, blank=True)
|
instruction_content = models.TextField('指导书内容', null=True, blank=True)
|
||||||
|
workshop = models.ForeignKey(Organization, verbose_name='生产车间', on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '工序'
|
verbose_name = '工序'
|
||||||
|
@ -58,6 +61,7 @@ class Step(CommonAModel):
|
||||||
number = models.CharField('步骤编号', max_length=100, null=True, blank=True)
|
number = models.CharField('步骤编号', max_length=100, null=True, blank=True)
|
||||||
instruction_content = models.TextField('相应操作指导', null=True, blank=True)
|
instruction_content = models.TextField('相应操作指导', null=True, blank=True)
|
||||||
sort = models.IntegerField('排序号', default=1)
|
sort = models.IntegerField('排序号', default=1)
|
||||||
|
equipments = models.ManyToManyField(Equipment, verbose_name='使用设备')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '工序步骤'
|
verbose_name = '工序步骤'
|
||||||
|
@ -66,6 +70,12 @@ class Step(CommonAModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
# class StepTable(CommonAModel):
|
||||||
|
# """
|
||||||
|
# 过程记录表格
|
||||||
|
# """
|
||||||
|
|
||||||
|
|
||||||
class StepOperationItem(CommonAModel):
|
class StepOperationItem(CommonAModel):
|
||||||
"""
|
"""
|
||||||
操作记录条目
|
操作记录条目
|
||||||
|
@ -126,6 +136,7 @@ class InputMaterial(CommonAModel):
|
||||||
verbose_name_plural = verbose_name
|
verbose_name_plural = verbose_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OutputMaterial(CommonAModel):
|
class OutputMaterial(CommonAModel):
|
||||||
"""
|
"""
|
||||||
输出物料
|
输出物料
|
||||||
|
@ -138,4 +149,16 @@ class OutputMaterial(CommonAModel):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '输出物料'
|
verbose_name = '输出物料'
|
||||||
verbose_name_plural = verbose_name
|
verbose_name_plural = verbose_name
|
||||||
|
|
||||||
|
class UsedStep(CommonAModel):
|
||||||
|
"""
|
||||||
|
产品生产子工序
|
||||||
|
"""
|
||||||
|
step = models.ForeignKey(Step, verbose_name='子工序', on_delete=models.CASCADE, related_name='usedsteps')
|
||||||
|
product = models.ForeignKey(Material, verbose_name='关联产品', on_delete=models.CASCADE)
|
||||||
|
process = models.ForeignKey(Process, verbose_name='关联工序', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = '产品生产子工序'
|
||||||
|
verbose_name_plural = verbose_name
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
from apps.em.serializers import EquipmentSerializer, EquipmentSimpleSerializer
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from .models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, Step
|
from .models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, Step, UsedStep
|
||||||
from apps.system.serializers import FileSimpleSerializer
|
from apps.system.serializers import FileSimpleSerializer
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +43,22 @@ class StepSerializer(serializers.ModelSerializer):
|
||||||
model = Step
|
model = Step
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class StepSimpleSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Step
|
||||||
|
fields = ['id', 'name', 'sort']
|
||||||
|
|
||||||
|
class StepDetailSerializer(serializers.ModelSerializer):
|
||||||
|
equipments_ = EquipmentSimpleSerializer(source='equipments_', many=True)
|
||||||
|
class Meta:
|
||||||
|
model = Step
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setup_eager_loading(queryset):
|
||||||
|
queryset = queryset.prefetch_related('equipments')
|
||||||
|
return queryset
|
||||||
|
|
||||||
class ProductProcessListSerializer(serializers.ModelSerializer):
|
class ProductProcessListSerializer(serializers.ModelSerializer):
|
||||||
process_ = ProcessSimpleSerializer(source='process', read_only=True)
|
process_ = ProcessSimpleSerializer(source='process', read_only=True)
|
||||||
product_ = MaterialSimpleSerializer(source='product', read_only=True)
|
product_ = MaterialSimpleSerializer(source='product', read_only=True)
|
||||||
|
@ -95,4 +112,27 @@ class OutputMaterialSerializer(serializers.ModelSerializer):
|
||||||
class OutputMaterialUpdateSerializer(serializers.ModelSerializer):
|
class OutputMaterialUpdateSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OutputMaterial
|
model = OutputMaterial
|
||||||
fields = ['count', 'sort']
|
fields = ['count', 'sort']
|
||||||
|
|
||||||
|
class UsedStepCreateSerializer(serializers.ModelSerializer):
|
||||||
|
"""
|
||||||
|
产品生产子工序创建
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
model = UsedStep
|
||||||
|
fields = ['step', 'product', 'process']
|
||||||
|
|
||||||
|
class UsedStepListSerializer(serializers.ModelSerializer):
|
||||||
|
"""
|
||||||
|
产品生产子工序序列化
|
||||||
|
"""
|
||||||
|
step_ = StepSimpleSerializer(source='step', read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = UsedStep
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setup_eager_loading(queryset):
|
||||||
|
""" Perform necessary eager loading of data. """
|
||||||
|
queryset = queryset.select_related('step')
|
||||||
|
return queryset
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
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 InputMaterialViewSet, MaterialViewSet, OutputMaterialViewSet, ProcessViewSet, StepViewSet
|
from apps.mtm.views import InputMaterialViewSet, MaterialViewSet, OutputMaterialViewSet, ProcessViewSet, StepViewSet, UsedStepViewSet
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ router.register('process', ProcessViewSet, basename='process')
|
||||||
router.register('step', StepViewSet, basename='step')
|
router.register('step', StepViewSet, basename='step')
|
||||||
router.register('inputmaterial', InputMaterialViewSet, basename='inputmaterial')
|
router.register('inputmaterial', InputMaterialViewSet, basename='inputmaterial')
|
||||||
router.register('outputmaterial', OutputMaterialViewSet, basename='outputmaterial')
|
router.register('outputmaterial', OutputMaterialViewSet, basename='outputmaterial')
|
||||||
|
router.register('usedstep', UsedStepViewSet, basename='usedstep')
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,8 +2,8 @@ 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, ListModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin
|
from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin
|
||||||
|
|
||||||
from apps.mtm.models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, Step
|
from apps.mtm.models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, Step, UsedStep
|
||||||
from apps.mtm.serializers import InputMaterialListSerializer, InputMaterialSerializer, InputMaterialUpdateSerializer, MaterialDetailSerializer, MaterialSerializer, MaterialSimpleSerializer, OutputMaterialListSerializer, OutputMaterialSerializer, OutputMaterialUpdateSerializer, ProductProcessListSerializer, ProductProcessUpdateSerializer, ProcessSerializer, StepSerializer
|
from apps.mtm.serializers import InputMaterialListSerializer, InputMaterialSerializer, InputMaterialUpdateSerializer, MaterialDetailSerializer, MaterialSerializer, MaterialSimpleSerializer, OutputMaterialListSerializer, OutputMaterialSerializer, OutputMaterialUpdateSerializer, ProductProcessListSerializer, ProductProcessUpdateSerializer, ProcessSerializer, StepSerializer, UsedStepCreateSerializer, UsedStepListSerializer
|
||||||
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
|
||||||
|
@ -122,3 +122,17 @@ class OutputMaterialViewSet(CreateUpdateModelAMixin, ModelViewSet):
|
||||||
elif self.action == 'update':
|
elif self.action == 'update':
|
||||||
return OutputMaterialUpdateSerializer
|
return OutputMaterialUpdateSerializer
|
||||||
return OutputMaterialSerializer
|
return OutputMaterialSerializer
|
||||||
|
|
||||||
|
class UsedStepViewSet(OptimizationMixin, CreateModelMixin, DestroyModelMixin, ListModelMixin, GenericViewSet):
|
||||||
|
"""
|
||||||
|
产品生产子工序表
|
||||||
|
"""
|
||||||
|
perms_map = {'*':'*'}
|
||||||
|
queryset = UsedStep.objects.all()
|
||||||
|
filterset_fields = ['process', 'product', 'step']
|
||||||
|
ordering = ['step__sort', '-step__create_time']
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.action =='create':
|
||||||
|
return UsedStepCreateSerializer
|
||||||
|
return UsedStepListSerializer
|
|
@ -51,7 +51,8 @@ class FitJSONRenderer(JSONRenderer):
|
||||||
if response_body.code >= 400: # 响应异常
|
if response_body.code >= 400: # 响应异常
|
||||||
response_body.data = data # data里是详细异常信息
|
response_body.data = data # data里是详细异常信息
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
data = data[list(data.keys())[0]]
|
key = list(data.keys())[0]
|
||||||
|
data = key + data[key]
|
||||||
elif isinstance(data, list):
|
elif isinstance(data, list):
|
||||||
data = data[0]
|
data = data[0]
|
||||||
response_body.msg = data # 取一部分放入msg,方便前端alert
|
response_body.msg = data # 取一部分放入msg,方便前端alert
|
||||||
|
|
Loading…
Reference in New Issue