Parcourir la source

add function dolibarr.get_users

root il y a 6 ans
Parent
commit
ccaf31f9d2
1 fichiers modifiés avec 24 ajouts et 0 suppressions
  1. 24 0
      fcntoolbox/dolibarr.py

+ 24 - 0
fcntoolbox/dolibarr.py

@@ -68,3 +68,27 @@ class Instance:
     sqlquery = sql.SQL('SELECT {0} FROM llx_bank_account WHERE courant = 1 AND clos = 0'.format(','.join(fields)))
     self._cur.execute(sqlquery.as_string(self._cur))
     return self._cur
+
+  def get_users(self, fields=None, active_user=True, active_member=None):
+    if fields is None:
+      fields = ["firstname", "lastname", "email"]
+    sqlconds = []
+    if active_user == True:
+      sqlconds.append(sql.SQL('usr.statut=1'))
+    elif active_user == False:
+      sqlconds.append(sql.SQL('usr.statut=1'))
+    if active_member == True:
+      sqlconds.append(sql.SQL('usr.fk_member=member.rowid AND member.statut=1'))
+    elif active_member == False:
+      cond = sql.SQL("""( usr.fk_member is NULL
+        OR ( usr.fk_member=member.rowid AND member.statut=0 ) )""")
+      sqlconds.append(cond)
+    sqlcond = sql.SQL('')
+    if len(sqlconds) != 0:
+      sqlcond = sql.SQL(' WHERE ') + sql.SQL(' AND ').join(sqlconds)
+    sqlfields = [sql.SQL('usr.') + sql.Identifier(a) for a in fields]
+    sqlfields = sql.SQL(',').join(sqlfields)
+    sqlquery = sql.SQL('SELECT DISTINCT ON (usr.rowid) ') + sqlfields + sql.SQL(' FROM llx_user AS usr, llx_adherent AS member') + sqlcond
+    print(sqlquery.as_string(self._cur))
+    self._cur.execute(sqlquery.as_string(self._cur))
+    return self._cur