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

Changes for populating receipt_number to payments table for all payment types #740

Merged
merged 2 commits into from
Aug 6, 2021
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
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
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def search_account_payments(auth_account_id: str, status: str, page: int, limit:
# Result is tuple of payment and invoice records.
# Iterate the results and group all invoices for the same payment by keeping the last payment object to compare.
last_payment_iter = None
payment_dict = None
payment_dict = dict()

for result in results:
payment = result[0]
Expand Down
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
4 changes: 3 additions & 1 deletion 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 Down Expand Up @@ -616,6 +617,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