moved invoice mailing code out of gacksinvoice.py
smbaker [Thu, 18 Oct 2012 01:08:32 +0000 (18:08 -0700)]
apps/gacks/gacksinvoice.py

index ee5c135..446f5cc 100644 (file)
@@ -10,8 +10,6 @@ from gacksdb import GacksDB
 from gacksexcep import *
 from gackshandle import *
 from gackstime import GacksTime
-from email.mime.text import MIMEText
-from subprocess import Popen, PIPE
 import MySQLdb
 import MySQLdb.cursors
 
@@ -624,67 +622,5 @@ class GacksInvoiceManager(GacksDB):
             inv.set_state(STATE_APPLY, filterStates=[STATE_PENDING])
             inv.apply_to_balance(description = "Daily Invoice: Other", tNow=max_date)
 
-    def generate_invoice_email(self, account_name, end_date=None, days=7):
-        if end_date==None:
-            now = datetime.datetime.now()
-            if now.weekday()!=6:
-                # if it's not sunday, then find the last sunday
-                last_sunday = now - datetime.timedelta(days=now.weekday()+1)
-            else:
-                last_sunday = now
-            end_date = time.mktime(last_sunday.timetuple())
-
-        # round it to the nearest day
-        end_date = time.mktime(datetime.datetime.fromtimestamp(end_date).date().timetuple())
-
-        # include all time until the last minute of that day
-        end_date = end_date + 24*60*60 - 1
-
-        # add one second, since start date is a >= relation
-        start_date = end_date - days * 24*60*60 + 1
-
-        start_date_str = str(datetime.date.fromtimestamp(start_date))
-        end_date_str = str(datetime.date.fromtimestamp(end_date))
-
-        filter = {"account": account_name, "start_date": start_date, "end_date": end_date, "state": STATE_INVOICED}
-        invoice = self.get_invoice_prime(filter)
-        summary = invoice.get_summary()
-        #summary = self.get_invoice_summary(filter)
-
-        #gacks_secret=open("/root/gacks_account_secret.txt", "r").readline().strip()
-        gacks_secret = self.config.get("gacks", "account_secret")
-        account_token=hashlib.sha1(gacks_secret+account_name).hexdigest()[:8]
-
-        has_activity = (summary["charges"] > 0) or (summary["credits"] > 0)
-
-        text = ""
-        text += "This email confirms that your latest billing statement for the account %s is now available on Vicci.org. " % account_name
-        text += "This statement covers the period from %s to %s.\n\n" % (start_date_str, end_date_str)
-        text += "Unique best effort machines used: %d\n" % summary["be_machines"]
-        text += "Total est effort core-hours used: %0.2f\n" % summary["be_core_hours"]
-        text += "Unique reservation machines used: %d\n" % summary["resv_machines"]
-        text += "Total charges: $ %0.2f\n" % summary["charges"]
-        text += "Total credits: $ %0.2f\n\n" % summary["credits"]
-        text += "Please see the Invoice page on the Vicci web site for detailed information:\n\n"
-        text += "https://vicci.org/db/gacks/invoices.php?account_name=%s&start_date=%d&end_date=%d&state=3&account_token=%s\n\n" % (account_name, start_date, end_date, account_token)
-        text += "Sincerely,\n"
-        text += "Vicci.org\n\n"
-        return (text, has_activity)
-
-    def mail_invoice(self, account_name, end_date=None, days=7, email_list=[], send_blank=False):
-        (invoice_email, has_activity) = self.generate_invoice_email(account_name, end_date, days)
-
-        if (not has_activity) and (not send_blank):
-            return False
-
-        for email in email_list:
-            msg = MIMEText(invoice_email)
-            msg["From"] = "billing@vicci.org"
-            msg["To"] = email
-            msg["Subject"] = "Vicci Invoice"
-            p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
-            p.communicate(msg.as_string())
 
-        # return True if invoices mailed
-        return True