Advertisement
andriitereshchenko

Failed Transactions

Mar 4th, 2025
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | Software | 0 0
  1. def print_failed_transactions():
  2.     from datetime import date
  3.  
  4.     print('#, Failed Transaction ID, New Transaction ID, New Transaction Status, Identity ID, Employee, Email, Amount, Needs Recreation')
  5.     start_date = date(2025,2,28)
  6.     failed_transactions = AptPayTransaction.objects.filter(
  7.         transaction_type='Apt Send',
  8.         movement_type='Employee payout',
  9.         created__date__gte=start_date,
  10.         internal_status='Failed'
  11.     ).order_by('created')
  12.     for i, transaction in enumerate(failed_transactions, 1):
  13.         created = transaction.created
  14.         identity_id = transaction.identity_id
  15.         amount = transaction.amount
  16.  
  17.         needs_recreation = True
  18.         new_transaction_id = '-'
  19.         new_status = '-'
  20.         new_transaction = AptPayTransaction.objects.filter(
  21.             identity_id=identity_id,
  22.             amount=amount,
  23.             transaction_type='Apt Send',
  24.             movement_type='Employee payout',
  25.             created__gt=created,
  26.         ).first()
  27.         if new_transaction:
  28.             new_transaction_id = new_transaction.apt_pay_id
  29.             new_status = new_transaction.status
  30.             if new_transaction.internal_status != 'Failed':
  31.                 needs_recreation = False
  32.  
  33.         employee = transaction.employee_name
  34.         user_profile = ADTUserProfile.objects.filter(identity_id=identity_id).first()
  35.         if not user_profile:
  36.             user_profile = ADTUserProfile.objects.filter(
  37.                 previous_identity_ids__contains=[identity_id]
  38.             ).first()
  39.  
  40.         email = '-'
  41.         if user_profile:
  42.             email = user_profile.user.email
  43.         print(f'{i}, {transaction.apt_pay_id}, {new_transaction_id}, {new_status}, {identity_id}, {employee}, {email},'
  44.               f' {amount}, {needs_recreation}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement