Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4369 patch 2 #4621

Merged
merged 8 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions request-management-api/request_api/models/FOIRawRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,14 @@ def getonholdapplicationfeerequests(cls): # with the reminder date
onholdapplicationfeerequests = []
try:
sql = '''
SELECT * FROM (SELECT DISTINCT ON (requestid) requestid, (updated_at + INTERVAL '20 days') as reminder_date, status FROM public."FOIRawRequests"
SELECT * FROM (SELECT DISTINCT ON (requestid) requestid, updated_at, status FROM public."FOIRawRequests"
ORDER BY requestid ASC, version DESC) r
WHERE r.status = 'On-Hold - Application Fee'
and r.reminder_date::date = now()::date
order by r.reminder_date asc
AND r.updated_at::date < NOW()::date - INTERVAL '15 DAY'
order by r.updated_at asc
'''
rs = db.session.execute(text(sql))
for row in rs:
if row.status == 'On-Hold - Application Fee':
onholdapplicationfeerequests.append(row)
onholdapplicationfeerequests = rs
except Exception as ex:
logging.error(ex)
raise ex
Expand Down
23 changes: 16 additions & 7 deletions request-management-api/request_api/services/events/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pytz import timezone
from request_api.utils.enums import PaymentEventType
from request_api.utils.commons.datetimehandler import datetimehandler
from request_api.services.commons.duecalculator import duecalculator
from request_api.exceptions import BusinessException
from flask import current_app

Expand Down Expand Up @@ -43,15 +44,20 @@ def createpaymentreminderevent(self):
_today = datetimehandler().gettoday()

notificationservice().dismissremindernotification("rawrequest", self.__notificationtype())
# ca_holidays = duecalculator.getholidays()
eventtype = PaymentEventType.reminder.value
_onholdrequests = FOIRawRequest.getonholdapplicationfeerequests()
for entry in _onholdrequests:
_reminderdate = datetimehandler().formatdate(entry['reminder_date'])
if _reminderdate == _today:
_dateofstatechange = datetimehandler().formatdate(entry['updated_at'])
businessdayselapsed = duecalculator().getbusinessdaysbetween(_dateofstatechange)
if businessdayselapsed >= 20 and duecalculator().isbusinessday(_today):
commentexists = False
existingcomments = commentservice().getrawrequestcomments(entry['requestid'])
for comment in existingcomments:
if comment['text'] == self.__preparecomment(entry['requestid'], eventtype)['comment']: #checks if comment already exists
commentexists = True
if not commentexists:
self.__createcommentforrawrequest(entry['requestid'], eventtype)
self.__createnotificationforrawrequest(entry['requestid'], eventtype)
self.__createcommentforrawrequest(entry['axisrequestid'], eventtype)
pass
return DefaultMethodResult(True,'Payment reminder notifications created',_today)
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('Payment reminder Notification Error', exception.message))
Expand All @@ -63,7 +69,7 @@ def __createcommentforrawrequest(self, requestid, eventtype):

def __createnotificationforrawrequest(self, requestid, eventtype):
notification = self.__preparenotification(requestid, eventtype)
return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", "Payment", "system")
return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", self.__notificationtype(), "system")

def __createcomment(self, requestid, eventtype):
comment = self.__preparecomment(requestid, eventtype)
Expand All @@ -86,7 +92,7 @@ def __preparecomment(self, requestid, eventtype):
elif eventtype == PaymentEventType.depositpaid.value:
comment = {"comment": "Applicant has paid deposit. New LDD is " + FOIMinistryRequest.getduedate(requestid).strftime("%m/%d/%Y")}
elif eventtype == PaymentEventType.reminder.value:
comment = {"comment": f"Request {requestid} - 20 business days has passed awaiting payment, you can consider closing the request as abandoned"}
comment = {"comment": "20 business days has passed awaiting payment, you can consider closing the request as abandoned"}
else:
comment = None
if comment is not None:
Expand Down Expand Up @@ -116,3 +122,6 @@ def __defaultuserid(self):
def gettoday(self):
now_pst = maya.parse(maya.now()).datetime(to_timezone='America/Vancouver', naive=False)
return now_pst.strftime('%m/%d/%Y')

def __notificationtype(self):
return "Payment"