Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:DLUT-SIE/ERP into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeeco committed Jan 18, 2018
2 parents 984266a + 2cf0791 commit bd6bf86
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ERP/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'Messaging',
'Core.apps.CoreConfig',
'Distribution',
'Process',
'Process.apps.ProcessConfig',
'Procurement',
'Inventory.apps.InventoryConfig',
'Production.apps.ProductionConfig',
Expand Down
15 changes: 15 additions & 0 deletions Process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,18 @@
(WWI_EXAMINATION_SURVEYOR_INSPECTION_UNIT, '检验机构'),
(WWI_EXAMINATION_SURVEYOR_THIRD_PARTY_OR_USER, '第三方或用户'),
)

QUOTASTATUS_INIT = 0
QUOTASTATUS_WRITTEN = 1
QUOTASTATUS_RIVIEWED = 2
QUOTASTATUS_CHOICES = (
(QUOTASTATUS_INIT, '待编制'),
(QUOTASTATUS_WRITTEN, '待审核'),
(QUOTASTATUS_RIVIEWED, '已生成采购物料'),)

QUOTA_LIST_CATEGORY_USING = (QUOTA_LIST_CATEGORY_PRINCIPAL,
QUOTA_LIST_CATEGORY_AUXILIARY,
QUOTA_LIST_CATEGORY_WELDQUOTAPAGE,
QUOTA_LIST_CATEGORY_COOPERANT,
QUOTA_LIST_CATEGORY_FIRSTFEEDING,
QUOTA_LIST_CATEGORY_OUTPURCHASED)
6 changes: 6 additions & 0 deletions Process/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from django.apps import AppConfig
from django.db.models.signals import post_save


class ProcessConfig(AppConfig):
name = 'Process'

def ready(self):
from Process import signals
post_save.connect(signals.init_process,
sender='Core.WorkOrder')
20 changes: 20 additions & 0 deletions Process/migrations/0021_quotalist_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-01-18 06:56
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Process', '0020_auto_20171230_1441'),
]

operations = [
migrations.AddField(
model_name='quotalist',
name='status',
field=models.IntegerField(choices=[(0, '待编制'), (1, '待审核'), (2, '已生成采购物料')], default=0, verbose_name='定额明细表编制状态'),
),
]
86 changes: 79 additions & 7 deletions Process/models/quota.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from django.db import models
from django.db import models, transaction
from django.contrib.auth.models import User

from Process import QUOTA_LIST_CATEGORY_CHOICES
from Process import (
QUOTA_LIST_CATEGORY_CHOICES, QUOTASTATUS_CHOICES, QUOTASTATUS_INIT,
QUOTASTATUS_WRITTEN, QUOTASTATUS_RIVIEWED, QUOTA_LIST_CATEGORY_AUXILIARY,
QUOTA_LIST_CATEGORY_PRINCIPAL, QUOTA_LIST_CATEGORY_COOPERANT,
QUOTA_LIST_CATEGORY_FIRSTFEEDING, QUOTA_LIST_CATEGORY_OUTPURCHASED,
QUOTA_LIST_CATEGORY_WELDQUOTAPAGE)
from Process.models import (
Material, ProcessLibrary, ProcessMaterial, TotalWeldingMaterial)
from Core.utils.fsm import transition, TransitionMeta
from Procurement.models import ProcurementMaterial


class QuotaList(models.Model):
class QuotaList(models.Model, metaclass=TransitionMeta):
"""
定额明细表
"""
Expand All @@ -27,11 +34,79 @@ class QuotaList(models.Model):
null=True)
category = models.IntegerField(verbose_name='明细表类别',
choices=QUOTA_LIST_CATEGORY_CHOICES)
status = models.IntegerField(verbose_name='定额明细表编制状态',
choices=QUOTASTATUS_CHOICES,
default=QUOTASTATUS_INIT)

class Meta:
verbose_name = '定额明细表'
verbose_name_plural = '定额明细表'

@transition(field='status',
source=QUOTASTATUS_INIT,
target=QUOTASTATUS_WRITTEN,
name='编制确认')
def quota_write(self, request):
self.writer = request.user

def createProcurementMaterial(self):
work_order = self.lib.work_order
inventory_type = self.category
quotaclass = None
abstract_item = False
procurement_material_list = []
if inventory_type == QUOTA_LIST_CATEGORY_AUXILIARY:
quotaclass = AuxiliaryQuotaItem
elif inventory_type == QUOTA_LIST_CATEGORY_PRINCIPAL:
quotaclass = PrincipalQuotaItem
elif inventory_type == QUOTA_LIST_CATEGORY_WELDQUOTAPAGE:
quotaclass = WeldingQuotaItem
else:
abstract_item = True
if inventory_type == QUOTA_LIST_CATEGORY_COOPERANT:
quotaclass = CooperantItem
elif inventory_type == QUOTA_LIST_CATEGORY_FIRSTFEEDING:
quotaclass = FirstFeedingItem
elif inventory_type == QUOTA_LIST_CATEGORY_OUTPURCHASED:
quotaclass = BoughtInItem
if abstract_item:
for sub_order in work_order.subworkorder_set.all():
for item in quotaclass.objects.filter(
quota_list=self):
procurement_material = ProcurementMaterial()
procurement_material.process_material = \
item.process_material
procurement_material.sub_order = sub_order
procurement_material.inventory_type = self.category
procurement_material.material_number = \
item.process_material.material.uid
procurement_material.category = \
item.process_material.material.category
procurement_material.count = item.process_material.count
procurement_material.weight = item.process_material.weight
procurement_material_list.append(procurement_material)
else:
for sub_order in work_order.subworkorder_set.all():
for item in quotaclass.objects.filter(
quota_list=self):
procurement_material = ProcurementMaterial()
procurement_material.sub_order = sub_order
procurement_material.inventory_type = self.category
procurement_material.material_number = item.material.uid
procurement_material.category = item.material.category
procurement_material.count = item.count
procurement_material.weight = item.weight
procurement_material_list.append(procurement_material)
ProcurementMaterial.objects.bulk_create(procurement_material_list)

@transition(field='status',
source=QUOTASTATUS_WRITTEN,
target=QUOTASTATUS_RIVIEWED,
name='审核确认')
def quota_review(self, request):
self.reviewer = request.user
self.createProcurementMaterial()

def __str__(self):
return str(self.lib)

Expand Down Expand Up @@ -60,10 +135,7 @@ class AuxiliaryQuotaItem(AbstractQuotaItem):
"""
辅材定额
"""
process_material = models.OneToOneField(ProcessMaterial,
verbose_name='工艺物料',
related_name='%(class)s',
on_delete=models.CASCADE)

quota_coef = models.FloatField(verbose_name='定额系数', blank=True,
null=True)
quota = models.FloatField(verbose_name='定额', blank=True, null=True)
Expand Down
8 changes: 6 additions & 2 deletions Process/serializers/process_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
TotalWeldingMaterial, WeldingMaterial, FluxMaterial, WeldingCertification,
WeldingProcessSpecification, WeldingJointProcessAnalysis,
WeldingWorkInstruction)
from Core.utils.fsm import TransitionSerializerMixin as TSMixin


class GetCirculationRoutesMixin(serializers.Serializer):
circulation_routes = serializers.SerializerMethodField()

def get_circulation_routes(self, obj):
circulation_routes = []
if hasattr(obj.process_material, 'circulation_route'):
return None
routes = obj.process_material.circulation_route
for i in range(10):
cur = getattr(routes, 'C{}'.format(i + 1))
Expand Down Expand Up @@ -357,7 +360,7 @@ def get_total_weight(self, obj):
return 0


class QuotaListSerializer(serializers.ModelSerializer):
class QuotaListSerializer(TSMixin, serializers.ModelSerializer):
product_name = serializers.CharField(source='lib.work_order.product',
read_only=True)
work_order_uid = serializers.CharField(source='lib.work_order.uid',
Expand All @@ -369,7 +372,8 @@ class QuotaListSerializer(serializers.ModelSerializer):

class Meta:
model = QuotaList
fields = ('id', 'writer', 'reviewer', 'product_name', 'work_order_uid')
fields = ('id', 'status', 'actions', 'writer', 'reviewer',
'product_name', 'work_order_uid')


class PrincipalQuotaItemCreateSerializer(PrincipalQuotaItemSerializer):
Expand Down
21 changes: 21 additions & 0 deletions Process/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import transaction

from Process import QUOTA_LIST_CATEGORY_USING
from Process.models import QuotaList, ProcessLibrary


def init_process(*args, **kwargs):
"""
监听工作令的创建,当工作令创建完成后,建立相应的工艺库和所有的定额表
"""
if not kwargs['created']:
return
work_order = kwargs['instance']
with transaction.atomic():
quota_lists = []
process_library = ProcessLibrary.objects.create(work_order=work_order)
for item in QUOTA_LIST_CATEGORY_USING:
quota_list = QuotaList(lib=process_library,
category=item)
quota_lists.append(quota_list)
QuotaList.objects.bulk_create(quota_lists)
1 change: 0 additions & 1 deletion Process/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def post(self, request, format=None):
with transaction.atomic():
self.file_deal(process_library, data_file)
except Exception as e:
print(e)
return Response(status=status.HTTP_400_BAD_REQUEST)
else:
return Response(status=status.HTTP_204_NO_CONTENT)
Expand Down

0 comments on commit bd6bf86

Please sign in to comment.