Skip to content

Instantly share code, notes, and snippets.

@jeremylowery
Created March 18, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremylowery/3e78804d0a271eba73781754206089f7 to your computer and use it in GitHub Desktop.
Save jeremylowery/3e78804d0a271eba73781754206089f7 to your computer and use it in GitHub Desktop.
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