From 1d056a775f88284e71b0b796eae13496b9f9adcc Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 19 Oct 2021 09:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=90=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_client/.env.production | 4 +- hb_server/apps/hrm/views.py | 2 +- ...4_alter_recordformfield_rule_expression.py | 18 +++++++++ .../pm/migrations/0005_auto_20211019_0944.py | 38 +++++++++++++++++++ hb_server/apps/pm/models.py | 27 ++++++++++--- hb_server/apps/pm/serializers.py | 7 +++- hb_server/apps/pm/views.py | 17 +++++++-- 7 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 hb_server/apps/mtm/migrations/0024_alter_recordformfield_rule_expression.py create mode 100644 hb_server/apps/pm/migrations/0005_auto_20211019_0944.py diff --git a/hb_client/.env.production b/hb_client/.env.production index b79ed31..d214255 100644 --- a/hb_client/.env.production +++ b/hb_client/.env.production @@ -2,6 +2,6 @@ ENV = 'production' # base api -#VUE_APP_BASE_API = 'http://47.95.0.242:2222/api' -VUE_APP_BASE_API = 'http://127.0.0.1:8000/api' +VUE_APP_BASE_API = 'http://47.95.0.242:2222/api' +#VUE_APP_BASE_API = 'http://127.0.0.1:8000/api' diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 595285d..151fa06 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -85,7 +85,7 @@ class FaceLogin(CreateAPIView): unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0] os.remove(filepath) except: - logger.error('解码失败') + return Response('头像解码失败', status=status.HTTP_400_BAD_REQUEST) # 匹配人脸库 user_faces = Employee.objects.filter(face_data__isnull=False, user__is_active=True).values('user', 'face_data') diff --git a/hb_server/apps/mtm/migrations/0024_alter_recordformfield_rule_expression.py b/hb_server/apps/mtm/migrations/0024_alter_recordformfield_rule_expression.py new file mode 100644 index 0000000..f31fbc4 --- /dev/null +++ b/hb_server/apps/mtm/migrations/0024_alter_recordformfield_rule_expression.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.6 on 2021-10-19 01:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mtm', '0023_auto_20211018_1057'), + ] + + operations = [ + migrations.AlterField( + model_name='recordformfield', + name='rule_expression', + field=models.JSONField(default=list, help_text='判定表达式, 格式为[{"expression":"{value} > 3 and {value}<10"}] 其中{}用于填充的字段key,运算时会换算成实际的值,符合条件返回true,表达式只支持简单的运算或datetime/time运算.以首次匹配成功的条件为准,所以多个条件不要有冲突', verbose_name='判定表达式'), + ), + ] diff --git a/hb_server/apps/pm/migrations/0005_auto_20211019_0944.py b/hb_server/apps/pm/migrations/0005_auto_20211019_0944.py new file mode 100644 index 0000000..46824e4 --- /dev/null +++ b/hb_server/apps/pm/migrations/0005_auto_20211019_0944.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2.6 on 2021-10-19 01:44 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('mtm', '0024_alter_recordformfield_rule_expression'), + ('pm', '0004_subproductionplan_steps'), + ] + + operations = [ + migrations.AddField( + model_name='subproductionplan', + name='state', + field=models.IntegerField(default=0, verbose_name='状态'), + ), + migrations.CreateModel( + name='SubProductionProgress', + 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='删除标记')), + ('type', models.IntegerField(default=1, verbose_name='物料应用类型')), + ('count', models.IntegerField(verbose_name='应出入数')), + ('count_real', models.IntegerField(verbose_name='实际出入数')), + ('material', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mtm.material', verbose_name='关联物料')), + ('subproduction_plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='progress_subplan', to='pm.subproductionplan', verbose_name='关联子生产计划')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/hb_server/apps/pm/models.py b/hb_server/apps/pm/models.py index 5aab5f3..418e4dc 100644 --- a/hb_server/apps/pm/models.py +++ b/hb_server/apps/pm/models.py @@ -31,6 +31,13 @@ class SubProductionPlan(CommonAModel): """ 子生产计划 """ + state_choices=( + (0, '制定中'), + (1, '已下达'), + (2, '已接收'), + (3, '生产中'), + (4, '已完成') + ) production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE) subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE) start_date = models.DateField('计划开工日期') @@ -38,13 +45,21 @@ class SubProductionPlan(CommonAModel): workshop = models.ForeignKey(Organization, verbose_name='生产车间', on_delete=models.CASCADE) process = models.ForeignKey(Process, verbose_name='关联大工序', on_delete=models.CASCADE) steps = models.JSONField('工艺步骤', default=list) + state = models.IntegerField('状态', default=0) class Meta: verbose_name = '子生产计划' verbose_name_plural = verbose_name -# class ProductionProgress(BaseModel): -# """ -# 子计划生产进度 -# """ -# subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.CASCADE) -# material = models. \ No newline at end of file +class SubProductionProgress(BaseModel): + """ + 子计划生产进度统计表 + """ + type_choices=( + (1, '输入物料'), + (2, '输出物料') + ) + subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.CASCADE, related_name='progress_subplan') + material = models.ForeignKey(Material, verbose_name='关联物料', on_delete=models.CASCADE) + type = models.IntegerField('物料应用类型', default=1) + count = models.IntegerField('应出入数') + count_real = models.IntegerField('实际出入数') diff --git a/hb_server/apps/pm/serializers.py b/hb_server/apps/pm/serializers.py index 1950bce..7c79bc0 100644 --- a/hb_server/apps/pm/serializers.py +++ b/hb_server/apps/pm/serializers.py @@ -1,4 +1,4 @@ -from apps.pm.models import ProductionPlan, SubProductionPlan +from apps.pm.models import ProductionPlan, SubProductionPlan, SubProductionProgress from rest_framework import serializers from apps.sam.serializers import OrderSerializer from apps.mtm.serializers import MaterialSimpleSerializer, ProcessSimpleSerializer @@ -38,3 +38,8 @@ class SubProductionPlanUpdateSerializer(serializers.ModelSerializer): class GenSubPlanSerializer(serializers.Serializer): pass + +class SubProductionProgressSerializer(serializers.ModelSerializer): + material_ = MaterialSimpleSerializer(source='material', read_only=True) + class Meta: + model = SubProductionProgress \ No newline at end of file diff --git a/hb_server/apps/pm/views.py b/hb_server/apps/pm/views.py index a9856cd..4805099 100644 --- a/hb_server/apps/pm/views.py +++ b/hb_server/apps/pm/views.py @@ -2,11 +2,11 @@ from rest_framework import serializers from rest_framework.views import APIView from apps.em.models import Equipment from apps.em.serializers import EquipmentSerializer -from apps.mtm.models import InputMaterial, Step, SubProduction, UsedStep +from apps.mtm.models import InputMaterial, OutputMaterial, Step, SubProduction, UsedStep from apps.system.mixins import CreateUpdateModelAMixin -from apps.pm.serializers import GenSubPlanSerializer, ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer, ResourceCalListSerializer, ResourceCalSerializer, SubProductionPlanListSerializer, SubProductionPlanUpdateSerializer +from apps.pm.serializers import GenSubPlanSerializer, ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer, ResourceCalListSerializer, ResourceCalSerializer, SubProductionPlanListSerializer, SubProductionPlanUpdateSerializer, SubProductionProgressSerializer from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin -from apps.pm.models import ProductionPlan, SubProductionPlan +from apps.pm.models import ProductionPlan, SubProductionProgress, SubProductionPlan from rest_framework.viewsets import GenericViewSet, ModelViewSet from django.shortcuts import render from apps.sam.models import Order @@ -72,10 +72,14 @@ class ProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, CreateModel for i in subps: steps = Step.objects.filter(usedstep__subproduction=i, usedstep__subproduction__is_deleted=False, usedstep__is_deleted=False, is_deleted=False).values('id', 'number', 'name', 'usedstep__remark') - SubProductionPlan.objects.create(production_plan=production_plan, subproduction=i, + instance = SubProductionPlan.objects.create(production_plan=production_plan, subproduction=i, 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 InputMaterial.objects.filter(subproduction=i, is_delete=False).order_by('sort'): + SubProductionProgress.objects.create(material=m.material, type=1, count=m.count, subproduction_plan=instance) + for m in OutputMaterial.objects.filter(subproduction=i, is_delete=False).order_by('sort'): + SubProductionProgress.objects.create(material=m.material, type=2, count=m.count, subproduction_plan=instance) production_plan.is_planed=True production_plan.save() return Response() @@ -98,6 +102,11 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo return SubProductionPlanUpdateSerializer return SubProductionPlanListSerializer + @action(methods=['get'], detail=True, perms_map={'get':'*'}, serializer_class=SubProductionProgressSerializer) + def progress(self, request, pk=None): + obj = self.get_object() + serializer = SubProductionProgressSerializer(instance=obj.progress_subplan, many=True) + return Response(serializer.data) class ResourceViewSet(GenericViewSet):