From c9af0274f3bd99e413a22ef497291ef3f701a1c7 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 12:23:19 -0800 Subject: [PATCH 1/6] Fix payment_date for Disbursements, EJV, PAD, ONLINE BANKING. Fix disbursement_date. Fix refund_date for EJV, Disbursements. --- jobs/payment-jobs/tasks/distribution_task.py | 2 -- .../reconciliations/cgi_reconciliations.py | 21 +++++++++++-------- .../payment_reconciliations.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/jobs/payment-jobs/tasks/distribution_task.py b/jobs/payment-jobs/tasks/distribution_task.py index e5ee85fa8..416bf2d6a 100644 --- a/jobs/payment-jobs/tasks/distribution_task.py +++ b/jobs/payment-jobs/tasks/distribution_task.py @@ -155,9 +155,7 @@ def update_invoice_to_refunded_or_paid(cls, invoice: InvoiceModel): refund.gl_posted = datetime.now() refund.save() invoice.invoice_status_code = InvoiceStatus.REFUNDED.value - invoice.refund_date = datetime.now() else: invoice.invoice_status_code = InvoiceStatus.PAID.value - invoice.payment_date = datetime.now() invoice.save() current_app.logger.info(f'Updated invoice : {invoice.id}') diff --git a/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py b/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py index 6b0654110..8aaa05eb4 100644 --- a/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py +++ b/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py @@ -201,7 +201,8 @@ async def _process_jv_details_feedback(ejv_file, has_errors, line, receipt_numbe .find_by_id(debit_distribution.disbursement_distribution_code_id) credit_distribution.stop_ejv = True else: - await _update_invoice_disbursement_status(invoice) + effective_date = datetime.strptime(line[22:30], '%Y%m%d') + await _update_invoice_disbursement_status(invoice, effective_date) elif line[104:105] == 'D' and ejv_file.file_type == EjvFileType.PAYMENT.value: # This is for gov account payment JV. @@ -223,9 +224,10 @@ async def _process_jv_details_feedback(ejv_file, has_errors, line, receipt_numbe dist_code.stop_ejv = True elif invoice_link.disbursement_status_code == DisbursementStatus.COMPLETED.value: # Set the invoice status as REFUNDED if it's a JV reversal, else mark as PAID + effective_date = datetime.strptime(line[22:30], '%Y%m%d') is_reversal = invoice.invoice_status_code in ( InvoiceStatus.REFUNDED.value, InvoiceStatus.REFUND_REQUESTED.value) - _set_invoice_jv_reversal(invoice, is_reversal) + _set_invoice_jv_reversal(invoice, effective_date, is_reversal) # Mark the invoice reference as COMPLETED, create a receipt if inv_ref: @@ -242,15 +244,15 @@ async def _process_jv_details_feedback(ejv_file, has_errors, line, receipt_numbe return has_errors -def _set_invoice_jv_reversal(invoice: InvoiceModel, is_reversal: bool): +def _set_invoice_jv_reversal(invoice: InvoiceModel, effective_date: datetime, is_reversal: bool): # Set the invoice status as REFUNDED if it's a JV reversal, else mark as PAID if is_reversal: invoice.invoice_status_code = InvoiceStatus.REFUNDED.value - invoice.refund_date = datetime.now() + invoice.refund_date = effective_date else: invoice.invoice_status_code = InvoiceStatus.PAID.value - invoice.payment_date = datetime.now() - invoice.paid = invoice.total + invoice.payment_date = effective_date + invoice.paid = invoice.total def _fix_invoice_line(line): @@ -262,9 +264,9 @@ def _fix_invoice_line(line): return line -async def _update_invoice_disbursement_status(invoice): +async def _update_invoice_disbursement_status(invoice, effective_date: datetime): """Update status to reversed if its a refund, else to completed.""" - invoice.disbursement_date = datetime.now() + invoice.disbursement_date = effective_date if invoice.invoice_status_code in (InvoiceStatus.REFUNDED.value, InvoiceStatus.REFUND_REQUESTED.value): invoice.disbursement_status_code = DisbursementStatus.REVERSED.value else: @@ -413,7 +415,8 @@ async def _process_ap_header_non_gov_disbursement(line, ejv_file: EjvFileModel) capture_message(f'AP - NON-GOV - Disbursement failed for {invoice_id}, reason : {ap_header_error_message}', level='error') else: - await _update_invoice_disbursement_status(invoice) + # TODO - Fix this on BC Assessment launch, so the effective date reads from the feedback. + await _update_invoice_disbursement_status(invoice, effective_date=datetime.now()) if invoice.invoice_status_code != InvoiceStatus.PAID.value: refund = RefundModel.find_by_invoice_id(invoice.id) refund.gl_posted = datetime.now() diff --git a/queue_services/payment-reconciliations/src/reconciliations/payment_reconciliations.py b/queue_services/payment-reconciliations/src/reconciliations/payment_reconciliations.py index 6d623abff..f067dfd6f 100644 --- a/queue_services/payment-reconciliations/src/reconciliations/payment_reconciliations.py +++ b/queue_services/payment-reconciliations/src/reconciliations/payment_reconciliations.py @@ -394,7 +394,7 @@ async def _process_paid_invoices(inv_references, row): logger.debug('PAID Invoice. Invoice Reference ID : %s, invoice ID : %s', inv_ref.id, inv_ref.invoice_id) inv.invoice_status_code = InvoiceStatus.PAID.value - inv.payment_date = datetime.now() + inv.payment_date = receipt_date inv.paid = inv.total # Create Receipt records receipt: ReceiptModel = ReceiptModel() From 0742ec6fc072fa9078347c714284d283de14d039 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 12:29:56 -0800 Subject: [PATCH 2/6] Fix lint --- .../src/reconciliations/cgi_reconciliations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py b/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py index 8aaa05eb4..6cfee2d49 100644 --- a/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py +++ b/queue_services/payment-reconciliations/src/reconciliations/cgi_reconciliations.py @@ -252,7 +252,7 @@ def _set_invoice_jv_reversal(invoice: InvoiceModel, effective_date: datetime, is else: invoice.invoice_status_code = InvoiceStatus.PAID.value invoice.payment_date = effective_date - invoice.paid = invoice.total + invoice.paid = invoice.total def _fix_invoice_line(line): From 63b9b88150ed74d09aa57047c765bf0398b514b1 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 12:59:08 -0800 Subject: [PATCH 3/6] Fix unit tests --- .../integration/test_cgi_reconciliations.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py index f2d3bf085..ad4e296d3 100644 --- a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py +++ b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py @@ -137,13 +137,13 @@ async def test_successful_partner_ejv_reconciliations(session, app, stan_server, f'............................................................................................' \ f'.........0000...............................................................................' \ f'.......................................................................CGI\n' \ - f'..JD...FI0000000{ejv_header_id}00001........................................................' \ + f'..JD...FI0000000{ejv_header_id}0000120230529................................................' \ f'...........000000000090.00D.................................................................' \ f'...................................{invoice_id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header_id}00002........................................................' \ + f'..JD...FI0000000{ejv_header_id}0000220230529................................................' \ f'...........000000000090.00C.................................................................' \ f'...................................{invoice_id} ' \ f' 0000........................' \ @@ -397,13 +397,13 @@ async def test_successful_partner_reversal_ejv_reconciliations(session, app, sta f'............................................................................................' \ f'.........0000...............................................................................' \ f'.......................................................................CGI\n' \ - f'..JD...FI0000000{ejv_header_id}00001........................................................' \ + f'..JD...FI0000000{ejv_header_id}0000120230529................................................' \ f'...........000000000090.00C.................................................................' \ f'...................................{invoice_id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header_id}00002........................................................' \ + f'..JD...FI0000000{ejv_header_id}0000220230529................................................' \ f'...........000000000090.00D.................................................................' \ f'...................................{invoice_id} ' \ f' 0000........................' \ @@ -431,6 +431,7 @@ async def test_successful_partner_reversal_ejv_reconciliations(session, app, sta assert ejv_file.disbursement_status_code == DisbursementStatus.COMPLETED.value invoice = InvoiceModel.find_by_id(invoice_id) assert invoice.disbursement_status_code == DisbursementStatus.REVERSED.value + assert invoice.disbursement_date == datetime(2023,5,29) @pytest.mark.asyncio @@ -525,25 +526,25 @@ async def test_succesful_payment_ejv_reconciliations(session, app, stan_server, f'............................................................................................' \ f'.........0000...............................................................................' \ f'.......................................................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00001........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000120230529................................................' \ f'...........{pay_line_amount}D.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00002........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000220230529................................................' \ f'...........{pay_line_amount}C.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00003...........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000320230529...................................................' \ f'........{service_fee_amount}D.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00004........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000420230529................................................' \ f'...........{service_fee_amount}C..............................................................' \ f'......................................{inv.id} ' \ f' 0000........................' \ @@ -588,6 +589,7 @@ async def test_succesful_payment_ejv_reconciliations(session, app, stan_server, invoice: InvoiceModel = InvoiceModel.find_by_id(inv_id) assert invoice.disbursement_status_code is None assert invoice.invoice_status_code == InvoiceStatus.PAID.value + assert invoice.payment_date == datetime(2023,5,29) invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_by_invoice_id_and_status( inv_id, InvoiceReferenceStatus.COMPLETED.value ) @@ -694,25 +696,25 @@ async def test_succesful_payment_reversal_ejv_reconciliations(session, app, stan f'............................................................................................' \ f'.........0000...............................................................................' \ f'.......................................................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00001........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000120230529................................................' \ f'...........{pay_line_amount}C.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00002........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000220230529................................................' \ f'...........{pay_line_amount}D.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00003...........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000320230529...................................................' \ f'........{service_fee_amount}C.................................................................' \ f'...................................{inv.id} ' \ f' 0000........................' \ f'............................................................................................' \ f'..................................CGI\n' \ - f'..JD...FI0000000{ejv_header.id}00004........................................................' \ + f'..JD...FI0000000{ejv_header.id}0000420230529................................................' \ f'...........{service_fee_amount}D..............................................................' \ f'......................................{inv.id} ' \ f' 0000........................' \ @@ -757,6 +759,7 @@ async def test_succesful_payment_reversal_ejv_reconciliations(session, app, stan invoice: InvoiceModel = InvoiceModel.find_by_id(inv_id) assert invoice.disbursement_status_code is None assert invoice.invoice_status_code == InvoiceStatus.REFUNDED.value + assert invoice.refund_date == datetime(2023,5,29) invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_by_invoice_id_and_status( inv_id, InvoiceReferenceStatus.COMPLETED.value ) From 6851472ae95ad48523915b3ba585a73895553cab Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 13:07:57 -0800 Subject: [PATCH 4/6] lint fix --- .../tests/integration/test_cgi_reconciliations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py index ad4e296d3..e84913ec7 100644 --- a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py +++ b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py @@ -431,7 +431,7 @@ async def test_successful_partner_reversal_ejv_reconciliations(session, app, sta assert ejv_file.disbursement_status_code == DisbursementStatus.COMPLETED.value invoice = InvoiceModel.find_by_id(invoice_id) assert invoice.disbursement_status_code == DisbursementStatus.REVERSED.value - assert invoice.disbursement_date == datetime(2023,5,29) + assert invoice.disbursement_date == datetime(2023, 5, 29) @pytest.mark.asyncio @@ -589,7 +589,7 @@ async def test_succesful_payment_ejv_reconciliations(session, app, stan_server, invoice: InvoiceModel = InvoiceModel.find_by_id(inv_id) assert invoice.disbursement_status_code is None assert invoice.invoice_status_code == InvoiceStatus.PAID.value - assert invoice.payment_date == datetime(2023,5,29) + assert invoice.payment_date == datetime(2023, 5, 29) invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_by_invoice_id_and_status( inv_id, InvoiceReferenceStatus.COMPLETED.value ) @@ -759,7 +759,7 @@ async def test_succesful_payment_reversal_ejv_reconciliations(session, app, stan invoice: InvoiceModel = InvoiceModel.find_by_id(inv_id) assert invoice.disbursement_status_code is None assert invoice.invoice_status_code == InvoiceStatus.REFUNDED.value - assert invoice.refund_date == datetime(2023,5,29) + assert invoice.refund_date == datetime(2023, 5, 29) invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_by_invoice_id_and_status( inv_id, InvoiceReferenceStatus.COMPLETED.value ) From fdab903332aed0834f42791a8e454e17193c499e Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 13:10:28 -0800 Subject: [PATCH 5/6] white space --- .../tests/integration/test_cgi_reconciliations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py index e84913ec7..b26621fe0 100644 --- a/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py +++ b/queue_services/payment-reconciliations/tests/integration/test_cgi_reconciliations.py @@ -759,7 +759,7 @@ async def test_succesful_payment_reversal_ejv_reconciliations(session, app, stan invoice: InvoiceModel = InvoiceModel.find_by_id(inv_id) assert invoice.disbursement_status_code is None assert invoice.invoice_status_code == InvoiceStatus.REFUNDED.value - assert invoice.refund_date == datetime(2023, 5, 29) + assert invoice.refund_date == datetime(2023, 5, 29) invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_by_invoice_id_and_status( inv_id, InvoiceReferenceStatus.COMPLETED.value ) From 2e1d1dd7b814f8a6a1050abc010f09b49a8a82fe Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 7 Dec 2023 13:19:59 -0800 Subject: [PATCH 6/6] fix unit test --- jobs/payment-jobs/tests/jobs/test_distribution_task.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/jobs/payment-jobs/tests/jobs/test_distribution_task.py b/jobs/payment-jobs/tests/jobs/test_distribution_task.py index 3b2e29d1b..daffbd10e 100644 --- a/jobs/payment-jobs/tests/jobs/test_distribution_task.py +++ b/jobs/payment-jobs/tests/jobs/test_distribution_task.py @@ -64,7 +64,6 @@ def test_update_failed_distributions_refunds(session, monkeypatch): DistributionTask.update_failed_distributions() assert invoice.invoice_status_code == InvoiceStatus.REFUNDED.value - assert invoice.refund_date is not None def test_update_failed_distribution_payments(session, monkeypatch): @@ -112,7 +111,6 @@ def test_non_direct_pay_invoices(session, monkeypatch): factory_refund_invoice(invoice.id) DistributionTask.update_failed_distributions() assert invoice.invoice_status_code == InvoiceStatus.REFUNDED.value - assert invoice.refund_date is not None def test_no_response_pay_bc(session, monkeypatch):