消耗产出物料接口bug

This commit is contained in:
caoqianming 2021-11-22 16:13:36 +08:00
parent 0238e09d0a
commit 8666c13da8
7 changed files with 73 additions and 7 deletions

View File

@ -1,4 +1,5 @@
from django_filters import rest_framework as filters from django_filters import rest_framework as filters
from apps.mtm.models import Material, Step
from apps.pm.models import SubProductionProgress from apps.pm.models import SubProductionProgress
from apps.wpm.models import Operation, WProduct from apps.wpm.models import Operation, WProduct
@ -15,8 +16,12 @@ class SubproductionProgressFilterSet(filters.FilterSet):
def filter_operation(self, queryset, name, value): def filter_operation(self, queryset, name, value):
operation = Operation.objects.get(pk=value) operation = Operation.objects.get(pk=value)
wproducts = WProduct.objects.filter(ow_wproduct__operation=value) wproducts = WProduct.objects.filter(ow_wproduct__operation=value)
step = operation.step
if wproducts.exists(): if wproducts.exists():
subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts) subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts)
else: else:
subplans = WpmServies.get_subplans_queyset_from_step(operation.step) subplans = WpmServies.get_subplans_queyset_from_step(step)
return queryset.filter(subproduction_plan__in=subplans) queryset = queryset.filter(subproduction_plan__in=subplans)
if step.type == Step.STEP_TYPE_NOM:
queryset = queryset.exclude(material__type=Material.MA_TYPE_HALFGOOD)
return queryset

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.9 on 2021-11-22 07:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pm', '0014_subproductionplan_number'),
]
operations = [
migrations.AddField(
model_name='subproductionplan',
name='main_count_ok',
field=models.IntegerField(default=0, verbose_name='合格数'),
),
migrations.AddField(
model_name='subproductionprogress',
name='count_ok',
field=models.IntegerField(default=0, verbose_name='合格数量'),
),
]

View File

@ -56,6 +56,7 @@ class SubProductionPlan(CommonAModel):
main_product = models.ForeignKey(Material, verbose_name='主要产品', on_delete=models.CASCADE, null=True, blank=True) main_product = models.ForeignKey(Material, verbose_name='主要产品', on_delete=models.CASCADE, null=True, blank=True)
main_count = models.IntegerField('应产出数', default=0) main_count = models.IntegerField('应产出数', default=0)
main_count_real = models.IntegerField('实际产出数', default=0) main_count_real = models.IntegerField('实际产出数', default=0)
main_count_ok = models.IntegerField('合格数', default=0)
steps = models.JSONField('工艺步骤', default=list) steps = models.JSONField('工艺步骤', default=list)
@ -80,3 +81,4 @@ class SubProductionProgress(BaseModel):
count = models.IntegerField('应出入数') count = models.IntegerField('应出入数')
count_pick = models.IntegerField('实际领用数', default=0) count_pick = models.IntegerField('实际领用数', default=0)
count_real = models.IntegerField('实际消耗/产出数', default=0) count_real = models.IntegerField('实际消耗/产出数', default=0)
count_ok = models.IntegerField('合格数量', default=0)

View File

@ -1,5 +1,5 @@
from django_filters import rest_framework as filters from django_filters import rest_framework as filters
from apps.mtm.models import Step from apps.mtm.models import Material, Step
from apps.wpm.services import WpmServies from apps.wpm.services import WpmServies
from .models import Operation, WMaterial, WProduct from .models import Operation, WMaterial, WProduct
@ -19,7 +19,5 @@ class WMaterialFilterSet(filters.FilterSet):
subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts) subplans = WpmServies.get_subplans_queryset_from_wproducts(wproducts)
else: else:
subplans = WpmServies.get_subplans_queyset_from_step(step) subplans = WpmServies.get_subplans_queyset_from_step(step)
queryset = queryset.filter(subproduction_plan__in=subplans) queryset = queryset.filter(subproduction_plan__in=subplans).exclude(material__type=Material.MA_TYPE_HALFGOOD)
# if step.type == Step.STEP_TYPE_NOM:
# queryset = queryset.filter()
return queryset return queryset

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.9 on 2021-11-22 07:56
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wpm', '0019_auto_20211122_1110'),
]
operations = [
migrations.AlterField(
model_name='operationwproduct',
name='wproduct',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ow_wproduct', to='wpm.wproduct', verbose_name='关联半成品'),
),
]

View File

@ -326,12 +326,13 @@ class OperationMaterialCreate1Serailizer(serializers.ModelSerializer):
class Meta: class Meta:
model = OperationMaterial model = OperationMaterial
fields = ['operation', 'wmaterial', 'count'] fields = ['operation', 'wmaterial', 'count']
def create(self, validated_data): def create(self, validated_data):
wmaterial = validated_data['wmaterial'] wmaterial = validated_data['wmaterial']
validated_data['material'] = wmaterial.material validated_data['material'] = wmaterial.material
validated_data['subproduction_plan'] = wmaterial.subproduction_plan validated_data['subproduction_plan'] = wmaterial.subproduction_plan
validated_data['batch'] = wmaterial.batch validated_data['batch'] = wmaterial.batch
validated_data['type'] = SubprodctionMaterial.SUB_MA_TYPE_IN
return super().create(validated_data) return super().create(validated_data)
class OperationMaterialCreate2Serailizer(serializers.ModelSerializer): class OperationMaterialCreate2Serailizer(serializers.ModelSerializer):
@ -344,6 +345,7 @@ class OperationMaterialCreate2Serailizer(serializers.ModelSerializer):
subproduction_progress = validated_data['subproduction_progress'] subproduction_progress = validated_data['subproduction_progress']
validated_data['material'] = subproduction_progress.material validated_data['material'] = subproduction_progress.material
validated_data['subproduction_plan'] = subproduction_progress.subproduction_plan validated_data['subproduction_plan'] = subproduction_progress.subproduction_plan
validated_data['type'] = SubprodctionMaterial.SUB_MA_TYPE_OUT
return super().create(validated_data) return super().create(validated_data)
class OperationMaterialCreate3Serializer(serializers.ModelSerializer): class OperationMaterialCreate3Serializer(serializers.ModelSerializer):
@ -351,5 +353,9 @@ class OperationMaterialCreate3Serializer(serializers.ModelSerializer):
class Meta: class Meta:
model = OperationMaterial model = OperationMaterial
fields = ['operation', 'material'] fields = ['operation', 'material']
def create(self, validated_data):
validated_data['type'] = SubprodctionMaterial.SUB_MA_TYPE_TOOL
return super().create(validated_data)

View File

@ -349,6 +349,19 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
""" """
提交车间操作重要 提交车间操作重要
""" """
op = self.get_object()
# 更新物料消耗进度
for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_IN):
# 更新车间物料
i_wmat = i.wmaterial
i_wmat.count = i_wmat.count- i['count']
i_wmat.save()
# 更新子计划物料消耗情况
sp = i_wmat.subproduction_plan
sp.count_real = sp.count_real + i['count']
sp.save()
# 更新物料产出情况