Skip to content

Commit

Permalink
#17 [采购模块] (#224)
Browse files Browse the repository at this point in the history
* 增加了材料执行中的物料字段
为状态回溯写了对应的标单查询
增加了几行代码注释

* 状态修改(创建状态转移表)时修改对应标单状态
用filters去筛选标单状态列表

* delete migrations
  • Loading branch information
eyeeco authored and Time1ess committed Dec 30, 2017
1 parent 6dd0773 commit 5cb0875
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 10 deletions.
1 change: 1 addition & 0 deletions Procurement/api/contact_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Procurement import serializers


# 合同金额明细
class ContractDetailViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = ContractDetail.objects.all().order_by('-pk')
Expand Down
2 changes: 2 additions & 0 deletions Procurement/api/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Procurement import serializers


# 材料执行表
class MaterialExecutionViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialExecution.objects.all().order_by('-pk')
Expand All @@ -18,6 +19,7 @@ def get_serializer_class(self):
return serializers.MaterialExecutionSerializer


# 材料执行表明细
class MaterialExecutionDetailViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialExecutionDetail.objects.all().filter(
Expand Down
3 changes: 3 additions & 0 deletions Procurement/api/materialsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Procurement import serializers


# 材料代用申请单
class MaterialSubApplyViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialSubApply.objects.all().order_by('-pk')
Expand All @@ -23,6 +24,7 @@ def destroy(self, request, pk=None):
raise MethodNotAllowed(request.method)


# 材料代用申请单明细
class MaterialSubApplyItemViewSet(viewsets.ModelViewSet):
queryset = MaterialSubApplyItems.objects.all().order_by('-pk')

Expand All @@ -33,6 +35,7 @@ def get_serializer_class(self):
return serializers.MaterialSubApplyItemsSerializer


# 材料代用申请单评论
class MaterialSubApplyCommentViewSet(viewsets.ModelViewSet):
queryset = SubApplyComment.objects.all().order_by('-pk')
serializer_class = serializers.MaterialSubApplyCommentsSerializer
Expand Down
6 changes: 3 additions & 3 deletions Procurement/api/status_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from Core.utils.pagination import SmallResultsSetPagination
from Procurement.models import StatusChange
from Procurement import serializers
from Procurement import filters


# 状态回溯
class StatusChangeViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = StatusChange.objects.all().order_by('-pk')
serializer_class = serializers.StatusChangeSerializer

def perform_create(self, serializer):
serializer.save(change_user=self.request.user, normal_change=False)
filter_class = filters.StatusChangeFilter
3 changes: 3 additions & 0 deletions Procurement/api/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Procurement import filters


# 供应商
class SupplierViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = Supplier.objects.all().order_by('-pk')
Expand All @@ -21,12 +22,14 @@ def get_serializer_class(self):
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')
Expand Down
5 changes: 4 additions & 1 deletion Procurement/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

from .supplier import (SupplyRelationshipFilter, )

from .status_change import (StatusChangeFilter, )

__all__ = ['PurchaseOrderFilter', 'BiddingSheetFilter',
'BiddingApplicationFilter', 'SupplyRelationshipFilter']
'BiddingApplicationFilter', 'SupplyRelationshipFilter',
'StatusChangeFilter']
10 changes: 10 additions & 0 deletions Procurement/filters/status_change.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 StatusChange


class StatusChangeFilter(filters.FilterSet):

class Meta:
model = StatusChange
fields = ('bidding_sheet', )
31 changes: 31 additions & 0 deletions Procurement/migrations/0007_auto_20171230_1819.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-30 10:19
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

dependencies = [
('Procurement', '0006_auto_20171229_1100'),
]

operations = [
migrations.AlterField(
model_name='materialexecutiondetail',
name='material',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='material', to='Procurement.ProcurementMaterial', verbose_name='物料'),
),
migrations.AlterField(
model_name='statuschange',
name='new_status',
field=models.IntegerField(choices=[(0, '标单创建'), (1, '供应商选择'), (2, '招标申请选择'), (3, '招标申请填写'), (4, '招标中'), (5, '中标确认'), (6, '进程跟踪'), (7, '标单检验'), (8, '标单入库'), (9, '标单完成'), (10, '标单终止')], verbose_name='标单状态'),
),
migrations.AlterField(
model_name='statuschange',
name='original_status',
field=models.IntegerField(choices=[(0, '标单创建'), (1, '供应商选择'), (2, '招标申请选择'), (3, '招标申请填写'), (4, '招标中'), (5, '中标确认'), (6, '进程跟踪'), (7, '标单检验'), (8, '标单入库'), (9, '标单完成'), (10, '标单终止')], verbose_name='标单状态'),
),
]
1 change: 1 addition & 0 deletions Procurement/models/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MaterialExecutionDetail(models.Model):
related_name='materialexecution',
on_delete=models.SET_NULL)
material = models.ForeignKey('ProcurementMaterial', verbose_name='物料',
related_name='material',
on_delete=models.CASCADE)
batch_number = models.CharField(verbose_name='出厂批号', max_length=50,
null=True, blank=True)
Expand Down
4 changes: 2 additions & 2 deletions Procurement/models/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class StatusChange(models.Model):
"""
bidding_sheet = models.ForeignKey('BiddingSheet', verbose_name='标单',
on_delete=models.CASCADE)
original_status = models.IntegerField(verbose_name='标单状态', unique=True,
original_status = models.IntegerField(verbose_name='标单状态',
choices=BIDDING_SHEET_STATUS_CHOICES)
new_status = models.IntegerField(verbose_name='标单状态', unique=True,
new_status = models.IntegerField(verbose_name='标单状态',
choices=BIDDING_SHEET_STATUS_CHOICES)
change_user = models.ForeignKey(User, verbose_name='更改用户',
on_delete=models.CASCADE)
Expand Down
6 changes: 2 additions & 4 deletions Procurement/serializers/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
from django.db import transaction

from Procurement.models import MaterialExecution, MaterialExecutionDetail
from Procurement.serializers import ProcurementMaterialReadSerializer


class MaterialExecutionDetailSerializer(serializers.ModelSerializer):
material = ProcurementMaterialReadSerializer(read_only=True)

class Meta:
model = MaterialExecutionDetail
fields = '__all__'


class MaterialExecutionSerializer(serializers.ModelSerializer):

materialexecution = MaterialExecutionDetailSerializer(many=True)

# TODO: 此处是物料的外接显示,等待武指导写完物料的序列化器引入即可

class Meta:
model = MaterialExecution
fields = '__all__'


class MaterialExecutionCreateSerializer(serializers.ModelSerializer):

details = serializers.ListField(
child=serializers.IntegerField(), write_only=True)

Expand Down
14 changes: 14 additions & 0 deletions Procurement/serializers/status_change.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from rest_framework import serializers
from django.db import transaction

from Procurement.models import StatusChange
from Procurement.models import BiddingSheet


class StatusChangeSerializer(serializers.ModelSerializer):
Expand All @@ -9,3 +11,15 @@ class Meta:
model = StatusChange
fields = '__all__'
read_only_fields = ('normal_change', 'change_user')

def create(self, validated_data):
with transaction.atomic():
changelist = StatusChange(
change_user=self.context['request'].user,
normal_change=False,
**validated_data)
changelist.save()
BiddingSheet.objects.filter(
uid=validated_data['bidding_sheet']).update(
status=validated_data['new_status'])
return changelist

0 comments on commit 5cb0875

Please sign in to comment.