From e717f23928be6aab4e57401e9448f9e8487acec9 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 18 Apr 2020 16:03:37 +0200 Subject: [PATCH] add support for special Transaction --- management/commands/import_nk15.py | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/management/commands/import_nk15.py b/management/commands/import_nk15.py index 69a1e49..f55ae36 100644 --- a/management/commands/import_nk15.py +++ b/management/commands/import_nk15.py @@ -152,18 +152,21 @@ 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"], + # "pk": row["id"], "destination_id" : MAP_IDBDE[row["destinataire"]], "source_id": MAP_IDBDE[row["emetteur"]], "created_at":make_aware(date), @@ -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)