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(
'tmp_details')
read_only_fields = ['created', 'template_no']
class ChangeRequestTemplatesSerializerList(
serializers.ModelSerializer
):
......
......@@ -187,7 +187,7 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet):
except Exception as e:
return Response(e,
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@transaction.atomic
def partial_update(self, request, *args, **kwargs):
......@@ -348,12 +348,12 @@ class ChangeRequestTemplatePost(APIView):
def post(self, request):
template_header = request.data
try:
try:
data_list_approver = []
data_list_stake = []
data_list_attach = []
data_list_detail = []
template_header_data = {
'requested_to_template_name': template_header['requested_to_template_name'],
'requested_to_template_id': template_header['requested_to_template_id'],
......
......@@ -4,7 +4,9 @@ import json
from rest_framework.exceptions import ParseError
from functools import wraps
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 django.db.models import Q
from app.businesslayer.changerequest.change_request_template import (
......@@ -285,62 +287,57 @@ def TemplateValidation(function):
def wrapper(self, request, *args, **kwargs):
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
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)
return error_message('400', 'Superuser department cannot be selected',
'failed', 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)
return error_message('400', 'Please make sure to add an Approver, Vendor and Requestor into routing table',
'failed', 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)
return error_message('400', 'Please add Vendor/Implementor and Requestor into routing table',
'failed', 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 error_message('400', validation_result + ' is already exist for the same level of approval.',
'failed', status.HTTP_400_BAD_REQUEST)
# Do not allow saving user as Vendor and other delegation
validate = validation_poc_vendor_only(
template_header['requested_to_user'], tmp_approvers)
if validate is True:
message = {
'code': 400,
'status': 'failed',
'message': 'Point of contact can only be assign to Vendor/Implementor',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
return error_message('400', 'Point of contact can only be assign to Vendor/Implementor',
'failed', 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