-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重写合同金额部分
- Loading branch information
Showing
7 changed files
with
46 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters