From a44a052f937cad5c4e75cac4f92b8da3198661fd Mon Sep 17 00:00:00 2001 From: Eyeeco <1911362549@qq.com> Date: Wed, 17 Jan 2018 04:28:20 -0800 Subject: [PATCH] =?UTF-8?q?[#17]=E9=87=87=E8=B4=AD=E6=A8=A1=E5=9D=97=20(#2?= =?UTF-8?q?80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#17] 采购模块 修改一个字段、给前端展示相应字段的中文 * flake8 * 为供应商文件和供应商报价单提供了filter * flake8 * flake8 * [#17]采购模块 给文件字段增添了两个信息 重写了合同模块的计算 * bug * 优化查询 * @staticmethod --- Procurement/api/contact_detail.py | 2 ++ Procurement/filters/__init__.py | 5 +++- Procurement/filters/contract_details.py | 10 ++++++++ Procurement/serializers/contact_detail.py | 23 ++++++++++++++++++- Procurement/serializers/material_execution.py | 1 + Procurement/serializers/supplier.py | 9 ++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Procurement/filters/contract_details.py diff --git a/Procurement/api/contact_detail.py b/Procurement/api/contact_detail.py index 0e01b91..022882a 100644 --- a/Procurement/api/contact_detail.py +++ b/Procurement/api/contact_detail.py @@ -3,6 +3,7 @@ from Core.utils.pagination import SmallResultsSetPagination from Procurement.models import ContractDetail from Procurement import serializers +from Procurement import filters # 合同金额明细 @@ -10,6 +11,7 @@ class ContractDetailViewSet(viewsets.ModelViewSet): pagination_class = SmallResultsSetPagination queryset = ContractDetail.objects.all().order_by('-pk') serializer_class = serializers.ContractDetailSerializer + filter_class = filters.ContractDetailFilter def perform_create(self, serializer): serializer.save(submitter=self.request.user,) diff --git a/Procurement/filters/__init__.py b/Procurement/filters/__init__.py index 51c9c5c..96f94f7 100644 --- a/Procurement/filters/__init__.py +++ b/Procurement/filters/__init__.py @@ -11,8 +11,11 @@ from .material_excution import (MaterialExcutionFilter, ) +from .contract_details import (ContractDetailFilter, ) + __all__ = ['PurchaseOrderFilter', 'BiddingSheetFilter', 'BiddingApplicationFilter', 'SupplyRelationshipFilter', 'StatusChangeFilter', 'ProcurementMaterialFilter', 'MaterialSubApplyFilter', 'MaterialExcutionFilter', - 'SupplyDocumentFilter', 'SupplyQuotationFilter'] + 'SupplyDocumentFilter', 'SupplyQuotationFilter', + 'ContractDetailFilter'] diff --git a/Procurement/filters/contract_details.py b/Procurement/filters/contract_details.py new file mode 100644 index 0000000..43f6052 --- /dev/null +++ b/Procurement/filters/contract_details.py @@ -0,0 +1,10 @@ +from django_filters import rest_framework as filters + +from Procurement.models import ContractDetail + + +class ContractDetailFilter(filters.FilterSet): + + class Meta: + model = ContractDetail + fields = ('bidding_sheet', ) diff --git a/Procurement/serializers/contact_detail.py b/Procurement/serializers/contact_detail.py index fbbbec2..c383fe8 100644 --- a/Procurement/serializers/contact_detail.py +++ b/Procurement/serializers/contact_detail.py @@ -1,5 +1,5 @@ from rest_framework import serializers - +from django.db.models import Sum from Procurement.models import ContractDetail @@ -10,8 +10,29 @@ class ContractDetailSerializer(serializers.ModelSerializer): source='bidding_sheet.contract_amount', read_only=True) billing_amount = serializers.FloatField( source='bidding_sheet.billing_amount', read_only=True) + accept_supplier = serializers.CharField( + source='bidding_sheet.biddingacceptance.accept_supplier', + read_only=True) + content = serializers.CharField( + source='bidding_sheet.biddingacceptance.content', + read_only=True) + prepaid_amount = serializers.SerializerMethodField(read_only=True) + payable_amount = serializers.SerializerMethodField(read_only=True) class Meta: model = ContractDetail fields = '__all__' read_only_fields = ('submitter',) + + @staticmethod + def get_sum(obj): + if not hasattr(obj, 'sum'): + obj.sum = obj.bidding_sheet.contractdetail_set.aggregate( + Sum('amount'))['amount__sum'] + return obj.sum + + def get_prepaid_amount(self, obj): + return self.get_sum(obj) + + def get_payable_amount(self, obj): + return obj.bidding_sheet.billing_amount - self.get_sum(obj) diff --git a/Procurement/serializers/material_execution.py b/Procurement/serializers/material_execution.py index 0172f6b..7943702 100644 --- a/Procurement/serializers/material_execution.py +++ b/Procurement/serializers/material_execution.py @@ -11,6 +11,7 @@ class MaterialExecutionDetailSerializer(serializers.ModelSerializer): class Meta: model = MaterialExecutionDetail fields = '__all__' + read_only_fields = ('material_execution',) class MaterialExecutionSerializer(serializers.ModelSerializer): diff --git a/Procurement/serializers/supplier.py b/Procurement/serializers/supplier.py index b39282e..c43c0fa 100644 --- a/Procurement/serializers/supplier.py +++ b/Procurement/serializers/supplier.py @@ -14,11 +14,20 @@ class Meta: class SupplierDocumentSerializer(serializers.ModelSerializer): + doc_name = serializers.SerializerMethodField(read_only=True) + doc_size = serializers.SerializerMethodField(read_only=True) class Meta: model = SupplierDocument fields = '__all__' + def get_doc_name(self, obj): + name = obj.path.name.split('/') + return name[-1] + + def get_doc_size(self, obj): + return obj.path.size + class QuotationSerializer(serializers.ModelSerializer):