From 5458fef0d4d3ceb42ca7d91e06ac61af115931b7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 31 Aug 2021 16:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=BA=8F=E8=A1=A8=E5=A2=9E=E5=8A=A0wo?= =?UTF-8?q?rkshop=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/mtm/serializers.py | 3 ++- hb_server/apps/mtm/views.py | 4 ++-- hb_server/apps/wf/services.py | 24 ++++++++++++++++++++++++ hb_server/apps/wf/views.py | 8 ++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/hb_server/apps/mtm/serializers.py b/hb_server/apps/mtm/serializers.py index 19145f3..3162536 100644 --- a/hb_server/apps/mtm/serializers.py +++ b/hb_server/apps/mtm/serializers.py @@ -2,7 +2,7 @@ from apps.em.serializers import EquipmentSerializer, EquipmentSimpleSerializer from rest_framework import serializers from rest_framework.exceptions import ValidationError from .models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, Step, UsedStep -from apps.system.serializers import FileSimpleSerializer +from apps.system.serializers import FileSimpleSerializer, OrganizationSimpleSerializer class MaterialSerializer(serializers.ModelSerializer): @@ -29,6 +29,7 @@ class MaterialSimpleSerializer(serializers.ModelSerializer): class ProcessSerializer(serializers.ModelSerializer): instruction_ = FileSimpleSerializer(source='instruction', read_only=True) + workshop_ = OrganizationSimpleSerializer(source='workshop', read_only=True) class Meta: model = Process fields = '__all__' diff --git a/hb_server/apps/mtm/views.py b/hb_server/apps/mtm/views.py index d52f1c6..3600169 100644 --- a/hb_server/apps/mtm/views.py +++ b/hb_server/apps/mtm/views.py @@ -46,10 +46,10 @@ class ProcessViewSet(PageOrNot, CreateUpdateModelAMixin, ModelViewSet): """ perms_map = {'get': '*', 'post': 'process_create', 'put': 'process_update', 'delete': 'process_delete'} - queryset = Process.objects.select_related('instruction').all() + queryset = Process.objects.select_related('instruction', 'workshop').all() serializer_class = ProcessSerializer search_fields = ['name', 'number'] - filterset_fields = ['number'] + filterset_fields = ['number', 'workshop'] ordering_fields = ['number'] ordering = ['number'] diff --git a/hb_server/apps/wf/services.py b/hb_server/apps/wf/services.py index 2569772..aea2eaf 100644 --- a/hb_server/apps/wf/services.py +++ b/hb_server/apps/wf/services.py @@ -1,3 +1,4 @@ +from typing import Tuple from apps.system.models import User from apps.wf.models import CustomField, State, Ticket, Transition, Workflow from rest_framework.exceptions import APIException @@ -149,5 +150,28 @@ class WfService(object): return dict(destination_participant_type=destination_participant_type, destination_participant=destination_participant, multi_all_person=multi_all_person_dict) + + @classmethod + def ticket_handle_permission_check(cls, ticket:Ticket, user:User)-> dict: + transitions = cls.get_state_transitions(ticket.state) + if not transitions: + return dict(permission=True, msg="工单当前状态无需操作") + current_participant_count = 1 + participant_type = ticket.participant_type + participant = ticket.participant + state = ticket.state + if participant_type == State.PARTICIPANT_TYPE_PERSONAL: + if user.id != participant: + return dict(permission=False, need_accept=False, in_add_node=False, msg="非当前处理人") + elif participant_type in [State.PARTICIPANT_TYPE_MULTI, State.PARTICIPANT_TYPE_DEPT, State.PARTICIPANT_TYPE_ROLE]: + if user.id not in participant: + return dict(permission=False, need_accept=False, in_add_node=False, msg="非当前处理人") + current_participant_count = len(participant.split(',')) + need_accept = False + if current_participant_count >1 and state.distribute_type == State.STATE_DISTRIBUTE_TYPE_ACTIVE: + # 如果是主动接单 + need_accept = True + + diff --git a/hb_server/apps/wf/views.py b/hb_server/apps/wf/views.py index c2afc1f..67d7e09 100644 --- a/hb_server/apps/wf/views.py +++ b/hb_server/apps/wf/views.py @@ -149,6 +149,14 @@ class TicketViewSet(OptimizationMixin, CreateUpdateCustomMixin, CreateModelMixin return Response(TicketSerializer(instance=ticket).data) + + def patch(self, request, *args, **kwargs): + """ + 处理工单 + """ + data = request.data + pass + @action(methods=['get'], detail=True, perms_map={'get':'*'}) def flowsteps(self, request, pk=None): """