mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-27 01:42:24 +00:00
sanityse date
This commit is contained in:
parent
aeb5ac9f8d
commit
99bd9e2f4a
@ -152,15 +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 transaction.id;")
|
||||
cur.execute("SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY transactions.id;")
|
||||
N = cur.rowcount
|
||||
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 = {
|
||||
# "pk": row["id"],
|
||||
"destination_id" : MAP_IDBDE[row["destinataire"]],
|
||||
"source_id": MAP_IDBDE[row["emetteur"]],
|
||||
"created_at":make_aware(row["date"]),
|
||||
"created_at":make_aware(date),
|
||||
"amount":row["montant"],
|
||||
"quantity":row["quantite"],
|
||||
"reason":row["description"],
|
||||
@ -251,24 +257,25 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **kwargs):
|
||||
global MAP_IDBDE
|
||||
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
|
||||
conn = pg.connect(database=nk15db,user=nk15user)
|
||||
cur = conn.cursor(cursor_factory = pge.DictCursor)
|
||||
|
||||
if kwargs["comptes"]:
|
||||
#reset database.
|
||||
call_command("migrate")
|
||||
call_command("loaddata","initial")
|
||||
self.print_success("reset nk20 database")
|
||||
import_comptes(cur)
|
||||
self.print_success("comptes table imported")
|
||||
elif kwargs["map"]:
|
||||
filename = kwargs["map"]
|
||||
with open(filename,'w') as fp:
|
||||
with open(filename,'r') as fp:
|
||||
MAP_IDBDE = json.load(fp)
|
||||
MAP_IDBDE = {int(k):int(v) for k,v in MAP_IDBDE.items()}
|
||||
if 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)
|
||||
|
||||
# /!\ need a prober MAP_IDBDE
|
||||
|
Loading…
Reference in New Issue
Block a user