WIP: Validate record

This commit is contained in:
Adrien Bourmault 2022-10-08 19:04:42 +02:00
parent 2ca0becf44
commit 035f44b4b5
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 35 additions and 14 deletions

View File

@ -66,12 +66,12 @@ def gestion_read(req):
def setup_workdir():
if not os.path.isdir(WORKDIR):
os.mkdir(WORKDIR)
if not "attente" in os.listdir(WORKDIR):
os.mkdir(WORKDIR+"/impayé")
if not "nouveau" in os.listdir(WORKDIR):
os.mkdir(WORKDIR+"/validé")
if not "validé" in os.listdir(WORKDIR):
if not "transition" in os.listdir(WORKDIR):
os.mkdir(WORKDIR+"/transition")
if not "nouveau" in os.listdir(WORKDIR):
os.mkdir(WORKDIR+"/nouveau")
if not "validé" in os.listdir(WORKDIR):
os.mkdir(WORKDIR+"/validé")
def sendmail(headers, data):
msg = bytes(headers + "\n", 'utf-8') + quopri.encodestring(bytes(data, 'utf-8'))
@ -104,19 +104,18 @@ def notify_unpaid(donor):
sendmail(mailheaders, mailtext)
def validate(donor):
def validate(record):
# Get infos
request = "SELECT *, l.reference true_reference " +\
"FROM services_users su " +\
"INNER JOIN membres m ON m.id = su.id_user " +\
"INNER JOIN services_fees sf ON sf.id = su.id_fee " +\
"LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id " +\
"LEFT JOIN acc_transactions_lines l ON l.id_transaction = tu.id_transaction " +\
"INNER JOIN acc_transactions tr ON tr.id = l.id_transaction " +\
"WHERE m.id = {} AND l.id_account = 481;".format(donor)
request = "SELECT * FROM acc_transactions tr " +\
"INNER JOIN acc_transactions_lines l " +\
" ON tr.id = l.id_transaction " +\
"WHERE tr.notes LIKE '%{}%' and id_account = 469".format(record)
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
print(gestion_read(request))
return
try:
answer = gestion_read(request)["results"][-1]
except:
@ -176,7 +175,29 @@ def validate(donor):
# The end
os.remove(WORKDIR+"/transition/"+donor)
def check_record(intent):
numero, content = get_file_content_all(intent).split("|")
name, surname, address, postal_code, city, email, amount, mode = \
content.split(";")
BUF.append("* {} {}, {}".format(numero, name+" "+surname, amount))
BUF.append(" NOUVEAU DON")
BUF.append("")
lines = [ "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n".format(
name, surname, address, postal_code, city, email, amount, mode
) ]
set_file_content(WORKDIR+"/transition/"+numero, lines)
if numero in os.listdir(WORKDIR+"/transition/"):
os.remove(intent)
def validate_donors():
# Get new
for new_intent in os.listdir(WORKDIR+"/nouveau"):
check_record(WORKDIR+"/nouveau/"+new_intent)
# Validate record
for record in os.listdir(WORKDIR+"/transition"):
validate(record)