Commit 38b5df47 authored by Gladys Forte's avatar Gladys Forte

{dev bugfix} Validate if poc is assigned to another delegation other than...

{dev bugfix} Validate if poc is assigned to another delegation other than Vendor (Template Post and Form Post
parent 91b6c315
......@@ -17,18 +17,18 @@ class ChangeRequestFormAttachmentsSerializer(
"contact_no": instance.uploaded_by.contact_no
}
ret['uploaded_by'] = user_object
ret['file_upload'] = self.context['request'].build_absolute_uri(
instance.file_upload.url.url)
ret['file_upload_id'] = instance.file_upload.id
return ret
class Meta:
model = models.ChangeRequestFormAttachments
fields = '__all__'
read_only_fields = ['created', 'code']
class ChangeRequestFormAttachmentsFileUploadSerializer(
serializers.ModelSerializer
):
......
......@@ -36,7 +36,8 @@ from app.applicationlayer.cms.utils_cr import (number_generator,
entity_log_bulk,
reminder_trigger_save,
overdue_trigger_save,
reset_autoemail_tables)
reset_autoemail_tables,
delete_master_attachment_file)
from app.entities import enums
from app.applicationlayer.utils import model_to_dict
......@@ -1375,6 +1376,7 @@ class ChangeRequestFormPost(APIView):
except Exception as e:
transaction.savepoint_rollback(sp1)
message = {
'code': 500,
'status': 'failed',
......
......@@ -455,14 +455,14 @@ class ChangeRequestTemplatePost(APIView):
'message': str(e),
}
return Response(message, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
transaction.savepoint_rollback(sp1)
if template_header['tmp_attachments']:
delete_master_attachment_file(
template_header['tmp_attachments'])
message = {
'code': 500,
'status': 'failed',
......
......@@ -157,3 +157,20 @@ def validation_approver_same_level(approvers):
return user_name
return None
# Check if poc is assigned to another delegation other than Vendor
def validation_poc_vendor_only(poc, approvers):
validate = False
for approver in approvers:
if 'user' in approver and 'delegation' in approver:
if poc == approver['user']:
if not approver['delegation'] == 'DELEGATION-20191119-0000002':
validate = True
return validate
......@@ -11,7 +11,8 @@ from app.businesslayer.changerequest.change_request_template import (
tmp_add_edit_delete,
validation_approver_same_level,
validation_existing_vendor_requestor,
validation_existing_approver
validation_existing_approver,
validation_poc_vendor_only
)
from app.applicationlayer.utils import error_message
......@@ -295,7 +296,7 @@ def TemplateValidation(function):
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 = {
......@@ -327,6 +328,18 @@ def TemplateValidation(function):
}
return Response(message,
status=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 function(self, request, *args, **kwargs)
return wrapper
......@@ -391,6 +404,18 @@ def FormValidation(function):
'message': 'Please select at least 1 approver before submitting this request.',
}
return Response(message, status=status.HTTP_400_BAD_REQUEST)
# Do not allow saving user as Vendor and other delegation
validate = validation_poc_vendor_only(
form_header['requested_to_user'], frm_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 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