From dc2240390481da02f6d2c9558dfd72a2a4158927 Mon Sep 17 00:00:00 2001 From: Eyeeco <1911362549@qq.com> Date: Wed, 24 Jan 2018 00:47:51 -0800 Subject: [PATCH] =?UTF-8?q?#17=20=E9=87=87=E8=B4=AD=E6=A8=A1=E5=9D=97=20(#?= =?UTF-8?q?307)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 订购单界面的 供应商选择 两个接口重写 * 几个创建模块优化 --- Procurement/api/supplier.py | 28 +++++++++++- Procurement/filters/__init__.py | 5 ++- Procurement/filters/supplier.py | 10 ++++- .../migrations/0013_auto_20180125_0023.py | 30 +++++++++++++ Procurement/models/bidding.py | 2 +- Procurement/models/supplier.py | 5 ++- Procurement/serializers/__init__.py | 6 ++- Procurement/serializers/supplier.py | 45 +++++++++++++++++++ 8 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 Procurement/migrations/0013_auto_20180125_0023.py diff --git a/Procurement/api/supplier.py b/Procurement/api/supplier.py index b7ed67a..ec6156f 100644 --- a/Procurement/api/supplier.py +++ b/Procurement/api/supplier.py @@ -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, @@ -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': @@ -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): @@ -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': '供应商已重置'}) # 供应商审核 diff --git a/Procurement/filters/__init__.py b/Procurement/filters/__init__.py index ee0e209..523e3dd 100644 --- a/Procurement/filters/__init__.py +++ b/Procurement/filters/__init__.py @@ -3,7 +3,7 @@ from .bidding import (BiddingSheetFilter, BiddingApplicationFilter) from .supplier import (SupplyRelationshipFilter, SupplyDocumentFilter, - SupplyQuotationFilter) + SupplyQuotationFilter, SupplierFilter) from .status_change import (StatusChangeFilter, ) @@ -19,4 +19,5 @@ 'StatusChangeFilter', 'ProcurementMaterialFilter', 'MaterialSubApplyFilter', 'MaterialExcutionFilter', 'SupplyDocumentFilter', 'SupplyQuotationFilter', - 'ContractDetailFilter', 'MaterialExecutionDetailFilter'] + 'ContractDetailFilter', 'MaterialExecutionDetailFilter', + 'SupplierFilter'] diff --git a/Procurement/filters/supplier.py b/Procurement/filters/supplier.py index 42d0b72..c0829eb 100644 --- a/Procurement/filters/supplier.py +++ b/Procurement/filters/supplier.py @@ -6,8 +6,6 @@ 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: @@ -15,6 +13,14 @@ class Meta: 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: diff --git a/Procurement/migrations/0013_auto_20180125_0023.py b/Procurement/migrations/0013_auto_20180125_0023.py new file mode 100644 index 0000000..b064c87 --- /dev/null +++ b/Procurement/migrations/0013_auto_20180125_0023.py @@ -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='价格'), + ), + ] diff --git a/Procurement/models/bidding.py b/Procurement/models/bidding.py index 5051573..89420e6 100644 --- a/Procurement/models/bidding.py +++ b/Procurement/models/bidding.py @@ -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) diff --git a/Procurement/models/supplier.py b/Procurement/models/supplier.py index 28191ba..479ce7d 100644 --- a/Procurement/models/supplier.py +++ b/Procurement/models/supplier.py @@ -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) @@ -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='交货及支付条件', diff --git a/Procurement/serializers/__init__.py b/Procurement/serializers/__init__.py index 2a2b843..e885ab8 100644 --- a/Procurement/serializers/__init__.py +++ b/Procurement/serializers/__init__.py @@ -19,7 +19,8 @@ from .supplier import ( SupplierSerializer, SupplierDocumentSerializer, QuotationSerializer, SupplierListSerializer, SupplierDetailSerializer, - BaseSupplyRelationshipSerializer, BaseSupplierCheckSerializer) + BaseSupplyRelationshipSerializer, BaseSupplierCheckSerializer, + SupplyRelationshipCreateSerializer, SupplierBiddingListSerializer) from .bidding import ( BaseBiddingSheetSerializer, BiddingSheetListSerializer, @@ -57,5 +58,6 @@ 'BaseSupplierCheckSerializer', 'BaseProcessFollowingInfoSerializer', 'BaseArrivalInspectionSerializer', 'BaseParityRatioCardSerializer', 'BaseBiddingCommentSerializer', 'BaseDynamicFieldSerializer', - 'BaseTransitionSerializer', 'ContractSerializer' + 'BaseTransitionSerializer', 'ContractSerializer', + 'SupplyRelationshipCreateSerializer', 'SupplierBiddingListSerializer' ] diff --git a/Procurement/serializers/supplier.py b/Procurement/serializers/supplier.py index 775a65f..24c745d 100644 --- a/Procurement/serializers/supplier.py +++ b/Procurement/serializers/supplier.py @@ -1,4 +1,5 @@ from rest_framework import serializers +from django.db import transaction from Procurement.models import (Supplier, SupplierDocument, Quotation, SupplyRelationship, SupplierCheck) @@ -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) @@ -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) @@ -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):