Commit 7af56ac6 authored by Gladys Forte's avatar Gladys Forte

template header validations

parent a92d24f0
......@@ -24,7 +24,8 @@ from app.applicationlayer.utils import log_save, CustomPagination
from rest_framework.exceptions import ParseError
from app.businesslayer.changerequest.change_request_template import (
tmp_add_edit_delete,
validation_approver_same_level
validation_approver_same_level,
validation_existing_vendor_requestor
)
from app.applicationlayer.management.account.serializer import ChangeRequestList
from app.applicationlayer.cms.template.approver.serializers import ChangeRequestTemplateApproversSerializer
......@@ -345,18 +346,50 @@ class ChangeRequestTemplatePost(APIView):
template_header = request.data
try:
# tmp_approvers = template_header['tmp_approvers']
# # Do not allow adding an approver for the same level
# validation_result = validation_approver_same_level(tmp_approvers)
# if validation_result is not None:
# message = {
# 'code': 400,
# 'status': 'failed',
# 'message': validation_result + ' is already existing for the same level of approval.',
# }
# return Response(message,
# status=status.HTTP_400_BAD_REQUEST)
# restrict superuser department
if (template_header['created_by_department'] == 'DEPARTMENT-20190923-0000001' or
template_header['requested_to_department'] == 'DEPARTMENT-20190923-0000001'):
message = {
'code': 400,
'status': 'failed',
'message': 'Superuser department cannot be selected',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
tmp_approvers = template_header['tmp_approvers']
# Check if Vendor and Requestor are existing on routing table
if len(tmp_approvers) < 2:
message = {
'code': 400,
'status': 'failed',
'message': 'Please make sure to add an Approver, Vendor and Requestor into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
else:
result = validation_existing_vendor_requestor(tmp_approvers)
if result is False:
message = {
'code': 400,
'status': 'failed',
'message': 'Please add Vendor/Implementor and Requestor into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
# Do not allow adding an approver for the same level
validation_result = validation_approver_same_level(tmp_approvers)
if validation_result is not None:
message = {
'code': 400,
'status': 'failed',
'message': validation_result + ' is already existing for the same level of approval.',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
data_list_approver = []
data_list_stake = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment