diff --git a/hb_server/apps/em/serializers.py b/hb_server/apps/em/serializers.py index a200114..55d0674 100644 --- a/hb_server/apps/em/serializers.py +++ b/hb_server/apps/em/serializers.py @@ -1,3 +1,4 @@ +from apps.mtm.models import Step from rest_framework import serializers from rest_framework.serializers import ModelSerializer @@ -8,6 +9,7 @@ from apps.system.serializers import OrganizationSimpleSerializer, UserSimpleSeri class EquipmentSerializer(ModelSerializer): belong_dept_ = OrganizationSimpleSerializer(source='belong_dept', read_only=True) keeper_ = UserSimpleSerializer(source='keeper', read_only=True) + step_ = serializers.SerializerMethodField() class Meta: model = Equipment fields = '__all__' @@ -18,6 +20,9 @@ class EquipmentSerializer(ModelSerializer): queryset = queryset.select_related('belong_dept','keeper') return queryset + def get_step_(self, obj): + return Step.objects.filter(equipments=obj).values('id', 'name', 'number') + class EquipmentSimpleSerializer(ModelSerializer): class Meta: model = Equipment diff --git a/hb_server/apps/mtm/serializers.py b/hb_server/apps/mtm/serializers.py index 410d24c..6a1dd98 100644 --- a/hb_server/apps/mtm/serializers.py +++ b/hb_server/apps/mtm/serializers.py @@ -1,6 +1,6 @@ -from apps.em.serializers import EquipmentSerializer, EquipmentSimpleSerializer +from apps.em.serializers import EquipmentSimpleSerializer from rest_framework import serializers -from rest_framework.exceptions import ValidationError +from rest_framework.exceptions import ParseError, ValidationError from .models import InputMaterial, Material, OutputMaterial, Process, ProductProcess, RecordForm, RecordFormField, Step, TechDoc, UsedStep from apps.system.serializers import FileSimpleSerializer, OrganizationSimpleSerializer diff --git a/hb_server/apps/wf/services.py b/hb_server/apps/wf/services.py index cd691d9..bee8799 100644 --- a/hb_server/apps/wf/services.py +++ b/hb_server/apps/wf/services.py @@ -168,8 +168,13 @@ class WfService(object): if user.id not in participant: return dict(permission=False, msg="非当前处理人") current_participant_count = len(participant) - if current_participant_count >1 and state.distribute_type == State.STATE_DISTRIBUTE_TYPE_ACTIVE: - return dict(permission=False, msg="需要先接单再处理") + if current_participant_count == 1: + if [user.id] != participant: + return dict(permission=False, msg="非当前处理人") + elif current_participant_count >1 and state.distribute_type == State.STATE_DISTRIBUTE_TYPE_ACTIVE: + if user.id not in participant: + return dict(permission=False, msg="非当前处理人") + return dict(permission=False, msg="需要先接单再处理", need_accept=True) if ticket.in_add_node: return dict(permission=False, msg="工单当前处于加签中,请加签完成后操作") return dict(permission=True, msg="") diff --git a/hb_server/apps/wf/views.py b/hb_server/apps/wf/views.py index 3740fec..3c2e13b 100644 --- a/hb_server/apps/wf/views.py +++ b/hb_server/apps/wf/views.py @@ -247,6 +247,20 @@ class TicketViewSet(OptimizationMixin, CreateUpdateCustomMixin, CreateModelMixin transitions = WfService.get_ticket_transitions(ticket) return Response(TransitionSerializer(instance=transitions, many=True).data) + @action(methods=['post'], detail=True, perms_map={'post':'*'}) + def accpet(self, request, pk=None): + """ + 接单,当工单当前处理人实际为多个人时(角色、部门、多人都有可能, 注意角色和部门有可能实际只有一人) + """ + ticket = self.get_object() + result = WfService.ticket_handle_permission_check(ticket, request.user) + if result.get('need_accept', False): + ticket.participant_type = State.PARTICIPANT_TYPE_PERSONAL + ticket.participant = request.user.id + ticket.save() + # 接单日志 + else: + raise APIException('无需接单') class TicketFlowViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): """