Commit 800ce8e0 authored by Gladys Forte's avatar Gladys Forte

Require Approver in Creating CR -...

Require Approver in Creating CR - http://54.169.104.100:27015/rms/rms-backend/issues/1 - all validations add to decorator
parent ed98e131
......@@ -73,6 +73,7 @@ from django.conf import settings
from io import BytesIO
from django.http import HttpResponse
from xhtml2pdf import pisa
from app.helper.decorators import *
config = configparser.ConfigParser()
......@@ -1178,67 +1179,11 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
class ChangeRequestFormPost(APIView):
@FormValidation
@transaction.atomic()
def post(self, request):
form_header = request.data
try:
# restrict superuser department
if (form_header['requested_by_department'] == 'DEPARTMENT-20190923-0000001' or
form_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)
frm_approvers = form_header['frm_approvers']
# Check if Vendor and Requestor are existing on routing table
if len(frm_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 = change_request_template.validation_existing_vendor_requestor(frm_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 = change_request_template.validation_approver_same_level(frm_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 a requestor to submit a CR without atleast 1 approver
counter = change_request_template.validation_existing_approver(frm_approvers)
if form_header['status'].lower() == 'pending' and counter == 0:
message = {
'code': 400,
'status': 'failed',
'message': 'Please select at least 1 approver before submitting this request.',
}
return Response(message, status=status.HTTP_400_BAD_REQUEST)
data_list_approver = []
data_list_stake = []
data_list_attach = []
......
......@@ -347,52 +347,7 @@ class ChangeRequestTemplatePost(APIView):
def post(self, request):
template_header = request.data
try:
# 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)
try:
data_list_approver = []
data_list_stake = []
data_list_attach = []
......
......@@ -10,7 +10,8 @@ from django.db.models import Q
from app.businesslayer.changerequest.change_request_template import (
tmp_add_edit_delete,
validation_approver_same_level,
validation_existing_vendor_requestor
validation_existing_vendor_requestor,
validation_existing_approver
)
......@@ -232,18 +233,72 @@ def TemplateValidation(function):
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': 'Superuser department cannot be selected',
'message': 'Please add Vendor/Implementor and Requestor into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
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)
return function(self, request, *args, **kwargs)
return wrapper
def FormValidation(function):
@wraps(function)
def wrapper(self, request, *args, **kwargs):
form_header = request.data
# restrict superuser department
if (form_header['requested_by_department'] == 'DEPARTMENT-20190923-0000001' or
form_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)
frm_approvers = form_header['frm_approvers']
# Check if Vendor and Requestor are existing on routing table
if len(tmp_approvers) < 2:
if len(frm_approvers) < 2:
message = {
'code': 400,
'status': 'failed',
......@@ -252,7 +307,7 @@ def TemplateValidation(function):
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
else:
result = validation_existing_vendor_requestor(tmp_approvers)
result = validation_existing_vendor_requestor(frm_approvers)
if result is False:
message = {
......@@ -264,7 +319,7 @@ def TemplateValidation(function):
status=status.HTTP_400_BAD_REQUEST)
# Do not allow adding an approver for the same level
validation_result = validation_approver_same_level(tmp_approvers)
validation_result = validation_approver_same_level(frm_approvers)
if validation_result is not None:
message = {
'code': 400,
......@@ -273,6 +328,16 @@ def TemplateValidation(function):
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
# Restrict a requestor to submit a CR without atleast 1 approver
counter = validation_existing_approver(frm_approvers)
if form_header['status'].lower() == 'pending' and counter == 0:
message = {
'code': 400,
'status': 'failed',
'message': 'Please select at least 1 approver before submitting this request.',
}
return Response(message, status=status.HTTP_400_BAD_REQUEST)
return function(self, request, *args, **kwargs)
return wrapper
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