Skip to content

Commit

Permalink
[#17]采购模块
Browse files Browse the repository at this point in the history
重写了材料执行部分
  • Loading branch information
eyeeco committed Jan 18, 2018
1 parent 962cd53 commit 76a4640
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Procurement/api/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def get_serializer_class(self):
# 材料执行表明细
class MaterialExecutionDetailViewSet(viewsets.ModelViewSet):
pagination_class = SmallResultsSetPagination
queryset = MaterialExecutionDetail.objects.all().filter(
material_execution=None).order_by('-pk')
queryset = MaterialExecutionDetail.objects.all().order_by('-pk')
serializer_class = serializers.MaterialExecutionDetailSerializer
filter_class = filters.MaterialExecutionDetailFilter
5 changes: 3 additions & 2 deletions Procurement/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from .materialsub import (MaterialSubApplyFilter, )

from .material_excution import (MaterialExcutionFilter, )
from .material_excution import (MaterialExcutionFilter,
MaterialExecutionDetailFilter)

from .contract_details import (ContractDetailFilter, )

Expand All @@ -18,4 +19,4 @@
'StatusChangeFilter', 'ProcurementMaterialFilter',
'MaterialSubApplyFilter', 'MaterialExcutionFilter',
'SupplyDocumentFilter', 'SupplyQuotationFilter',
'ContractDetailFilter']
'ContractDetailFilter', 'MaterialExecutionDetailFilter']
7 changes: 7 additions & 0 deletions Procurement/filters/material_excution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ class MaterialExcutionFilter(filters.FilterSet):
class Meta:
model = models.MaterialExecution
fields = ('uid',)


# 根据材料执行表模糊查询
class MaterialExecutionDetailFilter(filters.FilterSet):
class Meta:
model = models.MaterialExecutionDetail
fields = ('material_execution',)
2 changes: 1 addition & 1 deletion Procurement/filters/procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class ProcurementMaterialFilter(filters.FilterSet):

class Meta:
model = ProcurementMaterial
fields = ('purchase_order',)
fields = ('purchase_order', 'status')
25 changes: 25 additions & 0 deletions Procurement/migrations/0009_auto_20180119_0516.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-01-18 21:16
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

dependencies = [
('Procurement', '0008_auto_20180118_2250'),
]

operations = [
migrations.RemoveField(
model_name='materialexecutiondetail',
name='batch_number',
),
migrations.AlterField(
model_name='materialexecutiondetail',
name='material_execution',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='material_execution', to='Procurement.MaterialExecution', verbose_name='材料执行表'),
),
]
6 changes: 2 additions & 4 deletions Procurement/models/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ class MaterialExecutionDetail(models.Model):
material_execution = models.ForeignKey(MaterialExecution,
verbose_name='材料执行表',
null=True, blank=True,
related_name='materialexecution',
related_name='material_execution',
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)
quota = models.CharField(verbose_name='定额', max_length=50,
null=True, blank=True)
part = models.CharField(verbose_name='零件', max_length=50,
Expand All @@ -54,4 +52,4 @@ class Meta:
verbose_name_plural = '材料执行表明细'

def __str__(self):
return '{}-{}'.format(self.material_execution, self.materiel)
return '{}-{}'.format(self.material_execution, self.material)
39 changes: 31 additions & 8 deletions Procurement/serializers/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@
from django.db import transaction

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


class MaterialExecutionDetailSerializer(serializers.ModelSerializer):
material = ProcurementMaterialReadSerializer(read_only=True)
execution_uid = serializers.CharField(
source='material_execution.uid', read_only=True)
execution_type = serializers.CharField(
source='material_execution.material_type', read_only=True)
sub_order = serializers.CharField(
source='material.sub_order', read_only=True)
batch_number = serializers.CharField(
source='material.batch_number', read_only=True)
material_name = serializers.CharField(
source='material.process_material.material.name', read_only=True)
material_uid = serializers.CharField(
source='material.process_material.material.uid', read_only=True)
material_category = serializers.CharField(
source='material.process_material.material.category', read_only=True)
count = serializers.CharField(
source='material.count', read_only=True)
weight = serializers.CharField(
source='material.weight', read_only=True)
spec = serializers.CharField(
source='material.process_material.spec', read_only=True)

class Meta:
model = MaterialExecutionDetail
Expand All @@ -22,22 +41,26 @@ class Meta:


class MaterialExecutionCreateSerializer(serializers.ModelSerializer):
details = serializers.ListField(
child=serializers.IntegerField(), write_only=True)
material_execution = MaterialExecutionDetailSerializer(many=True)

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

def create(self, validated_data):
with transaction.atomic():
id_array = validated_data.pop('details')
detail_list = validated_data.pop('material_execution')
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)
array = []
for detail in detail_list:
array.append(MaterialExecutionDetail(
material_execution=m_excution, **detail))
ProcurementMaterial.objects.filter(
id=detail['material'].id).update(status=4)
MaterialExecutionDetail.objects.bulk_create(array)
return m_excution


Expand Down

0 comments on commit 76a4640

Please sign in to comment.