车间操作列表优化
This commit is contained in:
parent
f21a599252
commit
d65f117303
|
@ -0,0 +1,29 @@
|
||||||
|
# Generated by Django 3.2.9 on 2021-11-19 05:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wpm', '0017_auto_20211119_1034'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='operationequip',
|
||||||
|
name='operation',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='oe_operation', to='wpm.operation', verbose_name='关联操作'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='operationrecord',
|
||||||
|
name='operation',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='or_operation', to='wpm.operation', verbose_name='关联的生产操作'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='operationwproduct',
|
||||||
|
name='operation',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ow_operation', to='wpm.operation', verbose_name='关联操作'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -61,7 +61,7 @@ class OperationWproduct(BaseModel):
|
||||||
"""
|
"""
|
||||||
生产操作半成品关联表
|
生产操作半成品关联表
|
||||||
"""
|
"""
|
||||||
operation = models.ForeignKey(Operation, verbose_name='关联操作', on_delete=models.CASCADE)
|
operation = models.ForeignKey(Operation, verbose_name='关联操作', on_delete=models.CASCADE, related_name='ow_operation')
|
||||||
wproduct = models.ForeignKey(WProduct, verbose_name='关联半成品', on_delete=models.CASCADE)
|
wproduct = models.ForeignKey(WProduct, verbose_name='关联半成品', on_delete=models.CASCADE)
|
||||||
number = models.CharField('物品编号', null=True, blank=True, max_length=50)
|
number = models.CharField('物品编号', null=True, blank=True, max_length=50)
|
||||||
material = models.ForeignKey(Material, verbose_name='操作时的物料状态', on_delete=models.CASCADE)
|
material = models.ForeignKey(Material, verbose_name='操作时的物料状态', on_delete=models.CASCADE)
|
||||||
|
@ -88,7 +88,7 @@ class OperationRecord(BaseModel):
|
||||||
记录表格
|
记录表格
|
||||||
"""
|
"""
|
||||||
form = models.ForeignKey(RecordForm, verbose_name='所用的生产记录表格', on_delete=models.CASCADE)
|
form = models.ForeignKey(RecordForm, verbose_name='所用的生产记录表格', on_delete=models.CASCADE)
|
||||||
operation = models.ForeignKey(Operation, verbose_name='关联的生产操作', on_delete=models.CASCADE)
|
operation = models.ForeignKey(Operation, verbose_name='关联的生产操作', on_delete=models.CASCADE, related_name='or_operation')
|
||||||
is_filled = models.BooleanField('是否填写', default=True)
|
is_filled = models.BooleanField('是否填写', default=True)
|
||||||
|
|
||||||
class OperationRecordItem(BaseModel):
|
class OperationRecordItem(BaseModel):
|
||||||
|
@ -104,6 +104,6 @@ class OperationRecordItem(BaseModel):
|
||||||
operation_record = models.ForeignKey(OperationRecord, verbose_name='关联的生产记录', on_delete=models.CASCADE)
|
operation_record = models.ForeignKey(OperationRecord, verbose_name='关联的生产记录', on_delete=models.CASCADE)
|
||||||
|
|
||||||
class OperationEquip(BaseModel):
|
class OperationEquip(BaseModel):
|
||||||
operation = models.ForeignKey(Operation, verbose_name='关联操作', on_delete=models.CASCADE)
|
operation = models.ForeignKey(Operation, verbose_name='关联操作', on_delete=models.CASCADE, related_name='oe_operation')
|
||||||
equip = models.ForeignKey(Equipment, verbose_name='生产设备', on_delete=models.CASCADE)
|
equip = models.ForeignKey(Equipment, verbose_name='生产设备', on_delete=models.CASCADE)
|
||||||
remark = models.TextField('备注', null=True, blank=True)
|
remark = models.TextField('备注', null=True, blank=True)
|
|
@ -1,9 +1,10 @@
|
||||||
from rest_framework import serializers, exceptions
|
from rest_framework import serializers, exceptions
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
from apps.em.serializers import EquipmentSimpleSerializer
|
||||||
from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, MaterialBatch, WareHouse
|
from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, MaterialBatch, WareHouse
|
||||||
from apps.inm.signals import update_inm
|
from apps.inm.signals import update_inm
|
||||||
from apps.mtm.models import Material, RecordForm, Step, SubprodctionMaterial
|
from apps.mtm.models import Material, RecordForm, Step, SubprodctionMaterial
|
||||||
from apps.mtm.serializers import MaterialSimpleSerializer, StepSimpleSerializer
|
from apps.mtm.serializers import MaterialSimpleSerializer, RecordFormSimpleSerializer, StepSimpleSerializer
|
||||||
|
|
||||||
from apps.pm.models import SubProductionPlan, SubProductionProgress
|
from apps.pm.models import SubProductionPlan, SubProductionProgress
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -11,7 +12,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from apps.pm.serializers import SubproductionPlanSimpleSerializer
|
from apps.pm.serializers import SubproductionPlanSimpleSerializer
|
||||||
from apps.qm.models import TestRecord, TestRecordItem
|
from apps.qm.models import TestRecord, TestRecordItem
|
||||||
from apps.system.serializers import UserSimpleSerializer
|
from apps.system.serializers import UserSimpleSerializer
|
||||||
from apps.wpm.models import Operation, OperationWproduct, WMaterial, WProduct, OperationRecord, OperationRecordItem
|
from apps.wpm.models import Operation, OperationEquip, OperationWproduct, WMaterial, WProduct, OperationRecord, OperationRecordItem
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
class PickHalfSerializer(serializers.Serializer):
|
class PickHalfSerializer(serializers.Serializer):
|
||||||
|
@ -140,10 +141,22 @@ class OperationDetailSerializer(serializers.ModelSerializer):
|
||||||
class OperationListSerializer(serializers.ModelSerializer):
|
class OperationListSerializer(serializers.ModelSerializer):
|
||||||
create_by_ = UserSimpleSerializer(source='create_by', read_only=True)
|
create_by_ = UserSimpleSerializer(source='create_by', read_only=True)
|
||||||
step_ = StepSimpleSerializer(source='step', read_only=True)
|
step_ = StepSimpleSerializer(source='step', read_only=True)
|
||||||
|
wproduct_count = serializers.SerializerMethodField()
|
||||||
|
equip_count = serializers.SerializerMethodField()
|
||||||
|
form_count = serializers.SerializerMethodField()
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Operation
|
model = Operation
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
def get_wproduct_count(self, obj):
|
||||||
|
return obj.ow_operation.count()
|
||||||
|
|
||||||
|
def get_equip_count(self, obj):
|
||||||
|
return obj.oe_operation.count()
|
||||||
|
|
||||||
|
def get_form_count(self, obj):
|
||||||
|
return obj.or_operation.count()
|
||||||
|
|
||||||
class OperationCreateSerializer(serializers.Serializer):
|
class OperationCreateSerializer(serializers.Serializer):
|
||||||
"""
|
"""
|
||||||
操作创建
|
操作创建
|
||||||
|
@ -176,6 +189,12 @@ class OperationCreateSerializer(serializers.Serializer):
|
||||||
raise exceptions.ValidationError(_('请选择半成品进行操作'))
|
raise exceptions.ValidationError(_('请选择半成品进行操作'))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class OperationUpdateSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = OperationRecord
|
||||||
|
fields =['use_scrap', 'remark']
|
||||||
|
|
||||||
class OperationInitSerializer(serializers.Serializer):
|
class OperationInitSerializer(serializers.Serializer):
|
||||||
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
|
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
|
||||||
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
|
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
|
||||||
|
@ -271,5 +290,22 @@ class WproductPutInSerializer(serializers.Serializer):
|
||||||
warehouse = serializers.PrimaryKeyRelatedField(queryset=WareHouse.objects.all(), label="仓库ID")
|
warehouse = serializers.PrimaryKeyRelatedField(queryset=WareHouse.objects.all(), label="仓库ID")
|
||||||
remark = serializers.CharField(label="入库备注", required =False)
|
remark = serializers.CharField(label="入库备注", required =False)
|
||||||
|
|
||||||
|
class OperationEquipListSerializer(serializers.Serializer):
|
||||||
|
equip_ = EquipmentSimpleSerializer(source='equip', read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = OperationEquip
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class OperationEquipUpdateSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = OperationEquip
|
||||||
|
fields = ['remark']
|
||||||
|
|
||||||
|
class OperationRecordListSerializer(serializers.ModelSerializer):
|
||||||
|
form_ = RecordFormSimpleSerializer(source='form', read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = OperationRecord
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from rest_framework.generics import CreateAPIView, GenericAPIView
|
from rest_framework.generics import CreateAPIView, GenericAPIView
|
||||||
from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
|
from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin, UpdateModelMixin
|
||||||
from rest_framework.utils import serializer_helpers
|
from rest_framework.utils import serializer_helpers
|
||||||
from rest_framework.utils.field_mapping import get_relation_kwargs
|
from rest_framework.utils.field_mapping import get_relation_kwargs
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
@ -17,7 +17,7 @@ from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from apps.wpm.models import OperationEquip, OperationWproduct, WMaterial, WProduct, Operation, OperationMaterial, OperationRecord, OperationRecordItem
|
from apps.wpm.models import OperationEquip, OperationWproduct, WMaterial, WProduct, Operation, OperationMaterial, OperationRecord, OperationRecordItem
|
||||||
|
|
||||||
from apps.wpm.serializers import OperationWproductListSerializer, OperationCreateSerializer, OperationDetailSerializer, OperationListSerializer, PickHalfSerializer, PickSerializer, OperationInitSerializer, OperationSubmitSerializer, WMaterialListSerializer, WProductListSerializer, WplanPutInSerializer, WpmTestRecordCreateSerializer, WproductPutInSerializer
|
from apps.wpm.serializers import OperationEquipListSerializer, OperationEquipUpdateSerializer, OperationRecordListSerializer, OperationUpdateSerializer, OperationWproductListSerializer, OperationCreateSerializer, OperationDetailSerializer, OperationListSerializer, PickHalfSerializer, PickSerializer, OperationInitSerializer, OperationSubmitSerializer, WMaterialListSerializer, WProductListSerializer, WplanPutInSerializer, WpmTestRecordCreateSerializer, WproductPutInSerializer
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from rest_framework import exceptions, serializers
|
from rest_framework import exceptions, serializers
|
||||||
|
@ -259,12 +259,12 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
||||||
wproduct.save()
|
wproduct.save()
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, GenericViewSet):
|
class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, UpdateModelMixin, GenericViewSet):
|
||||||
"""
|
"""
|
||||||
生产操作记录
|
生产操作记录
|
||||||
"""
|
"""
|
||||||
perms_map={'*':'*'}
|
perms_map={'*':'*'}
|
||||||
queryset = Operation.objects.select_related('step').all()
|
queryset = Operation.objects.select_related('step').prefetch_related('ow_operation', 'oe_operation', 'or_operation').all()
|
||||||
serializer_class = OperationListSerializer
|
serializer_class = OperationListSerializer
|
||||||
filterset_fields = ['step', 'step__process', 'is_submited']
|
filterset_fields = ['step', 'step__process', 'is_submited']
|
||||||
ordering_fields = ['id']
|
ordering_fields = ['id']
|
||||||
|
@ -278,6 +278,8 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen
|
||||||
return OperationDetailSerializer
|
return OperationDetailSerializer
|
||||||
elif self.action == 'create':
|
elif self.action == 'create':
|
||||||
return OperationCreateSerializer
|
return OperationCreateSerializer
|
||||||
|
elif self.action == 'update':
|
||||||
|
return OperationUpdateSerializer
|
||||||
return super().get_serializer_class()
|
return super().get_serializer_class()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
@ -347,6 +349,50 @@ class OperationWproductViewSet(ListModelMixin, DestroyModelMixin, GenericViewSe
|
||||||
wp.save()
|
wp.save()
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
|
class OperationEquipViewSet(ListModelMixin, DestroyModelMixin, UpdateModelMixin, GenericViewSet):
|
||||||
|
"""
|
||||||
|
操作使用的设备
|
||||||
|
"""
|
||||||
|
perms_map={'*':'*'}
|
||||||
|
queryset = OperationEquip.objects.select_related('operation', 'equip').all()
|
||||||
|
serializer_class = OperationEquipListSerializer
|
||||||
|
filterset_fields = ['operation', 'equip']
|
||||||
|
ordering_fields = ['id']
|
||||||
|
ordering = ['-id']
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.action == 'update':
|
||||||
|
return OperationEquipUpdateSerializer
|
||||||
|
return super().get_serializer_class()
|
||||||
|
@transaction.atomic()
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
instance = self.get_object()
|
||||||
|
if instance.operation.is_submited:
|
||||||
|
raise exceptions.APIException('该操作已提交')
|
||||||
|
instance.delete()
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
class OperationRecordViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet):
|
||||||
|
"""
|
||||||
|
操作使用的自定义表格
|
||||||
|
"""
|
||||||
|
perms_map={'*':'*'}
|
||||||
|
queryset = OperationRecord.objects.select_related('operation', 'form').all()
|
||||||
|
serializer_class = OperationRecordListSerializer
|
||||||
|
filterset_fields = ['operation', 'form']
|
||||||
|
ordering_fields = ['id']
|
||||||
|
ordering = ['-id']
|
||||||
|
|
||||||
|
@transaction.atomic()
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
instance = self.get_object()
|
||||||
|
if instance.operation.is_submited:
|
||||||
|
raise exceptions.APIException('该操作已提交')
|
||||||
|
instance.delete()
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DoFormInit(CreateAPIView, GenericAPIView):
|
class DoFormInit(CreateAPIView, GenericAPIView):
|
||||||
perms_map={'*':'*'}
|
perms_map={'*':'*'}
|
||||||
|
|
Loading…
Reference in New Issue