Skip to content

Commit

Permalink
#17 采购模块 (#307)
Browse files Browse the repository at this point in the history
* 订购单界面的 供应商选择
两个接口重写

* 几个创建模块优化
  • Loading branch information
eyeeco authored and Time1ess committed Jan 24, 2018
1 parent 92b0e4c commit dc22403
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 10 deletions.
28 changes: 27 additions & 1 deletion Procurement/api/supplier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response

from Core.utils.pagination import SmallResultsSetPagination
from Procurement.models import (Supplier, SupplierDocument, Quotation,
Expand All @@ -12,6 +14,7 @@ class SupplierViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = Supplier.objects.all().order_by('-pk')
serializer_class = serializers.SupplierSerializer
filter_class = filters.SupplierFilter

def get_serializer_class(self):
if self.action == 'list':
Expand All @@ -21,6 +24,19 @@ def get_serializer_class(self):
else:
return serializers.SupplierSerializer

@list_route()
def bidding_sheet(self, request, *args, **kwargs):
queryset = self.get_queryset()
page = self.paginate_queryset(queryset)
context = self.get_serializer_context()
if page is not None:
serializer = serializers.SupplierBiddingListSerializer(
page, many=True, context=context)
return self.get_paginated_response(serializer.data)
serializer = serializers.SupplierBiddingListSerializer(
queryset, many=True, context=context)
return Response(serializer.data)


# 供应商文件
class SupplierDocumentViewSet(viewsets.ModelViewSet):
Expand All @@ -43,7 +59,17 @@ class SupplyRelationshipViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = SupplyRelationship.objects.all().order_by('-pk')
filter_class = filters.SupplyRelationshipFilter
serializer_class = serializers.BaseSupplyRelationshipSerializer

def get_serializer_class(self):
if self.action == 'create':
return serializers.SupplyRelationshipCreateSerializer
else:
return serializers.BaseSupplyRelationshipSerializer

@list_route()
def reset(self, request, *args, **kwargs):
self.filter_queryset(self.get_queryset()).delete()
return Response({'status': '供应商已重置'})


# 供应商审核
Expand Down
5 changes: 3 additions & 2 deletions Procurement/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .bidding import (BiddingSheetFilter, BiddingApplicationFilter)

from .supplier import (SupplyRelationshipFilter, SupplyDocumentFilter,
SupplyQuotationFilter)
SupplyQuotationFilter, SupplierFilter)

from .status_change import (StatusChangeFilter, )

Expand All @@ -19,4 +19,5 @@
'StatusChangeFilter', 'ProcurementMaterialFilter',
'MaterialSubApplyFilter', 'MaterialExcutionFilter',
'SupplyDocumentFilter', 'SupplyQuotationFilter',
'ContractDetailFilter', 'MaterialExecutionDetailFilter']
'ContractDetailFilter', 'MaterialExecutionDetailFilter',
'SupplierFilter']
10 changes: 8 additions & 2 deletions Procurement/filters/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ class SupplyRelationshipFilter(filters.FilterSet):
supplier_code = filters.CharFilter(name='supplier_code',
lookup_expr='icontains')
status = filters.CharFilter(name='status', lookup_expr='exact')
bidding_sheet = filters.CharFilter(name='bidding_sheet',
lookup_expr='icontains')
supplier = filters.CharFilter(name="supplier", lookup_expr='icontains')

class Meta:
model = models.SupplyRelationship
fields = ('status', 'bidding_sheet', 'supplier', 'supplier_code')


class SupplierFilter(filters.FilterSet):
uid = filters.CharFilter(name='uid', lookup_expr='icontains')

class Meta:
model = models.Supplier
fields = ('uid',)


class SupplyDocumentFilter(filters.FilterSet):

class Meta:
Expand Down
30 changes: 30 additions & 0 deletions Procurement/migrations/0013_auto_20180125_0023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2018-01-24 16:23
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Procurement', '0012_auto_20180122_2046'),
]

operations = [
migrations.AlterField(
model_name='biddingsheet',
name='status',
field=models.IntegerField(choices=[(0, '标单创建'), (1, '供应商选择'), (2, '招标申请选择'), (3, '招标申请填写'), (4, '招标中'), (5, '中标确认'), (6, '进程跟踪'), (7, '标单检验'), (8, '标单入库'), (9, '标单完成'), (10, '标单终止')], verbose_name='标单状态'),
),
migrations.AlterField(
model_name='supplyrelationship',
name='C',
field=models.IntegerField(blank=True, choices=[(0, '实体'), (1, '贸易')], null=True, verbose_name='C'),
),
migrations.AlterField(
model_name='supplyrelationship',
name='price',
field=models.FloatField(blank=True, null=True, verbose_name='价格'),
),
]
2 changes: 1 addition & 1 deletion Procurement/models/bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BiddingSheet(models.Model, metaclass=TransitionMeta):
# TODO: auto_now_add?
create_dt = models.DateTimeField(verbose_name='创建时间',
blank=True, null=True)
status = models.IntegerField(verbose_name='标单状态', unique=True,
status = models.IntegerField(verbose_name='标单状态',
choices=BIDDING_SHEET_STATUS_CHOICES)
contract_number = models.CharField(verbose_name='合同编号', max_length=50,
blank=True, default=gen_uuid)
Expand Down
5 changes: 3 additions & 2 deletions Procurement/models/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class SupplyRelationship(models.Model):
# TODO: what are these fields?
A = models.BooleanField(verbose_name='A', blank=True, default=False)
B = models.BooleanField(verbose_name='B', blank=True, default=False)
C = models.IntegerField(verbose_name='C', choices=SUPPLIER_REL_C_CHOICES)
C = models.IntegerField(verbose_name='C', choices=SUPPLIER_REL_C_CHOICES,
blank=True, null=True)
D = models.BooleanField(verbose_name='D', blank=True, default=False)
E = models.BooleanField(verbose_name='E', blank=True, default=False)
F = models.BooleanField(verbose_name='F', blank=True, default=False)
Expand All @@ -131,7 +132,7 @@ class SupplyRelationship(models.Model):
blank=True, default='')
supplier_code = models.CharField(verbose_name='供方代码', max_length=40,
blank=True, default='')
price = models.FloatField(verbose_name='价格')
price = models.FloatField(verbose_name='价格', blank=True, null=True)
status = models.CharField(verbose_name='厂家协作能力质量情况及业绩',
max_length=100, blank=True, default='')
delivery_payment = models.CharField(verbose_name='交货及支付条件',
Expand Down
6 changes: 4 additions & 2 deletions Procurement/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from .supplier import (
SupplierSerializer, SupplierDocumentSerializer, QuotationSerializer,
SupplierListSerializer, SupplierDetailSerializer,
BaseSupplyRelationshipSerializer, BaseSupplierCheckSerializer)
BaseSupplyRelationshipSerializer, BaseSupplierCheckSerializer,
SupplyRelationshipCreateSerializer, SupplierBiddingListSerializer)

from .bidding import (
BaseBiddingSheetSerializer, BiddingSheetListSerializer,
Expand Down Expand Up @@ -57,5 +58,6 @@
'BaseSupplierCheckSerializer', 'BaseProcessFollowingInfoSerializer',
'BaseArrivalInspectionSerializer', 'BaseParityRatioCardSerializer',
'BaseBiddingCommentSerializer', 'BaseDynamicFieldSerializer',
'BaseTransitionSerializer', 'ContractSerializer'
'BaseTransitionSerializer', 'ContractSerializer',
'SupplyRelationshipCreateSerializer', 'SupplierBiddingListSerializer'
]
45 changes: 45 additions & 0 deletions Procurement/serializers/supplier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers
from django.db import transaction

from Procurement.models import (Supplier, SupplierDocument, Quotation,
SupplyRelationship, SupplierCheck)
Expand Down Expand Up @@ -31,11 +32,16 @@ def get_doc_size(self, obj):
class QuotationSerializer(serializers.ModelSerializer):
pretty_inventory_type = serializers.CharField(
source='get_inventory_type_display')
price = serializers.SerializerMethodField(read_only=True)

class Meta:
model = Quotation
fields = '__all__'

def get_price(self, obj):
# TODO: 计算总价,较复杂
return 0


class SupplierListSerializer(SupplierSerializer):
docs = SupplierDocumentSerializer(read_only=True, many=True)
Expand All @@ -44,6 +50,21 @@ class Meta(SupplierSerializer.Meta):
fields = ('id', 'uid', 'name', 'docs')


class SupplierBiddingListSerializer(SupplierListSerializer):
selected = serializers.SerializerMethodField(read_only=True)

class Meta(SupplierListSerializer.Meta):
fields = ('id', 'uid', 'name', 'docs', 'selected')

def get_selected(self, obj):
selected = False
query = self.context['request'].query_params
if query and 'id' in query and SupplyRelationship.objects.filter(
supplier=obj, bidding_sheet_id=query['id']).count() > 0:
selected = True
return selected


class SupplierDetailSerializer(SupplierSerializer):
docs = SupplierDocumentSerializer(read_only=True, many=True)
quotations = QuotationSerializer(read_only=True, many=True)
Expand All @@ -62,6 +83,30 @@ class Meta:
'delivery_payment')


class SupplyRelationshipCreateSerializer(BaseSupplyRelationshipSerializer):
suppliers = serializers.ListField(
child=serializers.IntegerField(min_value=0,), write_only=True)

class Meta(BaseSupplyRelationshipSerializer.Meta):
fields = ('bidding_sheet', 'suppliers')

def validate_suppliers(self, value):
if len(value) != Supplier.objects.filter(
id__in=value).count():
raise serializers.ValidationError('列表中有未知标单ID')
return value

def create(self, validated_data):
with transaction.atomic():
suppliers = validated_data.pop('suppliers')
sup_list = []
for supplier in suppliers:
sup_list.append(SupplyRelationship(
supplier_id=supplier, **validated_data))
sup_object = SupplyRelationship.objects.bulk_create(sup_list)
return sup_object[0]


# 供应商审核
class BaseSupplierCheckSerializer(BaseTransitionSerializer):

Expand Down

0 comments on commit dc22403

Please sign in to comment.