summaryrefslogtreecommitdiffstats
path: root/invoice
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-05-27 23:42:00 +0200
committerSebastian Reichel <sre@ring0.de>2012-05-27 23:42:00 +0200
commit29dce6f165c45ab209912e7ca0d240ae590fc3c4 (patch)
tree96d61bc46391df7e2cef3c63178a29611aa2aabf /invoice
parent8e221e224b15f7c77eb4c3bccc6325dea61a14d7 (diff)
downloadserial-barcode-scanner-29dce6f165c45ab209912e7ca0d240ae590fc3c4.tar.bz2
add method to send info about current stock
Diffstat (limited to 'invoice')
-rwxr-xr-xinvoice/generate-invoice.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/invoice/generate-invoice.py b/invoice/generate-invoice.py
index 3ac65b2..0af75c4 100755
--- a/invoice/generate-invoice.py
+++ b/invoice/generate-invoice.py
@@ -203,7 +203,51 @@ def monthly(timestamp = time.time()):
def backup(timestamp = time.time()):
print("backup()")
-def stock(timestamp = time.time()):
- print("stock()")
+def get_stock_data():
+ connection = sqlite3.connect('shop.db')
+ c = connection.cursor()
+ result = []
+
+ c.execute("SELECT name,amount FROM products")
+
+ for row in c:
+ result.append((row[0],row[1]))
+
+ c.close()
+
+ return result
+
+def gen_stock_asciitable():
+ stock = get_stock_data()
+ longest_name = 0
+ longest_amount = 0
+ asciitable = ""
+ for element in stock:
+ if len(element[0]) > longest_name:
+ longest_name = len(element[0])
+ if len(str(element[1])) > longest_amount:
+ longest_amount = len(str(element[1]))
+
+ asciitable = "+-" + longest_name * "-" + "-+-" + longest_amount * "-" + "-+\n"
+ asciitable += "| " + "Produkt" + (longest_name - len("Produkt")) * " " + " | " + (longest_amount - 1) * " " + "#" + " |\n"
+ asciitable += "+-" + longest_name * "-" + "-+-" + longest_amount * "-" + "-+\n"
+ for product in stock:
+ asciitable += "| " + product[0] + (longest_name - len(product[0])) * " " + " | " + (longest_amount - len(str(product[1]))) * " " + str(product[1]) + " |\n"
+ asciitable += "+-" + longest_name * "-" + "-+-" + longest_amount * "-" + "-+\n"
+
+ return asciitable
+
+def gen_stock_mail():
+ msg = MIMEMultipart()
+ msg["From"] = "KtT Shop System <shop@kreativitaet-trifft-technik.de>"
+ msg["To"] = "KtT Einkaufsteam <einkauf@kreativitaet-trifft-technik.de>"
+ msg["Subject"] = Header("Aktueller Warenbestand", 'utf-8')
+ msg.preamble = "Please use a MIME aware email client!"
+ msg.attach(MIMEText(gen_stock_asciitable(), 'plain', 'utf-8'))
+ return msg
+
+def stock():
+ send_mail(gen_stock_mail(), "einkauf@kreativitaet-trifft-technik.de")
+#stock()
daily()