-
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.
* [#17] 采购模块 重写合同金额部分 * 修改合同金额获得方式 * 合同金额优化
- Loading branch information
Showing
8 changed files
with
55 additions
and
35 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
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,37 @@ | ||
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_amounts = serializers.FloatField( | ||
source='prepaid_amount', | ||
read_only=True) | ||
payable_amounts = serializers.FloatField( | ||
source='payable_amount', | ||
read_only=True) | ||
prepaid_amount = serializers.SerializerMethodField(read_only=True) | ||
payable_amount = serializers.SerializerMethodField(read_only=True) | ||
|
||
class Meta: | ||
model = BiddingSheet | ||
fields = ('id', 'uid', 'contract_number', 'contract_amount', | ||
'billing_amount', 'accept_supplier', 'content', | ||
'prepaid_amounts', 'payable_amounts') | ||
|
||
|
||
class ContractDetailSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = ContractDetail | ||
fields = '__all__' | ||
read_only_fields = ('submitter',) | ||
|
||
@staticmethod | ||
def get_sum(obj): | ||
if not hasattr(obj, 'sum'): | ||
obj.sum = obj.bidding_sheet.contractdetail_set.aggregate( | ||
Sum('amount'))['amount__sum'] | ||
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) | ||
def validate(self, data): | ||
if data['amount'] <= data['bidding_sheet'].payable_amount: | ||
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