From 7a1357f372b624d0518e8000a7093f7ef6f61bb5 Mon Sep 17 00:00:00 2001 From: Eyeeco <1911362549@qq.com> Date: Thu, 18 Jan 2018 17:06:44 -0800 Subject: [PATCH] =?UTF-8?q?[#17]=20=E9=87=87=E8=B4=AD=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?(#293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#17] 采购模块 重写合同金额部分 * 修改合同金额获得方式 * 合同金额优化 * 修改了一个模型字段 * [#17]采购模块 重写了材料执行部分 * 修改命名 --- Procurement/api/material_execution.py | 4 +- Procurement/filters/__init__.py | 5 ++- Procurement/filters/material_excution.py | 7 ++++ Procurement/filters/procurement.py | 2 +- .../migrations/0009_auto_20180119_1656.py | 25 +++++++++++ Procurement/models/execution.py | 6 +-- Procurement/models/procurement.py | 10 ++++- Procurement/serializers/material_execution.py | 42 ++++++++++++++----- 8 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 Procurement/migrations/0009_auto_20180119_1656.py diff --git a/Procurement/api/material_execution.py b/Procurement/api/material_execution.py index 848eec6..5490587 100644 --- a/Procurement/api/material_execution.py +++ b/Procurement/api/material_execution.py @@ -24,6 +24,6 @@ def get_serializer_class(self): # 材料执行表明细 class MaterialExecutionDetailViewSet(viewsets.ModelViewSet): pagination_class = SmallResultsSetPagination - queryset = MaterialExecutionDetail.objects.all().filter( - material_execution=None).order_by('-pk') + queryset = MaterialExecutionDetail.objects.all().order_by('-pk') serializer_class = serializers.MaterialExecutionDetailSerializer + filter_class = filters.MaterialExecutionDetailFilter diff --git a/Procurement/filters/__init__.py b/Procurement/filters/__init__.py index 96f94f7..ee0e209 100644 --- a/Procurement/filters/__init__.py +++ b/Procurement/filters/__init__.py @@ -9,7 +9,8 @@ from .materialsub import (MaterialSubApplyFilter, ) -from .material_excution import (MaterialExcutionFilter, ) +from .material_excution import (MaterialExcutionFilter, + MaterialExecutionDetailFilter) from .contract_details import (ContractDetailFilter, ) @@ -18,4 +19,4 @@ 'StatusChangeFilter', 'ProcurementMaterialFilter', 'MaterialSubApplyFilter', 'MaterialExcutionFilter', 'SupplyDocumentFilter', 'SupplyQuotationFilter', - 'ContractDetailFilter'] + 'ContractDetailFilter', 'MaterialExecutionDetailFilter'] diff --git a/Procurement/filters/material_excution.py b/Procurement/filters/material_excution.py index 93e9f8c..eda7933 100644 --- a/Procurement/filters/material_excution.py +++ b/Procurement/filters/material_excution.py @@ -9,3 +9,10 @@ class MaterialExcutionFilter(filters.FilterSet): class Meta: model = models.MaterialExecution fields = ('uid',) + + +# 根据材料执行表模糊查询 +class MaterialExecutionDetailFilter(filters.FilterSet): + class Meta: + model = models.MaterialExecutionDetail + fields = ('material_execution',) diff --git a/Procurement/filters/procurement.py b/Procurement/filters/procurement.py index c72b02b..f0cbfc1 100644 --- a/Procurement/filters/procurement.py +++ b/Procurement/filters/procurement.py @@ -21,4 +21,4 @@ class ProcurementMaterialFilter(filters.FilterSet): class Meta: model = ProcurementMaterial - fields = ('purchase_order',) + fields = ('purchase_order', 'status') diff --git a/Procurement/migrations/0009_auto_20180119_1656.py b/Procurement/migrations/0009_auto_20180119_1656.py new file mode 100644 index 0000000..910c719 --- /dev/null +++ b/Procurement/migrations/0009_auto_20180119_1656.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2018-01-19 08:56 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('Procurement', '0008_auto_20180118_2250'), + ] + + operations = [ + migrations.RemoveField( + model_name='materialexecutiondetail', + name='batch_number', + ), + migrations.AlterField( + model_name='materialexecutiondetail', + name='material_execution', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='execution_details', to='Procurement.MaterialExecution', verbose_name='材料执行表'), + ), + ] diff --git a/Procurement/models/execution.py b/Procurement/models/execution.py index 54bea84..1ca47c6 100644 --- a/Procurement/models/execution.py +++ b/Procurement/models/execution.py @@ -33,13 +33,11 @@ class MaterialExecutionDetail(models.Model): material_execution = models.ForeignKey(MaterialExecution, verbose_name='材料执行表', null=True, blank=True, - related_name='materialexecution', + related_name='execution_details', on_delete=models.SET_NULL) material = models.ForeignKey('ProcurementMaterial', verbose_name='物料', related_name='material', on_delete=models.CASCADE) - batch_number = models.CharField(verbose_name='出厂批号', max_length=50, - null=True, blank=True) quota = models.CharField(verbose_name='定额', max_length=50, null=True, blank=True) part = models.CharField(verbose_name='零件', max_length=50, @@ -54,4 +52,4 @@ class Meta: verbose_name_plural = '材料执行表明细' def __str__(self): - return '{}-{}'.format(self.material_execution, self.materiel) + return '{}-{}'.format(self.material_execution, self.material) diff --git a/Procurement/models/procurement.py b/Procurement/models/procurement.py index 6806aed..60bb6e5 100644 --- a/Procurement/models/procurement.py +++ b/Procurement/models/procurement.py @@ -10,7 +10,9 @@ PURCHASE_ORDER_STATUS_AUDIT, PURCHASE_ORDER_STATUS_APPROVED, PURCHASE_ORDER_STATUS_FINISH) from Procurement import ( - PROCUREMENT_MATERIAL_WAITED, PROCUREMENT_MATERIAL_STATUS) + PROCUREMENT_MATERIAL_WAITED, PROCUREMENT_MATERIAL_STATUS, + PROCUREMENT_MATERIAL_ADDED_EXECUTION, + PROCUREMENT_MATERIAL_EXECUTION_FINISHED) from Core.utils.fsm import transition, TransitionMeta @@ -127,5 +129,11 @@ class Meta: verbose_name = '采购物料' verbose_name_plural = '采购物料' + @transition( + field='status', source=PROCUREMENT_MATERIAL_ADDED_EXECUTION, + target=PROCUREMENT_MATERIAL_EXECUTION_FINISHED, name='材料执行完成') + def material_execution_finished(self, request): + pass + def __str__(self): return '{} {}'.format(self.sub_order_id, self.process_material_id) diff --git a/Procurement/serializers/material_execution.py b/Procurement/serializers/material_execution.py index 7943702..90124a4 100644 --- a/Procurement/serializers/material_execution.py +++ b/Procurement/serializers/material_execution.py @@ -2,11 +2,29 @@ from django.db import transaction from Procurement.models import MaterialExecution, MaterialExecutionDetail -from Procurement.serializers import ProcurementMaterialReadSerializer class MaterialExecutionDetailSerializer(serializers.ModelSerializer): - material = ProcurementMaterialReadSerializer(read_only=True) + execution_uid = serializers.CharField( + source='material_execution.uid', read_only=True) + execution_type = serializers.CharField( + source='material_execution.material_type', read_only=True) + sub_order = serializers.CharField( + source='material.sub_order', read_only=True) + batch_number = serializers.CharField( + source='material.batch_number', read_only=True) + material_name = serializers.CharField( + source='material.process_material.material.name', read_only=True) + material_uid = serializers.CharField( + source='material.process_material.material.uid', read_only=True) + material_category = serializers.CharField( + source='material.process_material.material.category', read_only=True) + count = serializers.CharField( + source='material.count', read_only=True) + weight = serializers.CharField( + source='material.weight', read_only=True) + spec = serializers.CharField( + source='material.process_material.spec', read_only=True) class Meta: model = MaterialExecutionDetail @@ -15,7 +33,6 @@ class Meta: class MaterialExecutionSerializer(serializers.ModelSerializer): - materialexecution = MaterialExecutionDetailSerializer(many=True) class Meta: model = MaterialExecution @@ -23,23 +40,28 @@ class Meta: class MaterialExecutionCreateSerializer(serializers.ModelSerializer): - details = serializers.ListField( - child=serializers.IntegerField(), write_only=True) + execution_details = MaterialExecutionDetailSerializer(many=True) class Meta(MaterialExecutionSerializer.Meta): model = MaterialExecution fields = '__all__' - read_only_fields = ('lister',) + read_only_fields = ('lister', 'list_dt') def create(self, validated_data): with transaction.atomic(): - id_array = validated_data.pop('details') + detail_list = validated_data.pop('execution_details') m_excution = MaterialExecution(lister=self.context['request'].user, **validated_data) m_excution.save() - MaterialExecutionDetail.objects.filter( - id__in=id_array).update(material_execution=m_excution) - return m_excution + array = [] + request = self.context['request'] + for detail in detail_list: + array.append(MaterialExecutionDetail( + material_execution=m_excution, **detail)) + detail['material'].material_execution_finished(request) + detail['material'].save() + MaterialExecutionDetail.objects.bulk_create(array) + return m_excution class MaterialExecutionListSerializer(MaterialExecutionSerializer):