Skip to content

Commit

Permalink
[#17] 采购模块 (#293)
Browse files Browse the repository at this point in the history
* [#17] 采购模块
重写合同金额部分

* 修改合同金额获得方式

* 合同金额优化

* 修改了一个模型字段

* [#17]采购模块
重写了材料执行部分

* 修改命名
  • Loading branch information
eyeeco authored and Time1ess committed Jan 19, 2018
1 parent 8798333 commit 7a1357f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 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_1656.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-19 08:56
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='execution_details', 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='execution_details',
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)
10 changes: 9 additions & 1 deletion Procurement/models/procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
PURCHASE_ORDER_STATUS_AUDIT, PURCHASE_ORDER_STATUS_APPROVED,
PURCHASE_ORDER_STATUS_FINISH)
from Procurement import (
PROCUREMENT_MATERIAL_WAITED, PROCUREMENT_MATERIAL_STATUS)
PROCUREMENT_MATERIAL_WAITED, PROCUREMENT_MATERIAL_STATUS,
PROCUREMENT_MATERIAL_ADDED_EXECUTION,
PROCUREMENT_MATERIAL_EXECUTION_FINISHED)
from Core.utils.fsm import transition, TransitionMeta


Expand Down Expand Up @@ -127,5 +129,11 @@ class Meta:
verbose_name = '采购物料'
verbose_name_plural = '采购物料'

@transition(
field='status', source=PROCUREMENT_MATERIAL_ADDED_EXECUTION,
target=PROCUREMENT_MATERIAL_EXECUTION_FINISHED, name='材料执行完成')
def material_execution_finished(self, request):
pass

def __str__(self):
return '{} {}'.format(self.sub_order_id, self.process_material_id)
42 changes: 32 additions & 10 deletions Procurement/serializers/material_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@
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)
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 @@ -15,31 +33,35 @@ class Meta:


class MaterialExecutionSerializer(serializers.ModelSerializer):
materialexecution = MaterialExecutionDetailSerializer(many=True)

class Meta:
model = MaterialExecution
fields = '__all__'


class MaterialExecutionCreateSerializer(serializers.ModelSerializer):
details = serializers.ListField(
child=serializers.IntegerField(), write_only=True)
execution_details = 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('execution_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
array = []
request = self.context['request']
for detail in detail_list:
array.append(MaterialExecutionDetail(
material_execution=m_excution, **detail))
detail['material'].material_execution_finished(request)
detail['material'].save()
MaterialExecutionDetail.objects.bulk_create(array)
return m_excution


class MaterialExecutionListSerializer(MaterialExecutionSerializer):
Expand Down

0 comments on commit 7a1357f

Please sign in to comment.