From c49bb54868c58cce76c1273e3be8ff6b7ebb9623 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 2 Nov 2021 17:08:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A1=A8=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mtm/migrations/0028_auto_20211102_1707.py | 40 +++++++++++++++++++ hb_server/apps/mtm/models.py | 4 +- hb_server/apps/mtm/serializers.py | 24 +++++------ hb_server/apps/mtm/views.py | 16 ++++---- hb_server/apps/pm/views.py | 4 +- 5 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 hb_server/apps/mtm/migrations/0028_auto_20211102_1707.py diff --git a/hb_server/apps/mtm/migrations/0028_auto_20211102_1707.py b/hb_server/apps/mtm/migrations/0028_auto_20211102_1707.py new file mode 100644 index 0000000..b20ad14 --- /dev/null +++ b/hb_server/apps/mtm/migrations/0028_auto_20211102_1707.py @@ -0,0 +1,40 @@ +# Generated by Django 3.2.6 on 2021-11-02 09:07 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('mtm', '0027_alter_recordformfield_need_judge'), + ] + + operations = [ + migrations.CreateModel( + name='SubprodctionMaterial', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')), + ('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')), + ('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')), + ('is_main', models.BooleanField(default=False, verbose_name='是否主产出')), + ('count', models.FloatField(default=0, verbose_name='消耗量/产出量')), + ('type', models.IntegerField(default=1, verbose_name='物料应用类型')), + ('sort', models.IntegerField(default=1, verbose_name='排序号')), + ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subprodctionmaterial_create_by', to=settings.AUTH_USER_MODEL, verbose_name='创建人')), + ('material', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subplan_material', to='mtm.material', verbose_name='物料')), + ('subproduction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mtm.subproduction', verbose_name='关联生产分解')), + ('update_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subprodctionmaterial_update_by', to=settings.AUTH_USER_MODEL, verbose_name='最后编辑人')), + ], + options={ + 'abstract': False, + }, + ), + migrations.DeleteModel( + name='SubplanMaterial', + ), + ] diff --git a/hb_server/apps/mtm/models.py b/hb_server/apps/mtm/models.py index a86784b..ce615ac 100644 --- a/hb_server/apps/mtm/models.py +++ b/hb_server/apps/mtm/models.py @@ -160,7 +160,7 @@ class SubProduction(CommonAModel): verbose_name = '产品生产工序' verbose_name_plural = verbose_name -class SubplanMaterial(CommonAModel): +class SubprodctionMaterial(CommonAModel): """ 输入/输出物料/工具工装 """ @@ -171,7 +171,7 @@ class SubplanMaterial(CommonAModel): ) material = models.ForeignKey(Material, verbose_name='物料', on_delete=models.CASCADE, related_name='subplan_material') is_main = models.BooleanField('是否主产出', default=False) # 以该产品完成度计算进度 - count = models.FloatField('消耗量/产出量', default=1) + count = models.FloatField('消耗量/产出量', default=0) subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE) type = models.IntegerField('物料应用类型', default=1) sort = models.IntegerField('排序号', default=1) diff --git a/hb_server/apps/mtm/serializers.py b/hb_server/apps/mtm/serializers.py index 21b549b..49f4b87 100644 --- a/hb_server/apps/mtm/serializers.py +++ b/hb_server/apps/mtm/serializers.py @@ -1,7 +1,7 @@ from apps.em.serializers import EquipmentSimpleSerializer from rest_framework import serializers from rest_framework.exceptions import ParseError, ValidationError -from .models import Material, Process, RecordForm, RecordFormField, Step, SubplanMaterial, TechDoc, UsedStep, SubProduction +from .models import Material, Process, RecordForm, RecordFormField, Step, SubprodctionMaterial, TechDoc, UsedStep, SubProduction from apps.system.serializers import FileSimpleSerializer, OrganizationSimpleSerializer @@ -69,53 +69,53 @@ class SubProductionSerializer(serializers.ModelSerializer): class OtherMaterialSerializer(serializers.ModelSerializer): class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = ['sort', 'material', 'subproduction'] def create(self, validated_data): - if SubplanMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=3).exists(): + if SubprodctionMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=3).exists(): raise ValidationError('该物料已存在') validated_data['type']=3 return super().create(validated_data) -class SubplanMaterialListSerializer(serializers.ModelSerializer): +class SubprodctionMaterialListSerializer(serializers.ModelSerializer): material_ = MaterialSimpleSerializer(source='material', read_only=True) class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = '__all__' class InputMaterialSerializer(serializers.ModelSerializer): class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = ['count', 'sort', 'material', 'subproduction'] def create(self, validated_data): - if SubplanMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=1).exists(): + if SubprodctionMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=1).exists(): raise ValidationError('该物料已存在') validated_data['type']=1 return super().create(validated_data) class InputMaterialUpdateSerializer(serializers.ModelSerializer): class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = ['count', 'sort'] class OutputMaterialSerializer(serializers.ModelSerializer): class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = ['count', 'sort', 'material', 'subproduction', 'is_main'] def create(self, validated_data): - if SubplanMaterial.objects.filter(subproduction=validated_data['subproduction'], is_deleted=False, is_main=True, type=2).exists(): + if SubprodctionMaterial.objects.filter(subproduction=validated_data['subproduction'], is_deleted=False, is_main=True, type=2).exists(): raise ValidationError('主产出只能有1个') - if SubplanMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=2).exists(): + if SubprodctionMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False, type=2).exists(): raise ValidationError('该物料已存在') validated_data['type']=2 return super().create(validated_data) class OutputMaterialUpdateSerializer(serializers.ModelSerializer): class Meta: - model = SubplanMaterial + model = SubprodctionMaterial fields = ['count', 'sort', 'is_main'] diff --git a/hb_server/apps/mtm/views.py b/hb_server/apps/mtm/views.py index 3dd563c..f657bde 100644 --- a/hb_server/apps/mtm/views.py +++ b/hb_server/apps/mtm/views.py @@ -2,8 +2,8 @@ from django.shortcuts import render from rest_framework.viewsets import ModelViewSet, GenericViewSet from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin, RetrieveModelMixin, DestroyModelMixin -from apps.mtm.models import Material, Process, RecordForm, RecordFormField, Step, SubplanMaterial, TechDoc, UsedStep, SubProduction -from apps.mtm.serializers import InputMaterialSerializer, InputMaterialUpdateSerializer, MaterialDetailSerializer, MaterialSerializer, MaterialSimpleSerializer, OtherMaterialSerializer, OutputMaterialSerializer, OutputMaterialUpdateSerializer, ProcessSerializer, RecordFormCreateSerializer, RecordFormDetailSerializer, RecordFormFieldCreateSerializer, RecordFormFieldSerializer, RecordFormFieldUpdateSerializer, RecordFormSerializer, RecordFormUpdateSerializer, StepDetailSerializer, StepSerializer, SubProductionSerializer, SubplanMaterialListSerializer, TechDocCreateSerializer, TechDocListSerializer, TechDocUpdateSerializer, UsedStepCreateSerializer, UsedStepListSerializer, UsedStepUpdateSerializer +from apps.mtm.models import Material, Process, RecordForm, RecordFormField, Step, SubprodctionMaterial, TechDoc, UsedStep, SubProduction +from apps.mtm.serializers import InputMaterialSerializer, InputMaterialUpdateSerializer, MaterialDetailSerializer, MaterialSerializer, MaterialSimpleSerializer, OtherMaterialSerializer, OutputMaterialSerializer, OutputMaterialUpdateSerializer, ProcessSerializer, RecordFormCreateSerializer, RecordFormDetailSerializer, RecordFormFieldCreateSerializer, RecordFormFieldSerializer, RecordFormFieldUpdateSerializer, RecordFormSerializer, RecordFormUpdateSerializer, StepDetailSerializer, StepSerializer, SubProductionSerializer, SubprodctionMaterialListSerializer, TechDocCreateSerializer, TechDocListSerializer, TechDocUpdateSerializer, UsedStepCreateSerializer, UsedStepListSerializer, UsedStepUpdateSerializer from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin from rest_framework.decorators import action from rest_framework.response import Response @@ -85,14 +85,14 @@ class InputMaterialViewSet(CreateUpdateModelAMixin, ModelViewSet): 输入物料-增删改查 """ perms_map = {'*':'*'} - queryset = SubplanMaterial.objects.select_related('material').filter(type=1) + queryset = SubprodctionMaterial.objects.select_related('material').filter(type=1) serializer_class = InputMaterialSerializer filterset_fields = ['subproduction'] ordering = ['sort', '-create_time'] def get_serializer_class(self): if self.action == 'list': - return SubplanMaterialListSerializer + return SubprodctionMaterialListSerializer elif self.action == 'update': return InputMaterialUpdateSerializer return InputMaterialSerializer @@ -102,14 +102,14 @@ class OutputMaterialViewSet(CreateUpdateModelAMixin, ModelViewSet): 输出物料-增删改查 """ perms_map = {'*':'*'} - queryset = SubplanMaterial.objects.select_related('material').filter(type=2) + queryset = SubprodctionMaterial.objects.select_related('material').filter(type=2) serializer_class = OutputMaterialSerializer filterset_fields = ['subproduction'] ordering = ['sort', '-create_time'] def get_serializer_class(self): if self.action == 'list': - return SubplanMaterialListSerializer + return SubprodctionMaterialListSerializer elif self.action == 'update': return OutputMaterialUpdateSerializer return OutputMaterialSerializer @@ -119,14 +119,14 @@ class OtherMaterialViewSet(CreateUpdateModelAMixin, ListModelMixin, DestroyModel 其他物料-增删改查 """ perms_map = {'*':'*'} - queryset = SubplanMaterial.objects.select_related('material').filter(type=3) + queryset = SubprodctionMaterial.objects.select_related('material').filter(type=3) serializer_class = OutputMaterialSerializer filterset_fields = ['subproduction'] ordering = ['sort', '-create_time'] def get_serializer_class(self): if self.action == 'list': - return SubplanMaterialListSerializer + return SubprodctionMaterialListSerializer return OtherMaterialSerializer class UsedStepViewSet(OptimizationMixin, CreateModelMixin, DestroyModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet): diff --git a/hb_server/apps/pm/views.py b/hb_server/apps/pm/views.py index 2e649ba..9fc474d 100644 --- a/hb_server/apps/pm/views.py +++ b/hb_server/apps/pm/views.py @@ -5,7 +5,7 @@ from apps.em.models import Equipment from apps.em.serializers import EquipmentSerializer from apps.inm.models import MaterialBatch from apps.inm.serializers import MaterialBatchSerializer -from apps.mtm.models import Step, SubProduction, UsedStep +from apps.mtm.models import Step, SubProduction, SubprodctionMaterial, UsedStep from apps.system.mixins import CreateUpdateModelAMixin from apps.pm.serializers import GenSubPlanSerializer, PickNeedSerializer, PlanDestorySerializer, ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer, ResourceCalListSerializer, ResourceCalSerializer, SubProductionPlanListSerializer, SubProductionPlanUpdateSerializer, SubProductionProgressSerializer from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin @@ -87,7 +87,7 @@ class ProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, CreateModel start_date=production_plan.start_date, end_date=production_plan.end_date, workshop=i.process.workshop, process=i.process, create_by=request.user, steps = list(steps)) - for m in SubProduction.objects.filter(subproduction=i, is_deleted=False).order_by('sort'): + for m in SubprodctionMaterial.objects.filter(subproduction=i, is_deleted=False).order_by('sort'): SubProductionProgress.objects.create(material=m.material, type=m.type, count=m.count*production_plan.count, subproduction_plan=instance) production_plan.is_planed=True production_plan.save()