Created
March 18, 2017 20:37
-
-
Save jeremylowery/3e78804d0a271eba73781754206089f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def create_invoice(db, customer_id, line_items): | |
customer = customer_by_id(db, customer_id) | |
invoice_id = new_invoice_id(db) | |
insert_record(db, 'invoice', id=invoice_id, customer_id=customer_id) | |
for item in line_items: | |
insert_record(db, 'line_item', invoice_id=invoice_id, | |
amount=item.amount, product=item.product_id) | |
return invoice_id | |
def customer_by_id(db, customer_id) | |
cursor = db.cursor() | |
cursor.execute("select * from customer where id=%s", (customer_id,)) | |
return next(cursor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment