Skip to content

Commit

Permalink
#17 [采购模块] 完成供应商和财务管理CRUD操作 (#166)
Browse files Browse the repository at this point in the history
* 供应商模块(供应商、供应商文件、供应商报价)
财务管理(以标单为主,合同金额明细模型)

* 外键复数
  • Loading branch information
eyeeco authored and Time1ess committed Dec 24, 2017
1 parent 4365cef commit a4e9736
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 18 deletions.
11 changes: 8 additions & 3 deletions Procurement/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
from .material_execution import (
MaterialExecutionViewSet, MaterialExecutionDetailViewSet,)

from .status_change import (
StatusChangeViewSet,)
from .status_change import (StatusChangeViewSet,)

from .supplier import (
SupplierViewSet, SupplierDocumentViewSet, QuotationViewSet,)

from .contact_detail import (ContractDetailViewSet,)

__all__ = [
'MaterialSubApplyViewSet', 'MaterialSubApplyItemViewSet',
'MaterialSubApplyCommentViewSet', 'MaterialExecutionViewSet',
'MaterialExecutionDetailViewSet', 'StatusChangeViewSet'
'MaterialExecutionDetailViewSet', 'StatusChangeViewSet', 'SupplierViewSet',
'SupplierDocumentViewSet', 'QuotationViewSet', 'ContractDetailViewSet'
]
14 changes: 14 additions & 0 deletions Procurement/api/contact_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import viewsets

from Core.utils.pagination import SmallResultsSetPagination
from Procurement.models import ContractDetail
from Procurement import serializers


class ContractDetailViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = ContractDetail.objects.all().order_by('-pk')
serializer_class = serializers.ContractDetailSerializer

def perform_create(self, serializer):
serializer.save(submitter=self.request.user,)
31 changes: 31 additions & 0 deletions Procurement/api/supplier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rest_framework import viewsets

from Core.utils.pagination import SmallResultsSetPagination
from Procurement.models import Supplier, SupplierDocument, Quotation
from Procurement import serializers


class SupplierViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = Supplier.objects.all().order_by('-pk')
serializer_class = serializers.SupplierSerializer

def get_serializer_class(self):
if self.action == 'list':
return serializers.SupplierListSerializer
elif self.action == "retrieve":
return serializers.SupplierDetailSerializer
else:
return serializers.SupplierSerializer


class SupplierDocumentViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = SupplierDocument.objects.all().order_by('-pk')
serializer_class = serializers.SupplierDocumentSerializer


class QuotationViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = Quotation.objects.all().order_by('-pk')
serializer_class = serializers.QuotationSerializer
26 changes: 26 additions & 0 deletions Procurement/migrations/0005_auto_20171225_0407.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-24 20:07
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('Procurement', '0004_auto_20171223_1959'),
]

operations = [
migrations.AlterField(
model_name='quotation',
name='supplier',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotations', to='Procurement.Supplier', verbose_name='供应商'),
),
migrations.AlterField(
model_name='supplierdocument',
name='supplier',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='docs', to='Procurement.Supplier', verbose_name='供应商'),
),
]
3 changes: 2 additions & 1 deletion Procurement/models/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class Quotation(models.Model):
unit = models.CharField(verbose_name='单位', max_length=50,
blank=True, null=True)
supplier = models.ForeignKey('Supplier', verbose_name='供应商',
on_delete=models.CASCADE)
on_delete=models.CASCADE,
related_name='quotations')

class Meta:
verbose_name = '报价单'
Expand Down
2 changes: 1 addition & 1 deletion Procurement/models/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SupplierDocument(models.Model):
供应商文件
"""
supplier = models.ForeignKey(Supplier, verbose_name='供应商',
on_delete=models.CASCADE)
on_delete=models.CASCADE, related_name='docs')
path = models.FileField(verbose_name='路径',
upload_to=DynamicHashPath('SupplierDocument'))
upload_dt = models.DateTimeField(verbose_name='上传时间',
Expand Down
12 changes: 11 additions & 1 deletion Procurement/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from .status_change import (
StatusChangeSerializer,)

from .supplier import (
SupplierSerializer, SupplierDocumentSerializer, QuotationSerializer,
SupplierListSerializer, SupplierDetailSerializer)

from .contact_detail import (
ContractDetailSerializer,)

__all__ = [
'MaterialSubApplySerializer', 'MaterialSubApplyListSerializer',
'MaterialSubApplyItemsSerializer',
Expand All @@ -20,5 +27,8 @@
'MaterialExecutionSerializer',
'MaterialExecutionDetailSerializer',
'MaterialExecutionListSerializer', 'MaterialExecutionCreateSerializer',
'StatusChangeSerializer', 'MaterialSubApplyUpdateSerializer'
'StatusChangeSerializer', 'MaterialSubApplyUpdateSerializer',
'SupplierSerializer', 'SupplierDocumentSerializer', 'QuotationSerializer',
'SupplierListSerializer', 'SupplierDetailSerializer',
'ContractDetailSerializer'
]
11 changes: 11 additions & 0 deletions Procurement/serializers/contact_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from rest_framework import serializers

from Procurement.models import ContractDetail


class ContractDetailSerializer(serializers.ModelSerializer):

class Meta:
model = ContractDetail
fields = '__all__'
read_only_fields = ('submitter',)
39 changes: 39 additions & 0 deletions Procurement/serializers/supplier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from rest_framework import serializers

from Procurement.models import Supplier, SupplierDocument, Quotation


class SupplierSerializer(serializers.ModelSerializer):

class Meta:
model = Supplier
fields = '__all__'


class SupplierDocumentSerializer(serializers.ModelSerializer):

class Meta:
model = SupplierDocument
fields = '__all__'


class QuotationSerializer(serializers.ModelSerializer):

class Meta:
model = Quotation
fields = '__all__'


class SupplierListSerializer(SupplierSerializer):
doc = SupplierDocumentSerializer(read_only=True, many=True)

class Meta(SupplierSerializer.Meta):
fields = '__all__'


class SupplierDetailSerializer(SupplierSerializer):
doc = SupplierDocumentSerializer(read_only=True, many=True)
quotation = QuotationSerializer(read_only=True, many=True)

class Meta(SupplierSerializer.Meta):
fields = '__all__'
24 changes: 12 additions & 12 deletions Procurement/urls.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from django.conf.urls import url, include

from rest_framework import routers
from Procurement.api import MaterialSubApplyViewSet
from Procurement.api import MaterialSubApplyItemViewSet
from Procurement.api import MaterialSubApplyCommentViewSet
from Procurement.api import MaterialExecutionViewSet
from Procurement.api import MaterialExecutionDetailViewSet
from Procurement.api import StatusChangeViewSet
from Procurement import api

router = routers.SimpleRouter()
router.register(r'material_sub_applies', MaterialSubApplyViewSet)
router.register(r'material_sub_apply_items', MaterialSubApplyItemViewSet)
router.register(r'sub_spply_comments', MaterialSubApplyCommentViewSet)
router.register(r'material_executions', MaterialExecutionViewSet)
router.register(r'material_execution_details', MaterialExecutionDetailViewSet)
router.register(r'status_changes', StatusChangeViewSet)
router.register(r'material_sub_applies', api.MaterialSubApplyViewSet)
router.register(r'material_sub_apply_items', api.MaterialSubApplyItemViewSet)
router.register(r'sub_spply_comments', api.MaterialSubApplyCommentViewSet)
router.register(r'material_executions', api.MaterialExecutionViewSet)
router.register(r'material_execution_details',
api.MaterialExecutionDetailViewSet)
router.register(r'status_changes', api.StatusChangeViewSet)
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)

urlpatterns = [
url(r'^api/', include(router.urls)),
Expand Down

0 comments on commit a4e9736

Please sign in to comment.