Esempio n. 1
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)
Esempio n. 2
0
 def test_method_check_available_date_off_output_false(self):
     valid_data = {
         "date": [{
             "date": "2026-09-30",
             "type": "All day",
             "lunch": "False"
         }]
     }
     boolean = RequestOffServices.check_available_date_off(
         self.user1_profile.id, self.type_off_company_pay, valid_data)
     self.assertFalse(boolean)
Esempio n. 3
0
 def test_method_check_available_date_off_with_many_date_input(self):
     valid_data = {
         "date": [{
             "date": "2026-10-30",
             "type": "All day",
             "lunch": "False"
         }, {
             "date": "2025-11-30",
             "type": "All day",
             "lunch": "True"
         }, {
             "date": "2025-09-30",
             "type": "All day",
             "lunch": "True"
         }]
     }
     boolean = RequestOffServices.check_available_date_off(
         self.user3_profile.id, self.type_off_company_pay, valid_data)
     self.assertFalse(boolean)
Esempio n. 4
0
 def test_method_check_available_date_off_output_true(self):
     self.date_off_2 = DateOffFactory(request_off=self.request_off_user1,
                                      date="2026-09-30")
     boolean = RequestOffServices.check_available_date_off(
         self.user1_profile.id, self.type_off_company_pay, self.valid_data)
     self.assertTrue(boolean)
Esempio n. 5
0
 def test_method_check_available_date_off_with_type_off_company_pay(self):
     boolean = RequestOffServices.check_available_date_off(
         self.user1_profile.id, self.type_off_company_pay, self.valid_data)
     self.assertFalse(boolean)
Esempio n. 6
0
 def test_method_check_overlap_date_with_request_off_status_cancel_reject(
         self):
     boolean = RequestOffServices.check_overlap_date(
         self.valid_data, self.user2_profile.id)
     self.assertFalse(boolean)
Esempio n. 7
0
 def test_method_check_overlap_date_without_request_list(self):
     boolean = RequestOffServices.check_overlap_date(
         self.valid_data, self.user2_profile.id)
     self.assertFalse(boolean)
Esempio n. 8
0
 def test_method_check_overlap_date_output_true(self):
     self.date_off_2 = DateOffFactory(request_off=self.request_off_user1,
                                      date="2026-09-30")
     boolean = RequestOffServices.check_overlap_date(
         self.valid_data, self.user1_profile.id)
     self.assertTrue(boolean)
Esempio n. 9
0
 def test_method_check_overlap_date_output_false(self):
     boolean = RequestOffServices.check_overlap_date(
         self.valid_data, self.user1_profile.id)
     self.assertFalse(boolean)