Skip to content

Commit

Permalink
[#17]采购模块 (#280)
Browse files Browse the repository at this point in the history
* [#17] 采购模块
修改一个字段、给前端展示相应字段的中文

* flake8

* 为供应商文件和供应商报价单提供了filter

* flake8

* flake8

* [#17]采购模块
给文件字段增添了两个信息
重写了合同模块的计算

* bug

* 优化查询

* @staticmethod
  • Loading branch information
eyeeco authored and Time1ess committed Jan 17, 2018
1 parent f4c080e commit a44a052
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Procurement/api/contact_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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
@@ -1,5 +1,5 @@
from rest_framework import serializers

from django.db.models import Sum
from Procurement.models import ContractDetail


Expand All @@ -10,8 +10,29 @@ class ContractDetailSerializer(serializers.ModelSerializer):
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',)

@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)
1 change: 1 addition & 0 deletions Procurement/serializers/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MaterialExecutionDetailSerializer(serializers.ModelSerializer):
class Meta:
model = MaterialExecutionDetail
fields = '__all__'
read_only_fields = ('material_execution',)


class MaterialExecutionSerializer(serializers.ModelSerializer):
Expand Down
9 changes: 9 additions & 0 deletions Procurement/serializers/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ 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 a44a052

Please sign in to comment.