Add an email invoice tool
This commit is contained in:
parent
242f844055
commit
f36d7d7b76
1 changed files with 35 additions and 0 deletions
35
tools/emailinvoice.py
Normal file
35
tools/emailinvoice.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
from app import stripe
|
||||||
|
from app import app
|
||||||
|
|
||||||
|
from util.invoice import renderInvoiceToHtml
|
||||||
|
from util.email import send_invoice_email
|
||||||
|
|
||||||
|
from data import model
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
from flask import Flask, current_app
|
||||||
|
from flask_mail import Mail
|
||||||
|
|
||||||
|
def sendInvoice(invoice_id):
|
||||||
|
invoice = stripe.Invoice.retrieve(invoice_id)
|
||||||
|
if not invoice['customer']:
|
||||||
|
print 'No customer found'
|
||||||
|
return
|
||||||
|
|
||||||
|
customer_id = invoice['customer']
|
||||||
|
user = model.get_user_or_org_by_customer_id(customer_id)
|
||||||
|
if not user:
|
||||||
|
print 'No user found for customer %s' % (customer_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
invoice_html = renderInvoiceToHtml(invoice, user)
|
||||||
|
send_invoice_email(user.email, invoice_html)
|
||||||
|
print 'Invoice sent to %s' % (user.email)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Email an invoice')
|
||||||
|
parser.add_argument('invoice_id', help='The invoice ID')
|
||||||
|
args = parser.parse_args()
|
||||||
|
sendInvoice(args.invoice_id)
|
Reference in a new issue