Commit d0036ae0 authored by Gladys Forte's avatar Gladys Forte

{dev bugfix} check if cr prefix exists in template

parent 38b5df47
...@@ -94,8 +94,8 @@ class ChangeRequestTemplatesSerializer( ...@@ -94,8 +94,8 @@ class ChangeRequestTemplatesSerializer(
'tmp_details') 'tmp_details')
read_only_fields = ['created', 'template_no'] read_only_fields = ['created', 'template_no']
class ChangeRequestTemplatesSerializerList( class ChangeRequestTemplatesSerializerList(
serializers.ModelSerializer serializers.ModelSerializer
): ):
......
...@@ -187,7 +187,7 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet): ...@@ -187,7 +187,7 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet):
except Exception as e: except Exception as e:
return Response(e, return Response(e,
status=status.HTTP_500_INTERNAL_SERVER_ERROR) status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@transaction.atomic @transaction.atomic
def partial_update(self, request, *args, **kwargs): def partial_update(self, request, *args, **kwargs):
...@@ -348,12 +348,12 @@ class ChangeRequestTemplatePost(APIView): ...@@ -348,12 +348,12 @@ class ChangeRequestTemplatePost(APIView):
def post(self, request): def post(self, request):
template_header = request.data template_header = request.data
try: try:
data_list_approver = [] data_list_approver = []
data_list_stake = [] data_list_stake = []
data_list_attach = [] data_list_attach = []
data_list_detail = [] data_list_detail = []
template_header_data = { template_header_data = {
'requested_to_template_name': template_header['requested_to_template_name'], 'requested_to_template_name': template_header['requested_to_template_name'],
'requested_to_template_id': template_header['requested_to_template_id'], 'requested_to_template_id': template_header['requested_to_template_id'],
......
...@@ -4,7 +4,9 @@ import json ...@@ -4,7 +4,9 @@ import json
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from functools import wraps from functools import wraps
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from app.entities.models import User, Department, Company from app.entities.models import (User, Department, Company,
ChangeRequestTemplateHeader,
ChangeRequestFormHeader)
from app.entities import enums from app.entities import enums
from django.db.models import Q from django.db.models import Q
from app.businesslayer.changerequest.change_request_template import ( from app.businesslayer.changerequest.change_request_template import (
...@@ -285,62 +287,57 @@ def TemplateValidation(function): ...@@ -285,62 +287,57 @@ def TemplateValidation(function):
def wrapper(self, request, *args, **kwargs): def wrapper(self, request, *args, **kwargs):
template_header = request.data template_header = request.data
required = {'requested_to_template_name': 'Template Name',
'requested_to_template_id': 'CR Number prefix',
'requested_to_target_date': 'Lead Time',
'requested_to_company': 'Company',
'requested_to_department': 'Department'}
for key in required.keys():
if not key in template_header or template_header[key] == '':
return error_message('400', required[key] + ' is required',
'failed', status.HTTP_400_BAD_REQUEST)
# Check if prefix already exists
prefix = ChangeRequestTemplateHeader.objects.get(
requested_to_template_id=template_header['requested_to_template_id'])
if prefix:
return error_message('400', 'CR Number prefix already exists.',
'failed', status.HTTP_400_BAD_REQUEST)
# Restrict form using Superuser Department
if (template_header['created_by_department'] == 'DEPARTMENT-20190923-0000001' or if (template_header['created_by_department'] == 'DEPARTMENT-20190923-0000001' or
template_header['requested_to_department'] == 'DEPARTMENT-20190923-0000001'): template_header['requested_to_department'] == 'DEPARTMENT-20190923-0000001'):
message = { return error_message('400', 'Superuser department cannot be selected',
'code': 400, 'failed', status.HTTP_400_BAD_REQUEST)
'status': 'failed',
'message': 'Superuser department cannot be selected',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
tmp_approvers = template_header['tmp_approvers'] tmp_approvers = template_header['tmp_approvers']
# Check if Vendor and Requestor are existing on routing table # Check if Vendor and Requestor are existing on routing table
if len(tmp_approvers) < 2: if len(tmp_approvers) < 2:
message = { return error_message('400', 'Please make sure to add an Approver, Vendor and Requestor into routing table',
'code': 400, 'failed', status.HTTP_400_BAD_REQUEST)
'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: else:
result = validation_existing_vendor_requestor(tmp_approvers) result = validation_existing_vendor_requestor(tmp_approvers)
if result is False: if result is False:
message = { return error_message('400', 'Please add Vendor/Implementor and Requestor into routing table',
'code': 400, 'failed', status.HTTP_400_BAD_REQUEST)
'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 # Do not allow adding an approver for the same level
validation_result = validation_approver_same_level(tmp_approvers) validation_result = validation_approver_same_level(tmp_approvers)
if validation_result is not None: if validation_result is not None:
message = { return error_message('400', validation_result + ' is already exist for the same level of approval.',
'code': 400, 'failed', status.HTTP_400_BAD_REQUEST)
'status': 'failed',
'message': validation_result + ' is already exist for the same level of approval.',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
# Do not allow saving user as Vendor and other delegation # Do not allow saving user as Vendor and other delegation
validate = validation_poc_vendor_only( validate = validation_poc_vendor_only(
template_header['requested_to_user'], tmp_approvers) template_header['requested_to_user'], tmp_approvers)
if validate is True: if validate is True:
message = { return error_message('400', 'Point of contact can only be assign to Vendor/Implementor',
'code': 400, 'failed', status.HTTP_400_BAD_REQUEST)
'status': 'failed',
'message': 'Point of contact can only be assign to Vendor/Implementor',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
return function(self, request, *args, **kwargs) return function(self, request, *args, **kwargs)
return wrapper 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