Skip to content

Commit

Permalink
[#17] 采购模块 (#283)
Browse files Browse the repository at this point in the history
* [#17] 采购模块
重写合同金额部分

* 修改合同金额获得方式

* 合同金额优化
  • Loading branch information
eyeeco authored and Time1ess committed Jan 18, 2018
1 parent a44a052 commit b920d27
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 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
13 changes: 12 additions & 1 deletion Procurement/models/bidding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models

from django.db.models import Sum
from Core.utils import gen_uuid
from Procurement import (BIDDING_SHEET_STATUS_CHOICES, COMMENT_STATUS_CHOICES,
IMPLEMENT_CLASS_CHOICES)
Expand Down Expand Up @@ -59,6 +59,17 @@ class Meta:
def __str__(self):
return self.uid

@property
def prepaid_amount(self):
if not hasattr(self, '__prepaid_amount'):
self.__prepaid_amount = self.contractdetail_set.aggregate(
Sum('amount'))['amount__sum'] or 0
return self.__prepaid_amount

@property
def payable_amount(self):
return self.billing_amount - self.prepaid_amount

@transition(field='status', source=BIDDING_SHEET_STATUS_CREATE,
target=BIDDING_SHEET_STATUS_SELECT_SUPPLLER_APPROVED)
def select_supplier_approved():
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
49 changes: 24 additions & 25 deletions Procurement/serializers/contact_detail.py
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!")
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 b920d27

Please sign in to comment.