增加事务操作
This commit is contained in:
parent
537fda2e86
commit
5d5a1e7604
|
@ -4,6 +4,7 @@ from apps.inm.models import FIFO, FIFOItem, IProduct, MaterialBatch, WareHouse,I
|
||||||
|
|
||||||
from apps.system.serializers import UserSimpleSerializer
|
from apps.system.serializers import UserSimpleSerializer
|
||||||
from apps.mtm.serializers import MaterialSimpleSerializer
|
from apps.mtm.serializers import MaterialSimpleSerializer
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
class WareHouseSerializer(serializers. ModelSerializer):
|
class WareHouseSerializer(serializers. ModelSerializer):
|
||||||
create_by_=UserSimpleSerializer('create_by', read_only=True)
|
create_by_=UserSimpleSerializer('create_by', read_only=True)
|
||||||
|
@ -91,28 +92,29 @@ class FIFOInPurSerializer(serializers.ModelSerializer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 创建采购入库
|
# 创建采购入库
|
||||||
validated_data['type'] = FIFO.FIFO_TYPE_PUR_IN
|
with transaction.atomic():
|
||||||
obj = FIFO(**validated_data)
|
validated_data['type'] = FIFO.FIFO_TYPE_PUR_IN
|
||||||
obj.save()
|
obj = FIFO(**validated_data)
|
||||||
for i in details:
|
obj.save()
|
||||||
if 'details' in i:
|
for i in details:
|
||||||
p_details = i.pop('details')
|
if 'details' in i:
|
||||||
if len(p_details) != i['count']:
|
p_details = i.pop('details')
|
||||||
raise serializers.ValidationError('数目对不上')
|
if len(p_details) != i['count']:
|
||||||
|
raise serializers.ValidationError('数目对不上')
|
||||||
|
else:
|
||||||
|
i['fifo'] = obj
|
||||||
|
fifod = FIFOItem.objects.create(**i)
|
||||||
|
p_list = []
|
||||||
|
for x in p_details:
|
||||||
|
x['state'] = 1
|
||||||
|
x['material'] = i['material']
|
||||||
|
x['warehouse'] = validated_data['warehouse']
|
||||||
|
x['batch'] = i['batch']
|
||||||
|
x['fifos'] = [fifod.id]
|
||||||
|
p_list.append(IProduct(**x))
|
||||||
|
IProduct.objects.bulk_create(p_list)
|
||||||
else:
|
else:
|
||||||
i['fifo'] = obj
|
i['fifo'] = obj
|
||||||
fifod = FIFOItem.objects.create(**i)
|
FIFOItem.objects.create(**i)
|
||||||
p_list = []
|
|
||||||
for x in p_details:
|
|
||||||
x['state'] = 1
|
|
||||||
x['material'] = i['material']
|
|
||||||
x['warehouse'] = validated_data['warehouse']
|
|
||||||
x['batch'] = i['batch']
|
|
||||||
x['fifos'] = [fifod.id]
|
|
||||||
p_list.append(IProduct(**x))
|
|
||||||
IProduct.objects.bulk_create(p_list)
|
|
||||||
else:
|
|
||||||
i['fifo'] = obj
|
|
||||||
FIFOItem.objects.create(**i)
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from apps.inm.signals import update_inm
|
||||||
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
|
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
class WarehouseViewSet(CreateUpdateModelAMixin, ModelViewSet):
|
class WarehouseViewSet(CreateUpdateModelAMixin, ModelViewSet):
|
||||||
|
@ -118,8 +119,9 @@ class FIFOViewSet(ListModelMixin, GenericViewSet):
|
||||||
raise APIException('未检验通过, 不可审核')
|
raise APIException('未检验通过, 不可审核')
|
||||||
if obj.is_audited:
|
if obj.is_audited:
|
||||||
raise APIException('该入库记录已审核通过')
|
raise APIException('该入库记录已审核通过')
|
||||||
obj.is_audited = True
|
with transaction.atomic():
|
||||||
obj.save()
|
obj.is_audited = True
|
||||||
update_inm(obj) # 更新库存
|
obj.save()
|
||||||
|
update_inm(obj) # 更新库存
|
||||||
return Response()
|
return Response()
|
||||||
|
|
|
@ -6,6 +6,7 @@ from apps.system.mixins import CreateUpdateModelAMixin
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
from django.db import transaction
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
class StandardViewSet(CreateUpdateModelAMixin, ModelViewSet):
|
class StandardViewSet(CreateUpdateModelAMixin, ModelViewSet):
|
||||||
"""
|
"""
|
||||||
|
@ -66,26 +67,26 @@ class TestRecordViewSet(ModelViewSet):
|
||||||
record_data = vdata.pop('record_data')
|
record_data = vdata.pop('record_data')
|
||||||
if 'is_testok' not in vdata:
|
if 'is_testok' not in vdata:
|
||||||
raise APIException('未填写检测结论')
|
raise APIException('未填写检测结论')
|
||||||
|
with transaction.atomic():
|
||||||
obj = serializer.save(create_by = self.request.user)
|
obj = serializer.save(create_by = self.request.user)
|
||||||
tris = []
|
tris = []
|
||||||
for m in record_data: # 保存记录详情
|
for m in record_data: # 保存记录详情
|
||||||
form_field = m['form_field']
|
form_field = m['form_field']
|
||||||
m['field_name'] = form_field.field_name
|
m['field_name'] = form_field.field_name
|
||||||
m['field_key'] = form_field.field_key
|
m['field_key'] = form_field.field_key
|
||||||
m['field_type'] = form_field.field_type
|
m['field_type'] = form_field.field_type
|
||||||
m['field_value'] = m['field_value']
|
m['field_value'] = m['field_value']
|
||||||
m['sort'] = form_field.sort
|
m['sort'] = form_field.sort
|
||||||
m['need_judge'] = form_field.need_judge
|
m['need_judge'] = form_field.need_judge
|
||||||
m['is_testok'] = m['is_testok'] if 'is_testok' in m else True
|
m['is_testok'] = m['is_testok'] if 'is_testok' in m else True
|
||||||
m['test_record'] = obj
|
m['test_record'] = obj
|
||||||
tris.append(TestRecordItem(**m))
|
tris.append(TestRecordItem(**m))
|
||||||
TestRecordItem.objects.bulk_create(tris)
|
TestRecordItem.objects.bulk_create(tris)
|
||||||
|
|
||||||
# 如果检测合格
|
# 如果检测合格
|
||||||
if obj.fifo_item:
|
if obj.fifo_item:
|
||||||
obj.fifo_item.is_testok = True if obj.is_testok else False
|
obj.fifo_item.is_testok = True if obj.is_testok else False
|
||||||
obj.fifo_item.is_tested = True
|
obj.fifo_item.is_tested = True
|
||||||
obj.fifo_item.save()
|
obj.fifo_item.save()
|
||||||
|
|
||||||
return Response(status=status.HTTP_201_CREATED)
|
return Response(status=status.HTTP_201_CREATED)
|
|
@ -10,6 +10,7 @@ from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from apps.system.serializers import UserSimpleSerializer
|
from apps.system.serializers import UserSimpleSerializer
|
||||||
from apps.wpm.models import Operation, WMaterial, WProduct, OperationRecord, OperationRecordItem
|
from apps.wpm.models import Operation, WMaterial, WProduct, OperationRecord, OperationRecordItem
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
class PickDetailSerializer(serializers.Serializer):
|
class PickDetailSerializer(serializers.Serializer):
|
||||||
material = serializers.PrimaryKeyRelatedField(queryset=Material.objects.all(), label="物料ID")
|
material = serializers.PrimaryKeyRelatedField(queryset=Material.objects.all(), label="物料ID")
|
||||||
|
@ -36,40 +37,41 @@ class PickSerializer(serializers.Serializer):
|
||||||
except:
|
except:
|
||||||
raise serializers.ValidationError('物料不存在')
|
raise serializers.ValidationError('物料不存在')
|
||||||
# 创建出库记录
|
# 创建出库记录
|
||||||
operator = self.context['request'].user
|
with transaction.atomic():
|
||||||
validated_data['create_by'] = operator
|
operator = self.context['request'].user
|
||||||
validated_data['operator'] = operator
|
validated_data['create_by'] = operator
|
||||||
validated_data['type'] = FIFO.FIFO_TYPE_DO_OUT
|
validated_data['operator'] = operator
|
||||||
validated_data['inout_date'] = timezone.now()
|
validated_data['type'] = FIFO.FIFO_TYPE_DO_OUT
|
||||||
fifo = FIFO.objects.create(**validated_data)
|
validated_data['inout_date'] = timezone.now()
|
||||||
for i in picks:
|
fifo = FIFO.objects.create(**validated_data)
|
||||||
# 更新出库详情
|
for i in picks:
|
||||||
i['fifo'] = fifo
|
# 更新出库详情
|
||||||
i['count'] = i.pop('pick_count')
|
i['fifo'] = fifo
|
||||||
i['is_testok'] = True # 默认检测合格
|
i['count'] = i.pop('pick_count')
|
||||||
FIFOItem.objects.create(**i)
|
i['is_testok'] = True # 默认检测合格
|
||||||
# 更新车间物料
|
FIFOItem.objects.create(**i)
|
||||||
wm, _ = WMaterial.objects.get_or_create(material=i['material'], batch=i['batch'], \
|
# 更新车间物料
|
||||||
subproduction_plan=sp,defaults={
|
wm, _ = WMaterial.objects.get_or_create(material=i['material'], batch=i['batch'], \
|
||||||
'material':i['material'],
|
subproduction_plan=sp,defaults={
|
||||||
'batch':i['batch'],
|
'material':i['material'],
|
||||||
'subproduction_plan':sp,
|
'batch':i['batch'],
|
||||||
'count':0
|
'subproduction_plan':sp,
|
||||||
})
|
'count':0
|
||||||
wm.count = wm.count + i['count']
|
})
|
||||||
wm.save()
|
wm.count = wm.count + i['count']
|
||||||
# 更新子计划物料情况
|
wm.save()
|
||||||
spp = SubProductionProgress.objects.get(material=i['material'], subproduction_plan=sp, type=1)
|
# 更新子计划物料情况
|
||||||
spp.count_pick = spp.count_pick + i['count']
|
spp = SubProductionProgress.objects.get(material=i['material'], subproduction_plan=sp, type=1)
|
||||||
spp.save()
|
spp.count_pick = spp.count_pick + i['count']
|
||||||
sp.is_picked=True
|
spp.save()
|
||||||
sp.state = 3 #生产中
|
sp.is_picked=True
|
||||||
sp.state_date_real = timezone.now() #实际开工日期
|
sp.state = 3 #生产中
|
||||||
sp.save()
|
sp.state_date_real = timezone.now() #实际开工日期
|
||||||
# 更新库存
|
sp.save()
|
||||||
fifo.is_audited = True
|
# 更新库存
|
||||||
fifo.save()
|
fifo.is_audited = True
|
||||||
update_inm(fifo)
|
fifo.save()
|
||||||
|
update_inm(fifo)
|
||||||
return fifo
|
return fifo
|
||||||
|
|
||||||
class WMaterialListSerializer(serializers.ModelSerializer):
|
class WMaterialListSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -16,6 +16,7 @@ from apps.wpm.models import WMaterial, WProduct, Operation, OperationMaterial, O
|
||||||
|
|
||||||
from apps.wpm.serializers import OperationDetailSerializer, OperationListSerializer, PickSerializer, OperationInitSerializer, OperationSubmitSerializer, WMaterialListSerializer, WProductListSerializer
|
from apps.wpm.serializers import OperationDetailSerializer, OperationListSerializer, PickSerializer, OperationInitSerializer, OperationSubmitSerializer, WMaterialListSerializer, WProductListSerializer
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from django.db import transaction
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
class WPlanViewSet(ListModelMixin, GenericViewSet):
|
class WPlanViewSet(ListModelMixin, GenericViewSet):
|
||||||
"""
|
"""
|
||||||
|
@ -131,6 +132,8 @@ class DoFormInit(CreateAPIView, GenericAPIView):
|
||||||
class DoFormSubmit(CreateAPIView, GenericAPIView):
|
class DoFormSubmit(CreateAPIView, GenericAPIView):
|
||||||
perms_map={'*':'*'}
|
perms_map={'*':'*'}
|
||||||
serializer_class = OperationSubmitSerializer
|
serializer_class = OperationSubmitSerializer
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def post(self, request, format=None):
|
def post(self, request, format=None):
|
||||||
"""
|
"""
|
||||||
提交操作表单
|
提交操作表单
|
||||||
|
|
Loading…
Reference in New Issue