Commit 78400ef5 authored by Gladys Forte's avatar Gladys Forte

form action and email initial

parent 3a35976d
......@@ -22,7 +22,9 @@ from rest_framework.exceptions import ValidationError
from django.db import transaction, IntegrityError, connection
from app.applicationlayer.utils import QuerySetHelper
from app.businesslayer.changerequest import change_request
from app.applicationlayer.cms.utils_cr import number_generator
from app.applicationlayer.cms.utils_cr import (number_generator,
send_mail_requestor,
next_appover_email)
from app.entities import enums
from django.forms.models import model_to_dict
......@@ -279,7 +281,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code).update(action=None, remarks=None,
date_sent=None)
date_sent=None, created=None)
return Response(
"Change request form successfully re routed",
......@@ -312,7 +314,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
models.ChangeRequestFormApprovers.objects.filter(
form_code=form_code).update(action=None, remarks=None,
date_sent=None)
date_sent=None, created=None)
return Response(
"Change request form successfully resubmitted",
......@@ -326,10 +328,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
)
def actions(self, request, *args, **kwargs):
form_code = kwargs['form_code']
print(form_code)
id = serializer.data['id']
id = request.data['id']
current_user = request.data['user']
form_code = request.data['form_code']
......@@ -338,12 +337,12 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
level = request.data['level']
next_level = int(request.data['level']) + 1
remarks = request.data['remarks']
print("level 1")
next_approver = models.ChangeRequestFormApprovers.objects.filter(
level=str(next_level),
form_code=form_code
)
print("level 2")
if action.lower() == 'approved':
models.ChangeRequestFormApprovers.objects.filter(
......@@ -365,7 +364,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
requestor_notification_msg, action, requestor_email_code,
remarks, level
)
print("level 3")
for n_approver in next_approver:
print(n_approver.user)
......@@ -600,7 +599,7 @@ class ChangeRequestFormApproversViewset(meviewsets.ModelViewSet):
email_code = VENDOR_ACKNOWLEDGE_MESSAGE.split(';')[1]
next_appover_email(
n_approver.user, form_code, delegation,
n_approver.user.code, form_code, delegation,
notification_msg, action, email_code
)
......
......@@ -6,29 +6,28 @@ import requests
from app.entities import models
from datetime import timedelta
from django.db.models import Q
# from dateutil import parser
# EMAIL = settings.EMAIL
# ACCOUNTS = settings.ACCOUNTS
# GROUPS = settings.GROUPS
# COMPANIES = settings.COMPANIES
# ALLOWED_COMPANY = settings.ALLOWED_COMPANY
# CR_FRONT_LINK = settings.CR_FRONT_LINK
from app.applicationlayer.utils import main_threading
from app.helper.email_service import sender
CR_FRONT_LINK = settings.CR_FRONT_LINK
# NOTIFICATION = settings.NOTIFICATION
def get_group_details(group_no):
return requests.get(f'{GROUPS}?group_no={group_no}').json()['results'][0]
def get_dept_details(dept_no):
dept_instance = models.Department.objects.filter(code=dept_no)
return dept_instance
def get_companies_details(slug):
return requests.get(f'{COMPANIES}?slug={slug}').json()['results'][0]
company_instance = models.Company.objects.filter(code=slug)
return company_instance
def get_account_details(id_number):
return requests.get(f'{ACCOUNTS}?id_number={id_number}').json()['results'][0]
account_instance = models.User.objects.filter(code=id_number)
return account_instance
def get_allowed_company(id_number):
......@@ -152,8 +151,7 @@ def receiver_body(
def get_template_instance(form_code):
template_instance = models.ChangeRequestFormHeader.objects.filter(
Q(form_code=form_code) &
Q(archived_at=None)
Q(form_code=form_code)
).first()
return template_instance
......@@ -219,7 +217,7 @@ def send_mail_vendor(receiver,
sender_account_id = sender_instance['id_number']
sender_name = sender_instance['name']
group = get_group_details(requested_to_department)
group = get_dept_details(requested_to_department)
group_name = group['name']
company = get_companies_details(requested_to_company)
......@@ -262,63 +260,74 @@ def send_mail_requestor(receiver,
cr_link = f'{CR_FRONT_LINK}/{form_code}'
template_instance = get_template_instance(form_code)
app = 'cms'
cr_number = template_instance.requested_to_template_id
template_name = template_instance.requested_to_template_name
requested_to_company = template_instance.requested_to_company
requested_to_department = template_instance.requested_to_department
requested_by_user = template_instance.requested_by_user
created = template_instance.created
requested_to_company = template_instance.requested_to_company.code
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
# receiver details --------------------------------------------------
requestor_instance = get_account_details(requested_by_user)
requestor_name = requestor_instance['name']
requestor_email = requestor_instance['email']
requestor_account_id = requestor_instance['id_number']
requestor_name = requestor_instance.values_list('name', flat=True)[0]
requestor_email = requestor_instance.values_list('email', flat=True)[0]
# sender details --------------------------------------------------
sender_instance = get_account_details(receiver)
sender_account_username = sender_instance['username']
sender_account_id = sender_instance['id_number']
sender_name = sender_instance['name']
sender_email = sender_instance.values_list('email', flat=True)[0]
sender_name = sender_instance.values_list('name', flat=True)[0]
group = get_group_details(requested_to_department)
group_name = group['name']
department = get_dept_details(requested_to_department)
dept_name = department.values_list('name', flat=True)[0]
company = get_companies_details(requested_to_company)
company_name = company['name']
data = receiver_body(
sender_account_id, requestor_account_id, code,
requestor_email, app, "False", requestor_name, routing_level,
action, cr_number, template_name, company_name, group_name,
requested_to_priority, cr_link
)
if action.lower() == 'approved':
new_body = {"approved_by": sender_name}
elif action.lower() == 'rejected':
new_body = {"rejected_by": sender_name,
"remarks": remarks}
elif action.lower() == 'completed':
new_body = {"completed_by": sender_name}
elif action.lower() == 'acknowledged':
new_body = {"acknowledge_by": sender_name}
data = {**data, **new_body}
email_status = requests.post(EMAIL, data=data)
message = f"{sender_name} {msg} ({template_name})"
notif = send_notification(
form_code, cr_number,
requestor_account_id, requestor_name,
message, app,
sender_account_id, sender_account_username
)
company_name = company.values_list('name', flat=True)[0]
# call sender email
name = requestor_name
action_by = sender_name
routing_level = routing_level
status = action
cr_number = cr_number
cr_name = template_name
company_requestedto = company_name
department_requestedto = dept_name
priority_level = requested_to_priority
url = cr_link
recipient = requestor_email
action_type = action
admin = sender_email
args = [name, action_by, routing_level, status, cr_number, cr_name,
company_requestedto, department_requestedto, priority_level,
url, recipient, action_type, admin]
main_threading(args, sender.routing_table_actions)
# if action.lower() == 'approved':
# new_body = {"approved_by": sender_name}
# elif action.lower() == 'rejected':
# new_body = {"rejected_by": sender_name,
# "remarks": remarks}
# elif action.lower() == 'completed':
# new_body = {"completed_by": sender_name}
# elif action.lower() == 'acknowledged':
# new_body = {"acknowledge_by": sender_name}
# data = {**data, **new_body}
# message = f"{sender_name} {msg} ({template_name})"
# notif = send_notification(
# form_code, cr_number,
# requestor_account_id, requestor_name,
# message, app,
# sender_account_id, sender_account_username
# )
def next_appover_email(receiver, form_code, delegation, msg, action, code):
......@@ -331,7 +340,6 @@ def next_appover_email(receiver, form_code, delegation, msg, action, code):
requested_to_company = template_instance.requested_to_company
requested_to_department = template_instance.requested_to_department
requested_by_user = template_instance.requested_by_user
created = template_instance.created
requested_to_priority = template_instance.requested_to_priority
# for rec in receiver:
......@@ -351,7 +359,7 @@ def next_appover_email(receiver, form_code, delegation, msg, action, code):
sender_account_id = sender_instance['id_number']
sender_name = sender_instance['name']
group = get_group_details(requested_to_department)
group = get_dept_details(requested_to_department)
group_name = group['name']
company = get_companies_details(requested_to_company)
......@@ -366,6 +374,8 @@ def next_appover_email(receiver, form_code, delegation, msg, action, code):
email_status = requests.post(EMAIL, data=data)
message = f"{sender_name} {msg} ({template_name})"
notif = send_notification(
......
This diff is collapsed.
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px" />
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Acknowledgement Notification</h3><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px" />
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Approval Notification</h3><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Accepted</h3><br>
<p>Dear {name},</p><br>
<p>A change request you have completed has been accepted by the requestor. Please see the details of your change request below.</p><br>
<b>Accepted By</b><br>{accepted_by}<br><br>
<b>Accepted By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Acknowledged</h3><br>
<p>Dear {name},</p><br>
<p>Your change request has been acknowledged. Please see the details of your change request below.</p><br>
<b>Acknowledged By</b><br>{acknowledge_by}<br><br>
<b>Acknowledged By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Approved</h3><br>
<p>Dear {name},</p><br>
<p>Your change request has been approved. Please see the details of your change request below.</p><br>
<b>Approved By</b><br>{approved_by}<br><br>
<b>Approved By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Cancelled</h3><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Completed</h3><br>
<p>Dear {name},</p><br>
<p>Your change request has been completed. Please see the details of your change request below.</p><br>
<b>Completed By</b><br>{completed_by}<br><br>
<b>Completed By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Target Date Overdue</h3><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Rejected</h3><br>
<p>Dear {name},</p><br>
<p>A change request you have completed has been rejected by the requestor.Please see the details of your change request below.</p><br>
<b>Rejected By</b><br>{rejected_by}<br><br>
<b>Rejected By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,15 +5,13 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Rejected</h3><br>
<p>Dear {name},</p><br>
<p>Your change request has been rejected. Please see the details of your change request below.</p><br>
<b>Rejected By</b><br>{rejected_by}<br><br>
<b>Rejected By</b><br>{action_by}<br><br>
<b>Routing Level</b><br>{routing_level}<br><br>
<b>Status</b><br>{status}<br><br><br>
......
......@@ -5,10 +5,6 @@
</head>
<body style="font-family: arial;">
<div style="max-width:100px!important;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg"/>
</div>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">New User Created</h3><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Reset Password</h3><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Approval Reminder</h3><br>
......
......@@ -5,8 +5,6 @@
</head>
<body style="font-family: arial;">
<img src="https://s18.directupload.net/images/190807/wjwrxx5i.jpg" width="100px"/>
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Approval Reminder</h3><br>
......
......@@ -41,3 +41,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
#ADMIN PROFILE
CATCH_EMAIL = config['DEV']['CATCH_EMAIL']
CR_FRONT_LINK = config['CR_FRONT_LINK']['CR_LINK']
......@@ -39,3 +39,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
#ADMIN PROFILE
CATCH_EMAIL = config['LOCAL']['CATCH_EMAIL']
CR_FRONT_LINK = config['CR_FRONT_LINK']['CR_LINK']
......@@ -41,3 +41,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
#ADMIN PROFILE
CATCH_EMAIL = config['PRODUCTION']['CATCH_EMAIL']
CR_FRONT_LINK = config['CR_FRONT_LINK']['CR_LINK']
......@@ -42,3 +42,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
#ADMIN PROFILE
CATCH_EMAIL = config['UAT']['CATCH_EMAIL']
CR_FRONT_LINK = config['CR_FRONT_LINK']['CR_LINK']
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