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

18924 - Fix payment_date for Disbursements, EJV, PAD, ONLINE BANKING. Fix di… #1344

Merged
merged 6 commits into from
Dec 7, 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
2 changes: 0 additions & 2 deletions jobs/payment-jobs/tasks/distribution_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator Author

@seeker25 seeker25 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want to lose this data, as we're just shifting over GL's here.

else:
invoice.invoice_status_code = InvoiceStatus.PAID.value
invoice.payment_date = datetime.now()
invoice.save()
current_app.logger.info(f'Updated invoice : {invoice.id}')
2 changes: 0 additions & 2 deletions jobs/payment-jobs/tests/jobs/test_distribution_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -242,14 +244,14 @@ 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.payment_date = effective_date
invoice.paid = invoice.total


Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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........................' \
Expand Down Expand Up @@ -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........................' \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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........................' \
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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........................' \
Expand Down Expand Up @@ -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
)
Expand Down
Loading