From e2c1d70eb4acb37f3c92ab23f9c43878adaceb5e Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 25 Feb 2020 14:19:34 +0100 Subject: [PATCH] =?UTF-8?q?Import=20boutons=20transaction,=20prep=20for=20?= =?UTF-8?q?adh=C3=A9sions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- management/commands/import_nk15.py | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/management/commands/import_nk15.py b/management/commands/import_nk15.py index 295b332..1a85d0b 100644 --- a/management/commands/import_nk15.py +++ b/management/commands/import_nk15.py @@ -16,16 +16,16 @@ from django.db import IntegrityError from django.contrib.auth.models import User from note.models import Note, NoteSpecial, NoteUser, NoteClub from note.models import Alias -from note.models import Transaction, TransactionTemplate, TemplateCategory, TransactionType -from member.models import Profile, Club +from note.models import Transaction, TransactionTemplate,\ + TemplateCategory, TemplateTransaction, MembershipTransaction +from member.models import Profile, Club, Membership """ Script d'import de la nk15: -TODO: import aliases TODO: import transactions TODO: import adhesion TODO: import activite -TODO: import +TODO: import ... """ @transaction.atomic @@ -161,11 +161,33 @@ def import_boutons(cur,map_idbde): @transaction.atomic def import_transaction(cur, map_idbde): - cur.execute("SELECT * FROM transactions;") + cur.execute("SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY -id;") for row in cur: obj_dict = { - "pk":row["id"], +# "pk": row["id"], + "destination_id" : map_idbde[row["destinataire"]], + "source_id": map_idbde[row["emetteur"]], + "created_at":make_aware(row["date"]), + "amount":row["montant"], + "quantity":row["quantite"], + "reason":row["description"], + "valid":row["valide"], } + if row["type"] == "bouton": + cat_name = row["categorie"] + if cat_name == None: + cat_name = 'None' + cat, created = TemplateCategory.objects.get_or_create(name=cat_name) + if created: + cat.save() + obj_dict["category"] = cat + transac = TemplateTransaction.objects.create(**obj_dict) + transac.save() + elif row["type"] == "adhésion": + + else: + + @transaction.atomic def import_aliases(cur,map_idbde):