Skip to content

Commit

Permalink
#17 [采购模块] (#163)
Browse files Browse the repository at this point in the history
* 完成材料代用创建主表时对子表的创建
完成材料执行主表创建对子表的绑定
对材料执行子表的筛选显示

* 改名
  • Loading branch information
eyeeco authored and Time1ess committed Dec 24, 2017
1 parent bdc5899 commit 4365cef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
6 changes: 2 additions & 4 deletions Procurement/api/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class MaterialExecutionViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialExecution.objects.all().order_by('-pk')

def perform_create(self, serializer):
serializer.save(lister=self.request.user)

def get_serializer_class(self):
if self.action == 'create':
return serializers.MaterialExecutionCreateSerializer
Expand All @@ -23,5 +20,6 @@ def get_serializer_class(self):

class MaterialExecutionDetailViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialExecutionDetail.objects.all().order_by('-pk')
queryset = MaterialExecutionDetail.objects.all().filter(
material_execution=None).order_by('-pk')
serializer_class = serializers.MaterialExecutionDetailSerializer
5 changes: 2 additions & 3 deletions Procurement/api/materialsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ class MaterialSubApplyViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialSubApply.objects.all().order_by('-pk')

def perform_create(self, serializer):
serializer.save(applicant=self.request.user)

def get_serializer_class(self):
if self.action == 'list':
return serializers.MaterialSubApplyListSerializer
elif self.action == "update":
return serializers.MaterialSubApplyUpdateSerializer
else:
return serializers.MaterialSubApplySerializer

Expand Down
Empty file added Procurement/filters/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions Procurement/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MaterialSubApplySerializer,
MaterialSubApplyListSerializer,
MaterialSubApplyItemsSerializer, MaterialSubApplyItemsUpdateSerializer,
MaterialSubApplyCommentsSerializer,)
MaterialSubApplyCommentsSerializer, MaterialSubApplyUpdateSerializer)

from .material_execution import (
MaterialExecutionSerializer, MaterialExecutionDetailSerializer,
Expand All @@ -20,5 +20,5 @@
'MaterialExecutionSerializer',
'MaterialExecutionDetailSerializer',
'MaterialExecutionListSerializer', 'MaterialExecutionCreateSerializer',
'StatusChangeSerializer'
'StatusChangeSerializer', 'MaterialSubApplyUpdateSerializer'
]
20 changes: 16 additions & 4 deletions Procurement/serializers/material_execution.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 MaterialExecution, MaterialExecutionDetail

Expand All @@ -12,8 +13,7 @@ class Meta:

class MaterialExecutionSerializer(serializers.ModelSerializer):

materialexecution = MaterialExecutionDetailSerializer(many=True,
read_only=True)
materialexecution = MaterialExecutionDetailSerializer(many=True)

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

Expand All @@ -22,14 +22,26 @@ class Meta:
fields = '__all__'


class MaterialExecutionCreateSerializer(MaterialExecutionSerializer):
class MaterialExecutionCreateSerializer(serializers.ModelSerializer):

# TODO: 此处待完善,创建时需要完成对材料执行明细表的绑定
details = serializers.ListField(
child=serializers.IntegerField(), write_only=True)

class Meta(MaterialExecutionSerializer.Meta):
model = MaterialExecution
fields = '__all__'
read_only_fields = ('lister',)

def create(self, validated_data):
with transaction.atomic():
id_array = validated_data.pop('details')
m_excution = MaterialExecution(lister=self.context['request'].user,
**validated_data)
m_excution.save()
MaterialExecutionDetail.objects.filter(
id__in=id_array).update(material_execution=m_excution)
return m_excution


class MaterialExecutionListSerializer(MaterialExecutionSerializer):

Expand Down
26 changes: 24 additions & 2 deletions Procurement/serializers/materialsub.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 MaterialSubApply, MaterialSubApplyItems
from Procurement.models import SubApplyComment
Expand Down Expand Up @@ -27,8 +28,7 @@ class Meta:

class MaterialSubApplySerializer(serializers.ModelSerializer):

sub_apply_items = MaterialSubApplyItemsSerializer(many=True,
read_only=True)
sub_apply_items = MaterialSubApplyItemsUpdateSerializer(many=True)
sub_spply_comments = MaterialSubApplyCommentsSerializer(many=True,
read_only=True)

Expand All @@ -37,6 +37,28 @@ class Meta:
fields = '__all__'
read_only_fields = ('applicant',)

def create(self, validated_data):
with transaction.atomic():
item_list = validated_data.pop('sub_apply_items')
m_subapply = MaterialSubApply(
applicant=self.context['request'].user,
**validated_data)
m_subapply.save()
items = []
for item in item_list:
items.append(MaterialSubApplyItems(
sub_apply=m_subapply, **item))
MaterialSubApplyItems.objects.bulk_create(items)
return m_subapply


class MaterialSubApplyUpdateSerializer(serializers.ModelSerializer):

class Meta:
model = MaterialSubApply
fields = '__all__'
read_only_fields = ('applicant',)


class MaterialSubApplyListSerializer(MaterialSubApplySerializer):
class Meta(MaterialSubApplySerializer.Meta):
Expand Down

0 comments on commit 4365cef

Please sign in to comment.