Skip to content

Commit

Permalink
Changes for populating receipt_number to payments table for all payme…
Browse files Browse the repository at this point in the history
…nt methods.
  • Loading branch information
sumesh-aot committed Aug 4, 2021
1 parent c18e120 commit 64ed977
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""populate_receipt_number_payments
Revision ID: 03b2c7caed21
Revises: c871202927f0
Create Date: 2021-07-28 10:10:39.460915
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = '03b2c7caed21'
down_revision = 'c871202927f0'
branch_labels = None
depends_on = None


def upgrade():
conn = op.get_bind()
res = conn.execute(f"select id, invoice_number from payments where receipt_number is null;")
results = res.fetchall()
for result in results:
pay_id = result[0]
invoice_number = result[1]
res = conn.execute(f"select r.receipt_number from receipts r left join invoice_references ir "
f"on ir.invoice_id=r.invoice_id where ir.status_code='COMPLETED' "
f"and invoice_number='{invoice_number}'")
receipt_number_result = res.fetchall()
if receipt_number_result:
receipt_number = receipt_number_result[0][0]
op.execute(f"update payments set receipt_number={receipt_number} where id = {pay_id}")


def downgrade():
pass
1 change: 1 addition & 0 deletions pay-api/src/pay_api/services/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ def _update_receipt_details(invoices, payment, receipt_details, transaction_dao)
capture_message(f'ALERT : Paid Amount is less than owed amount. Paid : {payment.paid_amount}, '
f'Owed: {payment.invoice_amount}', level='error')
else:
payment.receipt_number = receipt_details[0]
payment.payment_status_code = PaymentStatus.COMPLETED.value

for invoice in invoices:
Expand Down
8 changes: 6 additions & 2 deletions pay-api/tests/unit/services/test_payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_transaction_update(session, stan_server, public_user_mock):
line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
line.save()

factory_payment(invoice_number=invoice_reference.invoice_number).save()
payment: Payment = factory_payment(invoice_number=invoice_reference.invoice_number).save()

transaction = PaymentTransactionService.create_transaction_for_invoice(invoice.id, get_paybc_transaction_request())
transaction = PaymentTransactionService.update_transaction(transaction.id,
Expand All @@ -166,6 +166,7 @@ def test_transaction_update(session, stan_server, public_user_mock):
assert transaction.transaction_start_time is not None
assert transaction.transaction_end_time is not None
assert transaction.status_code == TransactionStatus.COMPLETED.value
assert payment.receipt_number


@skip_in_pod
Expand All @@ -180,7 +181,7 @@ def test_transaction_update_with_no_receipt(session, stan_server):
line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
line.save()

factory_payment(invoice_number=invoice_reference.invoice_number).save()
payment: Payment = factory_payment(invoice_number=invoice_reference.invoice_number).save()

transaction = PaymentTransactionService.create_transaction_for_invoice(invoice.id, get_paybc_transaction_request())
transaction = PaymentTransactionService.update_transaction(transaction.id, pay_response_url=None)
Expand All @@ -195,6 +196,7 @@ def test_transaction_update_with_no_receipt(session, stan_server):
assert transaction.transaction_end_time is not None
assert transaction.status_code == TransactionStatus.FAILED.value
assert transaction.asdict() is not None
assert payment.receipt_number


@skip_in_pod
Expand Down Expand Up @@ -507,6 +509,7 @@ def get_receipt(cls, payment_account, pay_response_url: str,
assert transaction.transaction_start_time is not None
assert transaction.transaction_end_time is not None
assert transaction.status_code == TransactionStatus.COMPLETED.value
# assert payment.receipt_number


def test_create_transaction_for_nsf_payment(session):
Expand Down Expand Up @@ -616,6 +619,7 @@ def get_receipt(cls, payment_account, pay_response_url: str,
assert txn.status_code == 'COMPLETED'
payment_2 = Payment.find_by_id(payment_2.id)
assert payment_2.payment_status_code == 'COMPLETED'

invoice_1: Invoice = Invoice.find_by_id(invoice_1.id)
assert invoice_1.invoice_status_code == 'PAID'
cfs_account = CfsAccount.find_effective_by_account_id(payment_account.id)
Expand Down

0 comments on commit 64ed977

Please sign in to comment.