-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes for populating receipt_number to payments table for all payme…
…nt methods.
- Loading branch information
1 parent
c18e120
commit 64ed977
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
pay-api/migrations/versions/03b2c7caed21_populate_receipt_number_payments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters