add support for transactions
This commit is contained in:
parent
6ed6551459
commit
aeb5ac9f8d
|
@ -47,9 +47,7 @@ def update_line(n,N, content):
|
|||
n = str(n)
|
||||
N = str(N)
|
||||
n.rjust(len(N))
|
||||
content.ljust(41)
|
||||
content = content[:40]
|
||||
print(f"({n}/{N}) {content}", end="\r")
|
||||
print(f"({n}/{N}) {content:10.10}", end="\r")
|
||||
|
||||
@transaction.atomic
|
||||
def import_comptes(cur):
|
||||
|
@ -154,7 +152,7 @@ def import_boutons(cur):
|
|||
|
||||
@transaction.atomic
|
||||
def import_transaction(cur):
|
||||
cur.execute("SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY -id;")
|
||||
cur.execute("SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY transaction.id;")
|
||||
N = cur.rowcount
|
||||
for idx, row in enumerate(cur):
|
||||
update_line(idx,N,row["label"])
|
||||
|
@ -168,7 +166,10 @@ def import_transaction(cur):
|
|||
"reason":row["description"],
|
||||
"valid":row["valide"],
|
||||
}
|
||||
if row["type"] == "bouton":
|
||||
ttype = row["type"]
|
||||
if ttype == "don" or ttype == "transfert" or ttype == "invitation":
|
||||
transac = Transaction.objects.create(**obj_dict)
|
||||
elif ttype == "bouton":
|
||||
cat_name = row["categorie"]
|
||||
if cat_name == None:
|
||||
cat_name = 'None'
|
||||
|
@ -177,8 +178,29 @@ def import_transaction(cur):
|
|||
cat.save()
|
||||
obj_dict["category"] = cat
|
||||
transac = RecurrentTransaction.objects.create(**obj_dict)
|
||||
transac.save()
|
||||
elif row["type"] == "adhésion":
|
||||
elif ttype == "crédit" or ttype == "retrait":
|
||||
field_id = "source_id" if ttype == "crédit" else "destination_id"
|
||||
if "espèce" in row["description"]:
|
||||
obj_dict[field_id] = 1
|
||||
elif "carte" in row["description"]:
|
||||
obj_dict[field_id] = 2
|
||||
elif "cheques" in row["description"]:
|
||||
obj_dict[field_id] = 3
|
||||
elif "virement" in row["description"]:
|
||||
obj_dict[field_id] = 4
|
||||
actor = Note.objects.get(MAP_IDBDE[max(row["destinataire"],
|
||||
row["emetteur"])])
|
||||
# custom fields of SpecialTransaction
|
||||
if dest.__class__.__name__ == "NoteUser":
|
||||
obj_dict["first_name"] = dest.user.first_name
|
||||
obj_dict["last_name"] = dest.user.last_name
|
||||
elif dest.__class__.__name__ == "NoteClub":
|
||||
obj_dict["first_name"] = dest.club.name
|
||||
obj_dict["last_name"] = dest.club.name
|
||||
else:
|
||||
raise("You should'nt be there")
|
||||
transac = SpecialTransaction.objects.create(**obj_dict)
|
||||
elif ttype == "adhésion":
|
||||
print("adhesion not supported yet")
|
||||
else:
|
||||
print("other type not supported yet")
|
||||
|
@ -246,7 +268,7 @@ class Command(BaseCommand):
|
|||
MAP_IDBDE = json.load(fp)
|
||||
if kwargs["save"]:
|
||||
filename = kwargs["save"]
|
||||
with open(filename,'w') as fp:
|
||||
with open(filename,'r') as fp:
|
||||
json.dump(MAP_IDBDE,fp,sort_keys=True, indent=2)
|
||||
|
||||
# /!\ need a prober MAP_IDBDE
|
||||
|
|
Loading…
Reference in New Issue