Commit 8fd04052 authored by Gladys Forte's avatar Gladys Forte

fix status on email, added object template_no

parent 42b9cd97
......@@ -71,7 +71,8 @@ class ChangeRequestFormHeaderSerializer(
ret['requested_to_user'] = requested_to_user
ret['requested_by_user'] = requested_by_user
ret['requested_by_department'] = model_to_dict(instance.requested_by_department)
ret['template_no'] = model_to_dict(instance.template_no)
return ret
except Exception as e:
ret['action_required'] = "None"
......@@ -80,6 +81,7 @@ class ChangeRequestFormHeaderSerializer(
ret['requested_to_user'] = "None"
ret['requested_by_user'] ="None"
ret['requested_by_department'] = "None"
ret['template_no'] = "None"
return ret
......
......@@ -700,6 +700,21 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
)
# action
if action.lower() == 'approved':
the_next_vendor = models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code, level=int(next_level),
delegation='Vendor/Implementor'
).first()
if the_next_vendor:
the_last_vendor = models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code, delegation='Vendor/Implementor'
).order_by('level').last()
if the_next_vendor == the_last_vendor:
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Approved')
# NOTIF MSG FOR REQUESTOR
requestor_notification_msg = REQUESTOR_MESSAGE.split(';')[0]
......@@ -730,23 +745,12 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
).update(
is_action=False
)
the_next_vendor = models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code, level=int(next_level),
delegation='Vendor/Implementor'
).first()
if the_next_vendor:
the_last_vendor = models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code, delegation='Vendor/Implementor'
).order_by('level').last()
if the_next_vendor == the_last_vendor:
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Approved')
elif action.lower() == 'rejected':
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Rejected')
# send email to vendor
if delegation.lower() == 'requestor':
......@@ -767,10 +771,6 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
requestor_notification_msg, action,
remarks, level
)
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Rejected')
# update is_action for current level
models.ChangeRequestFormApprovers.objects.filter(
......@@ -781,15 +781,6 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
elif action.lower() == 'completed':
# EMAIL CODE FOR REQUESTOR
requestor_notification_msg = REQUESTOR_COMPLETION_MESSAGE.split(';')[0]
send_mail_requestor(
current_user, form_code, delegation,
requestor_notification_msg, action,
remarks, level
)
the_last_vendor = models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code, delegation='Vendor/Implementor'
).order_by('level').last()
......@@ -831,6 +822,15 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
is_action=False
)
# EMAIL CODE FOR REQUESTOR
requestor_notification_msg = REQUESTOR_COMPLETION_MESSAGE.split(';')[0]
send_mail_requestor(
current_user, form_code, delegation,
requestor_notification_msg, action,
remarks, level
)
elif action.lower() == 'acknowledged':
# EMAIL CODE FOR REQUESTOR
......@@ -844,6 +844,10 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
elif action.lower() == 'accepted':
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Closed')
# EMAIL CODE FOR VENDOR
requestor_notification_msg = VENDOR_ACCEPTANCE_MESSAGE.split(';')[0]
......@@ -853,10 +857,6 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
remarks, level
)
models.ChangeRequestFormHeader.objects.filter(
form_code=form_code
).update(status='Closed')
# update is_action for current level
models.ChangeRequestFormApprovers.objects.filter(
Q(form_code=form_code) & Q(level=int(level))
......@@ -1281,23 +1281,6 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
)
# data_list_attach = []
# # create form attachments
# if attach_body['attachments']:
# frm_attachments = attach_body['attachments']
# for frm_attachment in frm_attachments:
# frm_attachment['form_code'] = form_code
# frm_attachment['uploaded_by'] = id_number
# data_list_attach.append(frm_attachment)
# serializerAttach = ChangeRequestFormAttachmentsSerializer(
# data=data_list_attach, many=True)
# if serializerAttach.is_valid(raise_exception=True):
# serializerAttach.save()
message = status_message_response(
200, 'success',
'Attachments successfully updated!',
......
......@@ -265,11 +265,14 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet):
return Response(message, status=status.HTTP_200_OK)
return Response(
"Unable to edit due to existing transaction",
status=status.HTTP_400_BAD_REQUEST
message = status_message_response(
400, 'failed',
'Unable to update due to existing transaction',
''
)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
@action(
methods=['GET'], detail=False,
url_path='archived', url_name='archived'
......@@ -367,7 +370,7 @@ class ChangeRequestTemplatePost(APIView):
if serializer.is_valid(raise_exception=True):
serializer.save()
tmp_id = serializer.data['template_no']
# create template approvers
......
......@@ -234,7 +234,7 @@ def send_mail_requestor(current_user,
requested_to_department = template_instance.requested_to_department.code
requested_by_user = template_instance.requested_by_user.code
requested_to_priority = template_instance.requested_to_priority
cr_status = template_instance.status
# receiver details --------------------------------------------------
requestor_instance = get_account_details(requested_by_user)
......@@ -258,7 +258,7 @@ def send_mail_requestor(current_user,
name = requestor_name
action_by = sender_name
routing_level = routing_level
status = action
status = cr_status
cr_number = cr_number
cr_name = template_name
company_requestedto = company_name
......
......@@ -376,6 +376,7 @@ def attachment_add_edit_delete(form_request_body,
partial=partial)
serializer.is_valid(raise_exception=True)
old_instance = model_to_dict(frm_instance)
self.perform_update(serializer)
new_instance = serializer.data
......
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