add support for special Transaction
This commit is contained in:
parent
11e8b66a5d
commit
e717f23928
|
@ -152,18 +152,21 @@ def import_boutons(cur):
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def import_transaction(cur):
|
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
|
N = cur.rowcount
|
||||||
|
transac_list = []
|
||||||
for idx, row in enumerate(cur):
|
for idx, row in enumerate(cur):
|
||||||
update_line(idx,N,row["description"])
|
update_line(idx,N,row["description"])
|
||||||
# some date are set to None, use the previous one
|
# some date are set to None, use the previous one
|
||||||
date = row["date"]
|
date = row["transac_date"]
|
||||||
if date is None:
|
|
||||||
date = old_date
|
|
||||||
else:
|
|
||||||
old_date = date
|
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
# "pk": row["id"],
|
# "pk": row["id"],
|
||||||
"destination_id" : MAP_IDBDE[row["destinataire"]],
|
"destination_id" : MAP_IDBDE[row["destinataire"]],
|
||||||
"source_id": MAP_IDBDE[row["emetteur"]],
|
"source_id": MAP_IDBDE[row["emetteur"]],
|
||||||
"created_at":make_aware(date),
|
"created_at":make_aware(date),
|
||||||
|
@ -194,15 +197,15 @@ def import_transaction(cur):
|
||||||
obj_dict[field_id] = 3
|
obj_dict[field_id] = 3
|
||||||
elif "virement" in row["description"]:
|
elif "virement" in row["description"]:
|
||||||
obj_dict[field_id] = 4
|
obj_dict[field_id] = 4
|
||||||
actor = Note.objects.get(MAP_IDBDE[max(row["destinataire"],
|
pk = max(row["destinataire"], row["emetteur"])
|
||||||
row["emetteur"])])
|
actor = Note.objects.get(id=MAP_IDBDE[pk])
|
||||||
# custom fields of SpecialTransaction
|
# custom fields of SpecialTransaction
|
||||||
if dest.__class__.__name__ == "NoteUser":
|
if actor.__class__.__name__ == "NoteUser":
|
||||||
obj_dict["first_name"] = dest.user.first_name
|
obj_dict["first_name"] = actor.user.first_name
|
||||||
obj_dict["last_name"] = dest.user.last_name
|
obj_dict["last_name"] = actor.user.last_name
|
||||||
elif dest.__class__.__name__ == "NoteClub":
|
elif actor.__class__.__name__ == "NoteClub":
|
||||||
obj_dict["first_name"] = dest.club.name
|
obj_dict["first_name"] = actor.club.name
|
||||||
obj_dict["last_name"] = dest.club.name
|
obj_dict["last_name"] = actor.club.name
|
||||||
else:
|
else:
|
||||||
raise("You should'nt be there")
|
raise("You should'nt be there")
|
||||||
transac = SpecialTransaction.objects.create(**obj_dict)
|
transac = SpecialTransaction.objects.create(**obj_dict)
|
||||||
|
|
Loading…
Reference in New Issue