Browse Source

fcn-cotisation: add bank details

root 6 years ago
parent
commit
aba89eec45
1 changed files with 11 additions and 2 deletions
  1. 11 2
      fcn-cotisation

+ 11 - 2
fcn-cotisation

@@ -12,6 +12,9 @@ import smtplib
 from email.mime.text import MIMEText
 from email.parser import Parser
 
+# local imports
+import fcntoolbox.dolibarr as dolibarr
+
 parser = argparse.ArgumentParser()
 parser.add_argument("selection", type=str,
                     choices=["send-reminders", "report"])
@@ -31,6 +34,8 @@ s = smtplib.SMTP('localhost')
 
 conn = psycopg2.connect(database=confdoli['database'], 
   user=confdoli['user'], password=confdoli['password'])
+doli = dolibarr.Instance(conn)
+accounts = list(doli.get_bank_accounts(fields=['iban_prefix', 'bank']))
 
 parsedate = lambda x : datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")
 
@@ -79,8 +84,12 @@ def sendReminders(reminder):
   
   for adherent in adherents:
     adherent['rowid'] = int(adherent['rowid'])
-#    adherent['datefin'] = parsedate(adherent['datefin'])
-    rawemail = remindFormat.format(**adherent)
+    fdict = adherent.copy()
+    if len(accounts) > 0:
+      account = accounts[0]
+      fdict['bank_account_iban'] = account[0]
+      fdict['bank_account_bank'] = account[1]
+    rawemail = remindFormat.format(**fdict)
     parsedemail = Parser().parsestr(rawemail)
     body = parsedemail.get_payload()
     msg = MIMEText(body)