Commit 9f599e56 authored by John Red Medrano's avatar John Red Medrano

Merge branch 'RMSv2' of http://42.61.118.105:7990/scm/rms/api-main-service...

Merge branch 'RMSv2' of http://42.61.118.105:7990/scm/rms/api-main-service into core-dev-red-develop
parents 32a4c227 32fcfbe1
......@@ -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 = []
......
......@@ -35,6 +35,7 @@ from app.applicationlayer.cms.template.attachment.serializers import ChangeReque
from app.applicationlayer.cms.template.header.serializers import ChangeRequestTemplatesSerializer
from app.applicationlayer.cms.template.header.serializers import ChangeRequestTemplatesSerializerList
from app.applicationlayer.cms.template.header.table_filters import HeaderFilterSet
from app.helper.decorators import *
# from django_filters import rest_framework as filters
......@@ -341,56 +342,12 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet):
class ChangeRequestTemplatePost(APIView):
@TemplateValidation
@transaction.atomic()
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 = []
......
......@@ -7,6 +7,12 @@ from rest_framework.authtoken.models import Token
from app.entities.models import User, Department, Company
from app.entities import enums
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_approver
)
def error_safe(function):
......@@ -245,3 +251,120 @@ class rms:
return function(self, request, *args, **kwargs)
return wrapper
def TemplateValidation(function):
@wraps(function)
def wrapper(self, request, *args, **kwargs):
template_header = request.data
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 exist 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(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 = 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 = validation_approver_same_level(frm_approvers)
if validation_result is not None:
message = {
'code': 400,
'status': 'failed',
'message': validation_result + ' is already exist 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 = 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