diff --git a/request-management-api/request_api/resources/applicantcorrespondence.py b/request-management-api/request_api/resources/applicantcorrespondence.py index 63a5c11dd..3ae650e35 100644 --- a/request-management-api/request_api/resources/applicantcorrespondence.py +++ b/request-management-api/request_api/resources/applicantcorrespondence.py @@ -82,20 +82,6 @@ def get(requestid, ministryrequestid): except BusinessException: return "Error happened while fetching applicant correspondence logs" , 500 - # @staticmethod - # @TRACER.trace() - # @cross_origin(origins=allowedorigins()) - # @auth.require - # @auth.hasusertype('iao') - # def post(requestid, ministryrequestid): - # try: - # requestjson = request.get_json() - # applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson) - # rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid) - # result = communicationwrapperservice().send_email(rawrequestid, ministryrequestid, applicantcorrespondencelog) - # return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - # except BusinessException: - # return "Error happened while saving applicant correspondence log" , 500 @staticmethod @TRACER.trace() @cross_origin(origins=allowedorigins()) @@ -105,23 +91,12 @@ def post(requestid, ministryrequestid): try: requestjson = request.get_json() applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson) - result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid()) - if cfrfeeservice().getactivepayment(requestid, ministryrequestid) != None: - requestservice().postfeeeventtoworkflow(requestid, ministryrequestid, "CANCELLED") - if result.success == True: - _attributes = applicantcorrespondencelog["attributes"][0] if "attributes" in applicantcorrespondencelog else None - _paymentexpirydate = _attributes["paymentExpiryDate"] if _attributes is not None and "paymentExpiryDate" in _attributes else None - if _paymentexpirydate not in (None, ""): - paymentservice().createpayment(requestid, ministryrequestid, _attributes, AuthHelper.getuserid()) - requestservice().postcorrespondenceeventtoworkflow(requestid, ministryrequestid, result.identifier, applicantcorrespondencelog['attributes'], applicantcorrespondencelog['templateid']) - - return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 + rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid) + result = communicationwrapperservice().send_email(rawrequestid, ministryrequestid, applicantcorrespondencelog) + return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except BusinessException: return "Error happened while saving applicant correspondence log" , 500 - - - - + @cors_preflight('POST,OPTIONS') @API.route('/foiflow/applicantcorrespondence/draft//') class FOIFlowApplicantCorrespondenceDraft(Resource): diff --git a/request-management-api/request_api/resources/fee.py b/request-management-api/request_api/resources/fee.py index c92913e2c..b3b8216ef 100644 --- a/request-management-api/request_api/resources/fee.py +++ b/request-management-api/request_api/resources/fee.py @@ -60,8 +60,6 @@ class Payment(Resource): def post(request_id: int): try: request_json = request.get_json() - print("request_id", request_id) - print("request_json", request_json) fee_service: FeeService = FeeService(request_id=request_id, code=request_json['fee_code']) pay_response = fee_service.init_payment(request_json) return pay_response, 201 diff --git a/request-management-api/request_api/services/communicationwrapperservice.py b/request-management-api/request_api/services/communicationwrapperservice.py index 32ab5348f..b4a4e9331 100644 --- a/request-management-api/request_api/services/communicationwrapperservice.py +++ b/request-management-api/request_api/services/communicationwrapperservice.py @@ -26,8 +26,11 @@ def send_email(self,requestid, ministryrequestid, applicantcorrespondencelog): result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid()) if result.success == True: # raw requests should never be fee emails so they would only get handled by else statement + isFee = self.__is_fee_processing(applicantcorrespondencelog["templateid"]) + print("isFee", isFee) if self.__is_fee_processing(applicantcorrespondencelog["templateid"]) == True: - return self.__handle_fee_email(requestid, ministryrequestid, applicantcorrespondencelog) + print("isFee2", isFee) + return self.__handle_fee_email(requestid, ministryrequestid, applicantcorrespondencelog, result) else: if "emails" in applicantcorrespondencelog and len(applicantcorrespondencelog["emails"]) > 0: template = applicantcorrespondenceservice().gettemplatebyid(applicantcorrespondencelog["templateid"]) @@ -35,17 +38,32 @@ def send_email(self,requestid, ministryrequestid, applicantcorrespondencelog): return result - def __handle_fee_email(self,requestid, ministryrequestid, applicantcorrespondencelog): + def __handle_fee_email(self,requestid, ministryrequestid, applicantcorrespondencelog, result): if cfrfeeservice().getactivepayment(requestid, ministryrequestid) != None: requestservice().postfeeeventtoworkflow(requestid, ministryrequestid, "CANCELLED") _attributes = applicantcorrespondencelog["attributes"][0] if "attributes" in applicantcorrespondencelog else None _paymentexpirydate = _attributes["paymentExpiryDate"] if _attributes is not None and "paymentExpiryDate" in _attributes else None if _paymentexpirydate not in (None, ""): paymentservice().createpayment(requestid, ministryrequestid, _attributes, AuthHelper.getuserid()) + print("isFee3") return requestservice().postcorrespondenceeventtoworkflow(requestid, ministryrequestid, result.identifier, applicantcorrespondencelog['attributes'], applicantcorrespondencelog['templateid']) + # def __is_fee_processing(self, templateid): + # template = applicantcorrespondenceservice().gettemplatebyid(templateid) + # print("template10", template) + # return template and template.name in ['PAYONLINE', 'PAYOUTSTANDING'] + + # def __is_fee_processing(self, templateid): + # template = applicantcorrespondenceservice().getactivetemplatebyid(templateid) + # template2 = applicantcorrespondenceservice().gettemplatebyid(templateid).name + # print("template10", template) + # print("template12", template2) + # if template and hasattr(template, 'name') and template.name.upper() in ['PAYONLINE', 'PAYOUTSTANDING']: + # return True + # return False + def __is_fee_processing(self, templateid): - if applicantcorrespondenceservice().gettemplatebyid(templateid) in ['PAYONLINE','PAYOUTSTANDING']: + if applicantcorrespondenceservice().gettemplatebyid(templateid).name in ['PAYONLINE','PAYOUTSTANDING']: return True return False diff --git a/request-management-api/request_api/services/external/bpmservice.py b/request-management-api/request_api/services/external/bpmservice.py index 09534a129..1ef074eb0 100644 --- a/request-management-api/request_api/services/external/bpmservice.py +++ b/request-management-api/request_api/services/external/bpmservice.py @@ -169,7 +169,7 @@ def _getserviceaccounttoken_(self): def _getHeaders_(self, token): """Generate headers.""" if token is None: - token = self._getserviceaccounttoken_() + token = self._getserviceaccounttoken_(); return { "Authorization": "Bearer " + token, "Content-Type": "application/json", diff --git a/request-management-api/request_api/services/unopenedreportservice.py b/request-management-api/request_api/services/unopenedreportservice.py index 61fa1054a..67c18642b 100644 --- a/request-management-api/request_api/services/unopenedreportservice.py +++ b/request-management-api/request_api/services/unopenedreportservice.py @@ -68,11 +68,12 @@ async def generateunopenedreport(self): alerts.append({"request": request, "rank": 2, "potentialmatches": alert.potentialmatches}) UnopenedReport.bulkinsert(alertdbrows) alerts.sort(key=lambda a : a.get('potentialmatches', {'highscore': -1})['highscore']) + requestjson={"email": self.reportemail, "topic": "Unopened Report"} senderservice().send( subject="Intake Unopened Request Report: " + str(date.today()), content=self.generateemailhtml(alerts), _messageattachmentlist=[], - requestjson={"email": self.reportemail, "topic": "Unopened Report"} + emails=requestjson.get("email") ) return alerts