Skip to content

Commit

Permalink
[#17] 采购模块
Browse files Browse the repository at this point in the history
重写合同金额部分
  • Loading branch information
eyeeco committed Jan 18, 2018
1 parent a44a052 commit 5612c81
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Procurement/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -27,7 +27,8 @@
'MaterialSubApplyCommentViewSet', 'MaterialExecutionViewSet',
'MaterialExecutionDetailViewSet', 'StatusChangeViewSet', 'SupplierViewSet',
'SupplierDocumentViewSet', 'SupplierCheckViewSet',
'QuotationViewSet', 'ContractDetailViewSet', 'PurchaseOrderViewSet',
'QuotationViewSet', 'ContractViewset', 'ContractDetailViewSet',
'PurchaseOrderViewSet',
'ProcurementMaterialViewSet', 'BiddingSheetViewSet',
'BiddingApplicationViewSet', 'SupplyRelationshipViewSet',
'BiddingAcceptanceViewSet', 'ProcessFollowingInfoViewSet',
Expand Down
9 changes: 8 additions & 1 deletion Procurement/api/contact_detail.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Procurement/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from .comment import (BaseBiddingCommentSerializer,)

from .contact_detail import (ContractDetailSerializer,)
from .contact_detail import (ContractSerializer, ContractDetailSerializer,)

__all__ = [
'MaterialSubApplySerializer', 'MaterialSubApplyListSerializer',
Expand All @@ -57,5 +57,5 @@
'BaseSupplierCheckSerializer', 'BaseProcessFollowingInfoSerializer',
'BaseArrivalInspectionSerializer', 'BaseParityRatioCardSerializer',
'BaseBiddingCommentSerializer', 'BaseDynamicFieldSerializer',
'BaseTransitionSerializer',
'BaseTransitionSerializer', 'ContractSerializer'
]
4 changes: 2 additions & 2 deletions Procurement/serializers/bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# 标单
class BaseBiddingSheetSerializer(BaseTransitionSerializer):

purchase_order_uid = serializers.CharField(source='purchase_order.uid',
read_only=True)

Expand All @@ -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')


# 标单申请表
Expand Down
42 changes: 27 additions & 15 deletions Procurement/serializers/contact_detail.py
Original file line number Diff line number Diff line change
@@ -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!")
3 changes: 2 additions & 1 deletion Procurement/serializers/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class SupplierSerializer(serializers.ModelSerializer):

class Meta:
model = Supplier
fields = '__all__'
Expand 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
Expand Down
3 changes: 2 additions & 1 deletion Procurement/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5612c81

Please sign in to comment.