Example #1
0
    def post(self, request, format=None):
        action = request.data.get('action')
        request_off_id = request.data.get('request_off_id')
        comment = request.data.get('comment')
        user = request.user.profile
        try:
            if action == Workday.STATUS_APPROVED:
                data = ActionRequestService.action_approve(
                    request_off_id, user, comment)
                serializer = RequestDetailSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)

            elif action == Workday.STATUS_REJECTED:
                data = ActionRequestService.action_reject(
                    request_off_id, user, comment)
                serializer = RequestDetailSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)

            elif action == Workday.STATUS_CANCEL:
                data = ActionRequestService.action_cancel(request_off_id, user)
                serializer = RequestOffSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        except Exception as e:
            error = str(e)
            return Response({'error': error},
                            status=status.HTTP_400_BAD_REQUEST)
Example #2
0
    def test_services_rejected_and_service_approve_request_approved(self):
        request_detail = ActionRequestService.action_reject(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_REJECTED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_REJECTED)

        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_REJECTED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_REJECTED)
Example #3
0
    def test_services_approved_with_two_line_manage(self):
        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_APPROVED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_FORWARDED)

        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user1_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_APPROVED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_APPROVED)
Example #4
0
    def test_services_cancel_and_approve_request_cancel_and_reject_request_cancel(self):
        request_off = ActionRequestService.action_cancel(self.response_request_data['id'], self.user3_profile)
        self.assertEqual(request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_off.status, Workday.STATUS_CANCEL)

        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_CANCEL)
        self.assertEqual(request_detail.status, None)

        request_detail = ActionRequestService.action_reject(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_CANCEL)
        self.assertEqual(request_detail.status, None)
Example #5
0
 def post(self, request, format=None):
     data = request.data
     profile = request.user.profile
     type_off_id = request.data.get('type_id')
     type_off = TypeOff.objects.filter(id=type_off_id).first()
     try:
         if RequestOffServices.check_out_of_join_date(data, profile.id):
             return Response(
                 {'error': 'There was a request for out of join date'},
                 status=status.HTTP_400_BAD_REQUEST)
         if RequestOffServices.check_available_date_off(
                 profile.id, type_off, data):
             return Response(
                 {'error': 'There was a request for over available day!'},
                 status=status.HTTP_400_BAD_REQUEST)
         if RequestOffServices.check_overlap_date(data, profile.id):
             return Response(
                 {'error': 'There was a request for this date!'},
                 status=status.HTTP_400_BAD_REQUEST)
         request_data = {"reason": data["reason"]}
         requestSerializer = RequestOffSerializer(data=request_data)
         with transaction.atomic():
             if requestSerializer.is_valid():
                 request_off = requestSerializer.save(type_off=type_off,
                                                      profile=profile)
             request_id = requestSerializer.data['id']
             for date in data["date"]:
                 date_data = {
                     "date": date["date"],
                     "type": date["type"],
                     "lunch": date["lunch"],
                     "request_off": request_id
                 }
                 dateSerializer = DateOffSerizlizer(data=date_data)
                 if dateSerializer.is_valid():
                     dateSerializer.save(request_off=request_off)
             ActionRequestService.create_action_user(
                 request_off, profile.line_manager)
             SendMailRequestOff.send_request(
                 type_off=type_off,
                 name_admin=profile.line_manager.name,
                 name_user=request_off.profile.name,
                 list_email=[profile.line_manager.user.email],
                 date_off=request_off.date_off.all())
         return Response(requestSerializer.data,
                         status=status.HTTP_201_CREATED)
     except:
         return Response({'Error': 'Error'},
                         status=status.HTTP_400_BAD_REQUEST)
Example #6
0
    def get(self, request):
        count = ActionRequestService.count_request(request.user.profile)
        data = {'count': count}

        return Response(data=data, status=status.HTTP_200_OK)
Example #7
0
 def test_services_approved_with_one_line_manage(self):
     request_detail = ActionRequestService.action_approve(self.request_of_user_4.id, self.user1_profile, '')
     self.assertEqual(request_detail.request_off.id, self.request_of_user_4.id)
     self.assertEqual(request_detail.status, Workday.STATUS_APPROVED)
     self.assertEqual(request_detail.request_off.status, Workday.STATUS_APPROVED)