diff --git a/Procurement/api/contact_detail.py b/Procurement/api/contact_detail.py index 0e01b91..3d8010d 100644 --- a/Procurement/api/contact_detail.py +++ b/Procurement/api/contact_detail.py @@ -3,13 +3,14 @@ from Core.utils.pagination import SmallResultsSetPagination from Procurement.models import ContractDetail from Procurement import serializers - +from Procurement import filters # 合同金额明细 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..13a0878 100644 --- a/Procurement/serializers/contact_detail.py +++ b/Procurement/serializers/contact_detail.py @@ -2,7 +2,6 @@ from Procurement.models import ContractDetail - class ContractDetailSerializer(serializers.ModelSerializer): contract_number = serializers.CharField( source='bidding_sheet.contract_number', read_only=True) @@ -10,8 +9,30 @@ 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',) + + def get_prepaid_amount(self,obj): + amount_sum = 0; + amount_set = ContractDetail.objects.filter( + bidding_sheet=obj.bidding_sheet) + for amount in amount_set: + amount_sum += amount.amount + return amount_sum + + def get_payable_amount(self, obj): + amount_sum = 0; + amount_set = ContractDetail.objects.filter( + bidding_sheet=obj.bidding_sheet) + for amount in amount_set: + amount_sum += amount.amount + return obj.bidding_sheet.billing_amount - amount_sum diff --git a/Procurement/serializers/material_execution.py b/Procurement/serializers/material_execution.py index 0172f6b..bc99b26 100644 --- a/Procurement/serializers/material_execution.py +++ b/Procurement/serializers/material_execution.py @@ -11,7 +11,7 @@ class MaterialExecutionDetailSerializer(serializers.ModelSerializer): class Meta: model = MaterialExecutionDetail fields = '__all__' - + read_only_fields = ('material_execution',) class MaterialExecutionSerializer(serializers.ModelSerializer): materialexecution = MaterialExecutionDetailSerializer(many=True) diff --git a/Procurement/serializers/supplier.py b/Procurement/serializers/supplier.py index b39282e..65648fe 100644 --- a/Procurement/serializers/supplier.py +++ b/Procurement/serializers/supplier.py @@ -14,11 +14,19 @@ 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):