From 1b7190a4b6c8aa03ad29e78fb54e7377908ca72c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 4 Nov 2021 16:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=A1=A8=E5=8D=95=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/inm/views.py | 4 +-- hb_server/apps/wpm/models.py | 34 ++++++++++++++++------ hb_server/apps/wpm/serializers.py | 8 ++++-- hb_server/apps/wpm/urls.py | 3 +- hb_server/apps/wpm/views.py | 47 ++++++++++++++++++++++++++----- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/hb_server/apps/inm/views.py b/hb_server/apps/inm/views.py index 2c3bd49..f8b7f5d 100644 --- a/hb_server/apps/inm/views.py +++ b/hb_server/apps/inm/views.py @@ -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): """ 出入库记录详情表 """ diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index 57d9548..a7e46a1 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -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) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index b70d745..e842a4d 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -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()) \ No newline at end of file + 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) diff --git a/hb_server/apps/wpm/urls.py b/hb_server/apps/wpm/urls.py index d6aad5e..1ce7fa3 100644 --- a/hb_server/apps/wpm/urls.py +++ b/hb_server/apps/wpm/urls.py @@ -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)), ] diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 74ee648..ac6bba3 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -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): - """ - 生产操作表单创建 - """ - perms_map={'*':'*'} \ No newline at end of file +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): + """ + 提交操作表单 + """ \ No newline at end of file