From 1d255da14263661f626f66923d343d3243711e62 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 11:47:41 -0700 Subject: [PATCH 1/8] Add self.__notificationtype and fix messaging --- .../request_api/models/FOIRawRequests.py | 4 +--- .../request_api/services/events/payment.py | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/request-management-api/request_api/models/FOIRawRequests.py b/request-management-api/request_api/models/FOIRawRequests.py index eb528090d..5d7cc7377 100644 --- a/request-management-api/request_api/models/FOIRawRequests.py +++ b/request-management-api/request_api/models/FOIRawRequests.py @@ -373,9 +373,7 @@ def getonholdapplicationfeerequests(cls): # with the reminder date order by r.reminder_date 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 diff --git a/request-management-api/request_api/services/events/payment.py b/request-management-api/request_api/services/events/payment.py index 3c137d8ad..0dfdf1932 100644 --- a/request-management-api/request_api/services/events/payment.py +++ b/request-management-api/request_api/services/events/payment.py @@ -50,8 +50,7 @@ def createpaymentreminderevent(self): _reminderdate = datetimehandler().formatdate(entry['reminder_date']) if _reminderdate == _today: self.__createnotificationforrawrequest(entry['requestid'], eventtype) - self.__createcommentforrawrequest(entry['axisrequestid'], eventtype) - pass + self.__createcommentforrawrequest(entry['requestid'], eventtype) return DefaultMethodResult(True,'Payment reminder notifications created',_today) except BusinessException as exception: current_app.logger.error("%s,%s" % ('Payment reminder Notification Error', exception.message)) @@ -63,7 +62,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) @@ -86,7 +85,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: @@ -116,3 +115,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" \ No newline at end of file From 544c79a62b5fb455b6565f251965decf3a068db1 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 11:56:45 -0700 Subject: [PATCH 2/8] Fix function call --- request-management-api/request_api/services/events/payment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-management-api/request_api/services/events/payment.py b/request-management-api/request_api/services/events/payment.py index 0dfdf1932..cef581a14 100644 --- a/request-management-api/request_api/services/events/payment.py +++ b/request-management-api/request_api/services/events/payment.py @@ -62,7 +62,7 @@ def __createcommentforrawrequest(self, requestid, eventtype): def __createnotificationforrawrequest(self, requestid, eventtype): notification = self.__preparenotification(requestid, eventtype) - return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", self.__notificationtype, "system") + return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", self.__notificationtype(), "system") def __createcomment(self, requestid, eventtype): comment = self.__preparecomment(requestid, eventtype) From 0343476aef2ae13153feac341cd2261fff13fc8e Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 12:03:58 -0700 Subject: [PATCH 3/8] Adjust interval to match business days --- request-management-api/request_api/models/FOIRawRequests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-management-api/request_api/models/FOIRawRequests.py b/request-management-api/request_api/models/FOIRawRequests.py index 5d7cc7377..2521aea26 100644 --- a/request-management-api/request_api/models/FOIRawRequests.py +++ b/request-management-api/request_api/models/FOIRawRequests.py @@ -366,7 +366,7 @@ 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 + INTERVAL '28 days') as reminder_date, 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 From 6af1a00b6f3cbbc45545c87e9e184c8b5e2c8465 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 13:57:23 -0700 Subject: [PATCH 4/8] Update SQL to use state changed date --- request-management-api/request_api/models/FOIRawRequests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/request-management-api/request_api/models/FOIRawRequests.py b/request-management-api/request_api/models/FOIRawRequests.py index 2521aea26..bbe7c1118 100644 --- a/request-management-api/request_api/models/FOIRawRequests.py +++ b/request-management-api/request_api/models/FOIRawRequests.py @@ -366,11 +366,11 @@ def getonholdapplicationfeerequests(cls): # with the reminder date onholdapplicationfeerequests = [] try: sql = ''' - SELECT * FROM (SELECT DISTINCT ON (requestid) requestid, (updated_at + INTERVAL '28 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 BETWEEN NOW()::date - INTERVAL '35 DAY' AND NOW()::date + INTERVAL '1 DAY' + order by r.updated_at asc ''' rs = db.session.execute(text(sql)) onholdapplicationfeerequests = rs From bd9dc56ada4b0a38f6d0bbaca964cd3da16baf53 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 14:00:22 -0700 Subject: [PATCH 5/8] Calculate relative to business days --- .../request_api/services/events/payment.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/request-management-api/request_api/services/events/payment.py b/request-management-api/request_api/services/events/payment.py index cef581a14..fd467e7be 100644 --- a/request-management-api/request_api/services/events/payment.py +++ b/request-management-api/request_api/services/events/payment.py @@ -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 @@ -43,12 +44,12 @@ 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): self.__createnotificationforrawrequest(entry['requestid'], eventtype) self.__createcommentforrawrequest(entry['requestid'], eventtype) return DefaultMethodResult(True,'Payment reminder notifications created',_today) From 29c21bd64d1116d3fe86dfa0ce0179cd2d416d4e Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 15:06:01 -0700 Subject: [PATCH 6/8] Change notification logic to include older requests --- .../request_api/services/events/payment.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/request-management-api/request_api/services/events/payment.py b/request-management-api/request_api/services/events/payment.py index fd467e7be..f3a864be1 100644 --- a/request-management-api/request_api/services/events/payment.py +++ b/request-management-api/request_api/services/events/payment.py @@ -49,9 +49,15 @@ def createpaymentreminderevent(self): for entry in _onholdrequests: _dateofstatechange = datetimehandler().formatdate(entry['updated_at']) businessdayselapsed = duecalculator().getbusinessdaysbetween(_dateofstatechange) - if businessdayselapsed == 20 and duecalculator().isbusinessday(_today): + if businessdayselapsed >= 20 and duecalculator().isbusinessday(_today): + commentexists = False + existingcomments = commentservice().getrawrequestcomments(entry['requestid']) + for comment in existingcomments: + if comment['text'] == '20 business days has passed awaiting payment, you can consider closing the request as abandoned': + commentexists = True + if not commentexists: + self.__createcommentforrawrequest(entry['requestid'], eventtype) self.__createnotificationforrawrequest(entry['requestid'], eventtype) - self.__createcommentforrawrequest(entry['requestid'], eventtype) return DefaultMethodResult(True,'Payment reminder notifications created',_today) except BusinessException as exception: current_app.logger.error("%s,%s" % ('Payment reminder Notification Error', exception.message)) From a6a75d7c98d58a4e572b0f6790da1940889a8726 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 15:10:41 -0700 Subject: [PATCH 7/8] Update sql to include all older requests --- request-management-api/request_api/models/FOIRawRequests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-management-api/request_api/models/FOIRawRequests.py b/request-management-api/request_api/models/FOIRawRequests.py index bbe7c1118..91eb206b6 100644 --- a/request-management-api/request_api/models/FOIRawRequests.py +++ b/request-management-api/request_api/models/FOIRawRequests.py @@ -369,7 +369,7 @@ def getonholdapplicationfeerequests(cls): # with the reminder date 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.updated_at::date BETWEEN NOW()::date - INTERVAL '35 DAY' AND NOW()::date + INTERVAL '1 DAY' + AND r.updated_at::date < NOW()::date - INTERVAL '15 DAY' order by r.updated_at asc ''' rs = db.session.execute(text(sql)) From 74b2ee9959276e3eb4f4274b60deb0b22cdb6cc4 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 24 Oct 2023 15:18:58 -0700 Subject: [PATCH 8/8] Remove hardcoded comparison --- request-management-api/request_api/services/events/payment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-management-api/request_api/services/events/payment.py b/request-management-api/request_api/services/events/payment.py index f3a864be1..61393d28d 100644 --- a/request-management-api/request_api/services/events/payment.py +++ b/request-management-api/request_api/services/events/payment.py @@ -53,7 +53,7 @@ def createpaymentreminderevent(self): commentexists = False existingcomments = commentservice().getrawrequestcomments(entry['requestid']) for comment in existingcomments: - if comment['text'] == '20 business days has passed awaiting payment, you can consider closing the request as abandoned': + if comment['text'] == self.__preparecomment(entry['requestid'], eventtype)['comment']: #checks if comment already exists commentexists = True if not commentexists: self.__createcommentforrawrequest(entry['requestid'], eventtype)