sanityse date

This commit is contained in:
Pierre-antoine Comby 2020-04-11 00:33:04 +02:00
parent aeb5ac9f8d
commit 99bd9e2f4a
1 changed files with 16 additions and 9 deletions

View File

@ -152,15 +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 transaction.id;") cur.execute("SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY transactions.id;")
N = cur.rowcount N = cur.rowcount
for idx, row in enumerate(cur): for idx, row in enumerate(cur):
update_line(idx,N,row["label"]) 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
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(row["date"]), "created_at":make_aware(date),
"amount":row["montant"], "amount":row["montant"],
"quantity":row["quantite"], "quantity":row["quantite"],
"reason":row["description"], "reason":row["description"],
@ -251,24 +257,25 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
global MAP_IDBDE global MAP_IDBDE
nk15db, nk15user = kwargs['nk15db'], kwargs['nk15user'] nk15db, nk15user = kwargs['nk15db'], kwargs['nk15user']
#reset database.
call_command("migrate")
call_command("loaddata","initial")
self.print_success("reset nk20 database")
# connecting to nk15 database # connecting to nk15 database
conn = pg.connect(database=nk15db,user=nk15user) conn = pg.connect(database=nk15db,user=nk15user)
cur = conn.cursor(cursor_factory = pge.DictCursor) cur = conn.cursor(cursor_factory = pge.DictCursor)
if kwargs["comptes"]: if kwargs["comptes"]:
#reset database.
call_command("migrate")
call_command("loaddata","initial")
self.print_success("reset nk20 database")
import_comptes(cur) import_comptes(cur)
self.print_success("comptes table imported") self.print_success("comptes table imported")
elif kwargs["map"]: elif kwargs["map"]:
filename = kwargs["map"] filename = kwargs["map"]
with open(filename,'w') as fp: with open(filename,'r') as fp:
MAP_IDBDE = json.load(fp) MAP_IDBDE = json.load(fp)
MAP_IDBDE = {int(k):int(v) for k,v in MAP_IDBDE.items()}
if kwargs["save"]: if kwargs["save"]:
filename = kwargs["save"] filename = kwargs["save"]
with open(filename,'r') as fp: with open(filename,'w') as fp:
json.dump(MAP_IDBDE,fp,sort_keys=True, indent=2) json.dump(MAP_IDBDE,fp,sort_keys=True, indent=2)
# /!\ need a prober MAP_IDBDE # /!\ need a prober MAP_IDBDE