Skip to content

Commit

Permalink
[#17]采购模块
Browse files Browse the repository at this point in the history
给文件字段增添了两个信息
重写了合同模块的计算
  • Loading branch information
eyeeco committed Jan 17, 2018
1 parent 1f07967 commit b8fbcdd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Procurement/api/contact_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
5 changes: 4 additions & 1 deletion Procurement/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
10 changes: 10 additions & 0 deletions Procurement/filters/contract_details.py
Original file line number Diff line number Diff line change
@@ -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', )
23 changes: 22 additions & 1 deletion Procurement/serializers/contact_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@

from Procurement.models import ContractDetail


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)
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
2 changes: 1 addition & 1 deletion Procurement/serializers/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions Procurement/serializers/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit b8fbcdd

Please sign in to comment.