Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def compare_charge_items_and_receipt_items(filepath):
- import getaround
- from getaround.core import models
- import pg8000
- """For each Rental the Receipt price, the Receipt Item prices, and the Charge Item amounts should all be equal"""
- conn = pg8000.connect(database="getaround", host="104.155.175.194",
- password="g3t@r0und!", port=5432,
- user="getaround", ssl=True)
- curs = conn.cursor()
- sql = """
- SELECT rental.id AS rental_id,
- rental.receipt_price_rental AS rental_price,
- sum(receipt_item.price - coalesce(receipt_item.discount_amount, 0)
- - coalesce(passthrough_fee_item.price, 0)) as sum_receipt_items,
- sum(coalesce(charge_item.amount,0)) as sum_charge_items,
- sum(receipt_item.price - coalesce(receipt_item.discount_amount, 0)
- - coalesce(passthrough_fee_item.price, 0))
- - sum(coalesce(charge_item.amount,0)) as diff
- -- these columns should be updated if we fix the issue in #5487
- FROM public.rental rental
- JOIN public.receipt_item receipt_item ON receipt_item.rental_id = rental.id
- LEFT JOIN public.receipt_item passthrough_fee_item ON receipt_item.passthrough_fee_id = passthrough_fee_item.id
- LEFT JOIN stripe.charge_item charge_item ON receipt_item.charge_item_id = charge_item.id
- LEFT JOIN stripe.charge_item fee_charge_item ON passthrough_fee_item.charge_item_id = fee_charge_item.id
- WHERE rental.created > '2015/06/01'
- AND rental.created < current_timestamp - INTERVAL '1 DAYS'
- AND rental.status = 'ACTIVE'
- AND receipt_item.canceled = FALSE
- GROUP BY rental.id
- ORDER BY diff DESC;
- """
- curs.execute(sql)
- results = curs.fetchall()
- out = open(filepath, "a+")
- for rental_id, rental_price, sum_receipt_items, sum_charge_items, diff in results:
- if diff > 0:
- rental = models.Rental.get_by(id=long(rental_id))
- request = rental.request
- auths = models.Authorization.get(request.authorization_keys)
- for auth in auths:
- if 'in_' in auth.external_id:
- invoice = stripe_facade.retrieve_invoice(auth.external_id)
- for stmt in _convert_invoice(invoice):
- out.write(stmt.encode("utf-8")+"\n")
- print stmt
- elif 'ch_' in auth.external_id:
- charge = stripe_facade.retrieve_charge(auth.external_id)
- for stmt in _convert_charge(charge):
- out.write(stmt.encode("utf-8")+"\n")
- print stmt
- elif 'ii_' in auth.external_id:
- invoice_item = stripe_facade.retrieve_invoice_item(auth.external_id)
- for stmt in _convert_invoice_item(invoice_item):
- out.write(stmt.encode("utf-8")+"\n")
- print stmt
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement