From 06d00218081780136fe3068420bb7c8ef6aaa4ea Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 24 Nov 2021 08:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E9=97=B4=E7=89=A9=E6=96=99=E5=A4=A7?= =?UTF-8?q?=E4=BA=8E0=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/pm/signals.py | 4 +++- hb_server/apps/pm/views.py | 2 +- .../0023_alter_operationmaterial_count.py | 19 +++++++++++++++++++ hb_server/apps/wpm/models.py | 2 +- hb_server/apps/wpm/serializers.py | 1 + hb_server/apps/wpm/views.py | 9 ++++++--- 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 hb_server/apps/wpm/migrations/0023_alter_operationmaterial_count.py diff --git a/hb_server/apps/pm/signals.py b/hb_server/apps/pm/signals.py index 6114b88..40bc5d3 100644 --- a/hb_server/apps/pm/signals.py +++ b/hb_server/apps/pm/signals.py @@ -13,8 +13,10 @@ def update_subplan_main(sender, instance, created, **kwargs): subplan.main_product = instance.material subplan.main_count = instance.count subplan.main_count_real = instance.count_real - if instance.count_real>= instance.count and instance.count_real != 0: + if instance.count_ok >= instance.count and instance.count_ok > 0: subplan.state = SubProductionPlan.SUBPLAN_STATE_DONE + elif instance.count_ok < instance.count and instance.count_ok > 0: + subplan.state = SubProductionPlan.SUBPLAN_STATE_WORKING subplan.save() diff --git a/hb_server/apps/pm/views.py b/hb_server/apps/pm/views.py index aa02784..145d577 100644 --- a/hb_server/apps/pm/views.py +++ b/hb_server/apps/pm/views.py @@ -176,7 +176,7 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo materials = [] for i in need: materials.append(i['material']) - objs = MaterialBatch.objects.filter(material__id__in=materials).order_by('material__number') + objs = MaterialBatch.objects.filter(material__id__in=materials, count_gt=0).order_by('material__number') have = MaterialBatchSerializer(instance=objs, many=True).data return Response({'need':need, 'have':have}) diff --git a/hb_server/apps/wpm/migrations/0023_alter_operationmaterial_count.py b/hb_server/apps/wpm/migrations/0023_alter_operationmaterial_count.py new file mode 100644 index 0000000..310a761 --- /dev/null +++ b/hb_server/apps/wpm/migrations/0023_alter_operationmaterial_count.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.9 on 2021-11-23 15:10 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0022_auto_20211123_1425'), + ] + + operations = [ + migrations.AlterField( + model_name='operationmaterial', + name='count', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='消耗或产出数量'), + ), + ] diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index db98eab..4a55447 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -75,7 +75,7 @@ class OperationMaterial(BaseModel): operation = models.ForeignKey(Operation, verbose_name='关联的生产操作', on_delete=models.CASCADE) material = models.ForeignKey(Material, verbose_name='可能产出的产品', on_delete=models.CASCADE, null=True, blank=True) - count = models.IntegerField('消耗或产出数量', validators=[MinValueValidator(0)]) + count = models.IntegerField('消耗或产出数量', validators=[MinValueValidator(0)], null=True, blank=True) wmaterial = models.ForeignKey(WMaterial, verbose_name='关联的车间物料', on_delete=models.CASCADE, null=True, blank=True) subproduction_progress = models.ForeignKey(SubProductionProgress, verbose_name='关联的生产进度', on_delete=models.CASCADE, null=True, blank=True) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index ed2850a..2c9e078 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -117,6 +117,7 @@ class WMaterialListSerializer(serializers.ModelSerializer): 车间物料 """ material_ = MaterialSimpleSerializer(source='material', read_only=True) + subproduction_plan_ = SubproductionPlanSimpleSerializer(source='subproduction_plan', read_only=True) class Meta: model = WMaterial fields = '__all__' diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index cdb81de..7a020cd 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -63,13 +63,15 @@ class WPlanViewSet(ListModelMixin, GenericViewSet): if 'wproducts' in i and len(i['wproducts'])>0: spp = SubProductionProgress.objects.get(pk=i['id']) spp.count_pick = spp.count_pick + len(i['wproducts']) - if spp.count_pick > spp.count: - raise exceptions.APIException('超过计划数') + # if spp.count_pick > spp.count: + # raise exceptions.APIException('超过计划数') spp.save() wps = WProduct.objects.filter(pk__in=[x for x in i['wproducts']]) wps.update(step=first_step, is_executed=False, act_state=WProduct.WPR_ACT_STATE_DOING, is_hidden=False, warehouse=None, subproduction_plan=sp, update_by=request.user, update_time=timezone.now()) + sp.is_picked = True + sp.save() return Response() @@ -137,7 +139,7 @@ class WMaterialViewSet(CreateUpdateModelAMixin, ListModelMixin, GenericViewSet): 车间物料表 """ perms_map={'*':'*'} - queryset = WMaterial.objects.select_related('material').all() + queryset = WMaterial.objects.select_related('material', 'subproduction_plan').filter(count_gt=0) serializer_class = WMaterialListSerializer filterset_class = WMaterialFilterSet ordering_fields = ['material__number'] @@ -313,6 +315,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd # 创建操作所用半成品关联记录 if 'wproducts' in vdata: owps = [] + WProduct.objects.filter(pk__in=[x.id for x in vdata['wproducts']]).update(operation=op) splans = WpmServies.get_subplans_queryset_from_wproducts(vdata['wproducts']) for wpd in vdata['wproducts']: owp = {}