调用表单操作

This commit is contained in:
caoqianming 2021-11-04 16:14:48 +08:00
parent ba9466a90b
commit 1b7190a4b6
5 changed files with 75 additions and 21 deletions

View File

@ -1,7 +1,7 @@
from django.shortcuts import render
from rest_framework import serializers
from rest_framework.exceptions import APIException
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.mixins import DestroyModelMixin, ListModelMixin, RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from apps.inm.filters import MbFilterSet
@ -63,7 +63,7 @@ class MaterialBatchViewSet(ListModelMixin, GenericViewSet):
queryset = self.queryset.filter(warehouse__id=data['warehouse'], material__id__in=data['materials'])
return Response(MaterialBatchSerializer(instance=queryset, many=True).data)
class FIFODetailViewSet(ListModelMixin, GenericViewSet):
class FIFODetailViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet):
"""
出入库记录详情表
"""

View File

@ -24,31 +24,47 @@ class WProduct(CommonAModel):
半成品/成品
"""
act_state_choices=(
(0, '待执行'),
(1, '进行中'),
(2, '已完成')
(1, '生产中'),
(2, '待检测'),
(3, '已合格')
)
number = models.CharField('物品编号', unique=True, null=True, blank=True, max_length=50)
m_state = models.ForeignKey(Material, verbose_name='所属物料状态', on_delete=models.CASCADE)
p_state = models.ForeignKey(Step, verbose_name='所在步骤', on_delete=models.CASCADE, null=True, blank=True)
act_state = models.IntegerField('进行状态', default=0)
parent = models.ForeignKey('self', verbose_name='上一级', on_delete=models.CASCADE, db_constraint=False)
act_state = models.IntegerField('进行状态', default=0, choices=act_state_choices)
is_executed = models.BooleanField('子工序是否已执行', default=False)
parent = models.ForeignKey('self', verbose_name='上一级', on_delete=models.CASCADE, db_constraint=False, null=True, blank=True)
remark = models.CharField('备注', max_length=200, null=True, blank=True)
subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='当前子生产计划', on_delete=models.CASCADE)
production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE)
class WProductFlow(BaseModel):
class WProductAction(CommonAModel):
"""
生产操作日志
生产操作
"""
wproducts = models.JSONField('关联产品ID列表', default=list, blank=True)
p_state = models.ForeignKey(Step, verbose_name='所在步骤', on_delete=models.CASCADE, null=True, blank=True)
m_state = models.ForeignKey(Material, verbose_name='操作时的物料状态', on_delete=models.CASCADE)
p_state = models.ForeignKey(Step, verbose_name='操作步骤', on_delete=models.CASCADE, null=True, blank=True)
remark = models.CharField('操作备注', max_length=200, null=True, blank=True)
class WProductMaterial(BaseModel):
"""
车间生产物料消耗产出表
"""
type_choices=(
(1, '消耗'),
(2, '产出')
)
type = models.IntegerField('类型', default=0, choices=type_choices)
wproduct_action = models.ForeignKey(WProductAction, verbose_name='关联的生产操作', on_delete=models.CASCADE)
material = models.ForeignKey(Material, verbose_name='关联的物料', on_delete=models.CASCADE)
count = models.IntegerField('消耗或产出数量')
class WProductRecord(CommonAModel):
"""
记录表格
"""
form = models.ForeignKey(RecordForm, verbose_name='所用的生产记录表格', on_delete=models.CASCADE)
record_data = models.JSONField('记录的数据', default=dict, blank=True)
wproduct_flow = models.ForeignKey(WProductFlow, verbose_name='关联的生产操作日志', on_delete=models.CASCADE)
wproduct_action = models.ForeignKey(WProductAction, verbose_name='关联的生产操作', on_delete=models.CASCADE)

View File

@ -8,7 +8,7 @@ from apps.mtm.serializers import MaterialSimpleSerializer
from apps.pm.models import SubProductionPlan, SubProductionProgress
from django.utils import timezone
from apps.wpm.models import WMaterial
from apps.wpm.models import WMaterial, WProduct
class PickDetailSerializer(serializers.Serializer):
material = serializers.PrimaryKeyRelatedField(queryset=Material.objects.all(), label="物料ID")
@ -45,6 +45,7 @@ class PickSerializer(serializers.Serializer):
# 更新出库详情
i['fifo'] = fifo
i['count'] = i.pop('pick_count')
i['is_teskok'] = True
FIFODetail.objects.create(**i)
# 更新车间物料
wm, _ = WMaterial.objects.get_or_create(material=i['material'], batch=i['batch'], \
@ -81,4 +82,7 @@ class WMaterialListSerializer(serializers.ModelSerializer):
class DoFormInitSerializer(serializers.Serializer):
action = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all())
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
wproducts = serializers.ListField(child=
serializers.PrimaryKeyRelatedField(queryset=WProduct.objects.all()), label="半成品ID列表", required=False)

View File

@ -3,12 +3,13 @@ from rest_framework import urlpatterns
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from apps.wpm.views import WMaterialViewSet, WPlanViewSet
from apps.wpm.views import DoFormInit, WMaterialViewSet, WPlanViewSet
router = DefaultRouter()
router.register('wmaterial', WMaterialViewSet, basename='wmaterial')
router.register('subplan', WPlanViewSet, basename='wplan')
urlpatterns = [
path('do/init/', DoFormInit.as_view()),
path('', include(router.urls)),
]

View File

@ -2,15 +2,18 @@ from django.shortcuts import render
from rest_framework.generics import CreateAPIView, GenericAPIView
from rest_framework.mixins import ListModelMixin
from rest_framework.utils.field_mapping import get_relation_kwargs
from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from apps.pm.models import SubProductionPlan
from apps.mtm.models import RecordForm
from apps.mtm.serializers import RecordFormDetailSerializer
from apps.pm.models import SubProductionPlan, SubProductionProgress
from apps.pm.serializers import SubProductionPlanListSerializer, SubProductionPlanUpdateSerializer
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
from rest_framework.decorators import action
from apps.wpm.models import WMaterial
from apps.wpm.serializers import PickSerializer, WMaterialListSerializer
from apps.wpm.serializers import DoFormInitSerializer, PickSerializer, WMaterialListSerializer
from rest_framework.response import Response
# Create your views here.
class WPlanViewSet(ListModelMixin, GenericViewSet):
@ -46,8 +49,38 @@ class WMaterialViewSet(CreateUpdateModelAMixin, ListModelMixin, GenericViewSet):
serializer.save()
return Response()
class DoFormInit(CreateAPIView):
"""
生产操作表单创建
"""
class DoFormInit(APIView):
perms_map={'*':'*'}
def post(self, request, format=None):
"""
调用操作表单
"""
serializer = DoFormInitSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
vdata = serializer.validated_data
ret = {}
# 调出该子计划现有物料
ret['input'] = list(WMaterial.objects.filter(subproduction_plan=vdata['subproduction_plan'])\
.values('material', 'material__name', 'count'))
for i in ret['input']:
i['count_input'] = 0
# 需要输出的物料
# 如果传入半成品列表就不需要
if not 'wproducts' in vdata:
ret['output'] = list(SubProductionProgress.objects.filter(subproduction_plan=vdata['subproduction_plan'], type=2)\
.values('material', 'material__name'))
for i in ret['output']:
i['count_output']=0
ret['forms'] = []
forms = RecordForm.objects.filter(step=vdata['step'], type=1)
if forms.exists():
ret['forms'] = RecordFormDetailSerializer(instance=forms, many=True).data
return Response(ret)
class DoFormSubmit(APIView):
def post(self, request, format=None):
"""
提交操作表单
"""