summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-07-08 19:14:20 +0200
committerSebastian Reichel <sre@ring0.de>2012-07-08 19:14:20 +0200
commit1dec4fa9f08a7e3142db94bffadc3bc7c66fa9ed (patch)
treedb74c307e52390b560a2d70bd11d4dffd69929d6
parent5884cc13263221bd8f296f5f424237c7734b7e6a (diff)
downloadserial-barcode-scanner-1dec4fa9f08a7e3142db94bffadc3bc7c66fa9ed.tar.bz2
Send one mail to the financal master
-rwxr-xr-xinvoice/generate-invoice.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/invoice/generate-invoice.py b/invoice/generate-invoice.py
index d541271..30a0139 100755
--- a/invoice/generate-invoice.py
+++ b/invoice/generate-invoice.py
@@ -208,7 +208,12 @@ def generate_mail(receiver, subject, message, pdfdata, timestamp=time.time(), cc
msg.attach(MIMEText(message, 'plain', 'utf-8'))
- if pdfdata is not None:
+ if isinstance(pdfdata, dict):
+ for name, data in pdfdata.items():
+ pdf = MIMEApplication(data, 'pdf')
+ pdf.add_header('Content-Disposition', 'attachment', filename = name)
+ msg.attach(pdf)
+ elif pdfdata is not None:
pdf = MIMEApplication(pdfdata, 'pdf')
pdf.add_header('Content-Disposition', 'attachment', filename = 'rechnung.pdf')
msg.attach(pdf)
@@ -284,6 +289,8 @@ def monthly(timestamp = time.time()):
title = "Getränkerechnung %04d/%02d" % (dstart.year, dstart.month)
number = 0
+ invoices = {}
+
for user in get_users_with_purchases(start, stop):
number += 1
subject = "Rechnung Nr.%04d%02d5%03d" % (dstart.year, dstart.month, number)
@@ -293,11 +300,17 @@ def monthly(timestamp = time.time()):
tex = generate_invoice_tex(user, title, subject, start, stop, False)
msg = generate_invoice_text(user, title, subject, start, stop, False)
pdf = generate_pdf(tex)
- mail = generate_mail(receiver, title, msg, pdf, timestamp, cc = "schatzmeister@kreativitaet-trifft-technik.de")
- send_mail(mail, [userinfo["email"], "schatzmeister@kreativitaet-trifft-technik.de"])
+ invoices["%04d%02d5%03d_%s_%s.pdf" % (dstart.year, dstart.month, number, userinfo["firstname"], userinfo["lastname"])] = pdf
+ mail = generate_mail(receiver, title, msg, pdf, timestamp)
+ send_mail(mail, userinfo["email"])
print("Sent invoice to", userinfo["firstname"], userinfo["lastname"])
else:
print("Can't send invoice for missing user with the following id:", user)
+
+ mail = generate_mail("Schatzmeister <schatzmeister@kreativiteat-trifft-technik.de>",
+ "Rechnungen %04d%02d" % (dstart.year, dstart.month),
+ None, invoices, timestamp)
+ send_mail(mail, "schatzmeister@kreativiteat-trifft-technik.de")
def backup():
timestamp = time.time()