From 5612c81cfd020bb64e01c72ebf03f93c313d1a9b Mon Sep 17 00:00:00 2001 From: eyeeco <1911362549@qq.com> Date: Thu, 18 Jan 2018 03:26:05 -0800 Subject: [PATCH] =?UTF-8?q?[#17]=20=E9=87=87=E8=B4=AD=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?=E9=87=8D=E5=86=99=E5=90=88=E5=90=8C=E9=87=91=E9=A2=9D=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Procurement/api/__init__.py | 5 +-- Procurement/api/contact_detail.py | 9 ++++- Procurement/serializers/__init__.py | 4 +-- Procurement/serializers/bidding.py | 4 +-- Procurement/serializers/contact_detail.py | 42 +++++++++++++++-------- Procurement/serializers/supplier.py | 3 +- Procurement/urls.py | 3 +- 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Procurement/api/__init__.py b/Procurement/api/__init__.py index 5e68e02..e419f3f 100644 --- a/Procurement/api/__init__.py +++ b/Procurement/api/__init__.py @@ -13,7 +13,7 @@ SupplierViewSet, SupplierDocumentViewSet, QuotationViewSet, SupplyRelationshipViewSet, SupplierCheckViewSet) -from .contact_detail import (ContractDetailViewSet,) +from .contact_detail import (ContractViewset, ContractDetailViewSet,) from .bidding import (BiddingSheetViewSet, BiddingApplicationViewSet, BiddingAcceptanceViewSet, ParityRatioCardViewSet) @@ -27,7 +27,8 @@ 'MaterialSubApplyCommentViewSet', 'MaterialExecutionViewSet', 'MaterialExecutionDetailViewSet', 'StatusChangeViewSet', 'SupplierViewSet', 'SupplierDocumentViewSet', 'SupplierCheckViewSet', - 'QuotationViewSet', 'ContractDetailViewSet', 'PurchaseOrderViewSet', + 'QuotationViewSet', 'ContractViewset', 'ContractDetailViewSet', + 'PurchaseOrderViewSet', 'ProcurementMaterialViewSet', 'BiddingSheetViewSet', 'BiddingApplicationViewSet', 'SupplyRelationshipViewSet', 'BiddingAcceptanceViewSet', 'ProcessFollowingInfoViewSet', diff --git a/Procurement/api/contact_detail.py b/Procurement/api/contact_detail.py index 022882a..621440d 100644 --- a/Procurement/api/contact_detail.py +++ b/Procurement/api/contact_detail.py @@ -1,11 +1,18 @@ from rest_framework import viewsets from Core.utils.pagination import SmallResultsSetPagination -from Procurement.models import ContractDetail +from Procurement.models import ContractDetail, BiddingSheet from Procurement import serializers from Procurement import filters +# 合同列表 +class ContractViewset(viewsets.ModelViewSet): + pagination_class = SmallResultsSetPagination + queryset = BiddingSheet.objects.all().order_by('-pk') + serializer_class = serializers.ContractSerializer + + # 合同金额明细 class ContractDetailViewSet(viewsets.ModelViewSet): pagination_class = SmallResultsSetPagination diff --git a/Procurement/serializers/__init__.py b/Procurement/serializers/__init__.py index 118e003..2a2b843 100644 --- a/Procurement/serializers/__init__.py +++ b/Procurement/serializers/__init__.py @@ -33,7 +33,7 @@ from .comment import (BaseBiddingCommentSerializer,) -from .contact_detail import (ContractDetailSerializer,) +from .contact_detail import (ContractSerializer, ContractDetailSerializer,) __all__ = [ 'MaterialSubApplySerializer', 'MaterialSubApplyListSerializer', @@ -57,5 +57,5 @@ 'BaseSupplierCheckSerializer', 'BaseProcessFollowingInfoSerializer', 'BaseArrivalInspectionSerializer', 'BaseParityRatioCardSerializer', 'BaseBiddingCommentSerializer', 'BaseDynamicFieldSerializer', - 'BaseTransitionSerializer', + 'BaseTransitionSerializer', 'ContractSerializer' ] diff --git a/Procurement/serializers/bidding.py b/Procurement/serializers/bidding.py index e3542cc..95a8438 100644 --- a/Procurement/serializers/bidding.py +++ b/Procurement/serializers/bidding.py @@ -6,7 +6,6 @@ # 标单 class BaseBiddingSheetSerializer(BaseTransitionSerializer): - purchase_order_uid = serializers.CharField(source='purchase_order.uid', read_only=True) @@ -18,10 +17,11 @@ class Meta: class BiddingSheetListSerializer(BaseBiddingSheetSerializer): + pretty_status = serializers.CharField(source='get_status_display') class Meta(BaseBiddingSheetSerializer.Meta): fields = ('id', 'uid', 'purchase_order', 'purchase_order_uid', - 'create_dt', 'status', 'category') + 'create_dt', 'status', 'category', 'pretty_status') # 标单申请表 diff --git a/Procurement/serializers/contact_detail.py b/Procurement/serializers/contact_detail.py index c383fe8..37cef77 100644 --- a/Procurement/serializers/contact_detail.py +++ b/Procurement/serializers/contact_detail.py @@ -1,38 +1,50 @@ from rest_framework import serializers from django.db.models import Sum -from Procurement.models import ContractDetail +from Procurement.models import ContractDetail, BiddingSheet -class ContractDetailSerializer(serializers.ModelSerializer): - contract_number = serializers.CharField( - source='bidding_sheet.contract_number', read_only=True) - contract_amount = serializers.FloatField( - source='bidding_sheet.contract_amount', read_only=True) - billing_amount = serializers.FloatField( - source='bidding_sheet.billing_amount', read_only=True) +class ContractSerializer(serializers.ModelSerializer): accept_supplier = serializers.CharField( - source='bidding_sheet.biddingacceptance.accept_supplier', + source='biddingacceptance.accept_supplier', read_only=True) content = serializers.CharField( - source='bidding_sheet.biddingacceptance.content', + source='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',) + model = BiddingSheet + fields = ('id', 'uid', 'contract_number', 'contract_amount', + 'billing_amount', 'accept_supplier', 'content', + 'prepaid_amount', 'payable_amount') @staticmethod def get_sum(obj): if not hasattr(obj, 'sum'): - obj.sum = obj.bidding_sheet.contractdetail_set.aggregate( + obj.sum = obj.contractdetail_set.aggregate( Sum('amount'))['amount__sum'] + if not obj.sum: + obj.sum = 0 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) + return obj.billing_amount - self.get_sum(obj) + + +class ContractDetailSerializer(serializers.ModelSerializer): + + class Meta: + model = ContractDetail + fields = '__all__' + read_only_fields = ('submitter',) + + def validate(self, data): + if data['amount'] <= data['bidding_sheet'].billing_amount -\ + ContractSerializer.get_sum(data['bidding_sheet']): + return data + else: + raise serializers.ValidationError("Amout out of Range!") diff --git a/Procurement/serializers/supplier.py b/Procurement/serializers/supplier.py index c43c0fa..775a65f 100644 --- a/Procurement/serializers/supplier.py +++ b/Procurement/serializers/supplier.py @@ -7,7 +7,6 @@ class SupplierSerializer(serializers.ModelSerializer): - class Meta: model = Supplier fields = '__all__' @@ -30,6 +29,8 @@ def get_doc_size(self, obj): class QuotationSerializer(serializers.ModelSerializer): + pretty_inventory_type = serializers.CharField( + source='get_inventory_type_display') class Meta: model = Quotation diff --git a/Procurement/urls.py b/Procurement/urls.py index dd1bdcb..d34071f 100644 --- a/Procurement/urls.py +++ b/Procurement/urls.py @@ -14,7 +14,8 @@ router.register(r'suppliers', api.SupplierViewSet) router.register(r'supplier_documents', api.SupplierDocumentViewSet) router.register(r'supplier_quotations', api.QuotationViewSet) -router.register(r'contact_details', api.ContractDetailViewSet) +router.register(r'contracts', api.ContractViewset) +router.register(r'contract_details', api.ContractDetailViewSet) router.register(r'purchase_orders', api.PurchaseOrderViewSet) router.register(r'procurement_materials', api.ProcurementMaterialViewSet) router.register(r'bidding_sheets', api.BiddingSheetViewSet)