add support for special Transaction

This commit is contained in:
Pierre-antoine Comby 2020-04-18 16:03:37 +02:00
parent 11e8b66a5d
commit e717f23928
1 changed files with 18 additions and 15 deletions

View File

@ -152,16 +152,19 @@ 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 transactions.id;")
idmin=58770
cur.execute("SELECT *, transactions.date AS transac_date\
FROM transactions\
LEFT JOIN adhesions ON transactions.id = adhesions.id\
WHERE transactions.id> {}\
ORDER BY transactions.id;".format(idmin))
N = cur.rowcount
transac_list = []
for idx, row in enumerate(cur):
update_line(idx,N,row["description"])
# some date are set to None, use the previous one
date = row["date"]
if date is None:
date = old_date
else:
old_date = date
date = row["transac_date"]
obj_dict = {
# "pk": row["id"],
"destination_id" : MAP_IDBDE[row["destinataire"]],
@ -194,15 +197,15 @@ def import_transaction(cur):
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"])])
pk = max(row["destinataire"], row["emetteur"])
actor = Note.objects.get(id=MAP_IDBDE[pk])
# 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
if actor.__class__.__name__ == "NoteUser":
obj_dict["first_name"] = actor.user.first_name
obj_dict["last_name"] = actor.user.last_name
elif actor.__class__.__name__ == "NoteClub":
obj_dict["first_name"] = actor.club.name
obj_dict["last_name"] = actor.club.name
else:
raise("You should'nt be there")
transac = SpecialTransaction.objects.create(**obj_dict)