add NoteSpecial update and cleaning

This commit is contained in:
Pierre-antoine Comby 2020-05-25 01:15:43 +02:00
parent 3a636ce189
commit 5a4e3473be
1 changed files with 14 additions and 10 deletions

View File

@ -44,6 +44,12 @@ class Command(ImportCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('-a', '--alias', action='store_true', help="import alias") parser.add_argument('-a', '--alias', action='store_true', help="import alias")
def import_special_account(self, cur):
cur.execute("SELECT idbde, solde from comptes where idbde <=0")
for row in cur:
note = Note.objects.get(pk=MAP_IDBDE[row["idbde"]])
note.amount = row["solde"]
note.save()
@timed @timed
@transaction.atomic @transaction.atomic
@ -67,13 +73,13 @@ class Command(ImportCommand):
self.update_line(idx, n, pseudo) self.update_line(idx, n, pseudo)
# clean pseudo (normalized pseudo must be unique) # clean pseudo (normalized pseudo must be unique)
if pseudo_norm in ALIAS_SET: if pseudo_norm in ALIAS_SET:
pseudo = pseudo+str(row["idbde"]) pseudo = pseudo + str(row["idbde"])
else: else:
ALIAS_SET.add(pseudo_norm) ALIAS_SET.add(pseudo_norm)
# clean date # clean date
note_dict = { note_dict = {
"pk": pk_note, "pk": pk_note,
"balance": 0, "balance": row['solde'],
"last_negative": None, "last_negative": None,
"is_active": True, "is_active": True,
"display_image": "", "display_image": "",
@ -157,7 +163,6 @@ class Command(ImportCommand):
MAP_IDBDE[row["idbde"]] = pk_note MAP_IDBDE[row["idbde"]] = pk_note
pk_note += 1 pk_note += 1
bulk_mgr.done() bulk_mgr.done()
self.print_success("comptes table imported")
@timed @timed
def import_alias(self, cur, chunk_size): def import_alias(self, cur, chunk_size):
@ -179,7 +184,6 @@ class Command(ImportCommand):
if alias_norm in ALIAS_SET: if alias_norm in ALIAS_SET:
continue continue
else: else:
print(alias_norm)
ALIAS_SET.add(alias_norm) ALIAS_SET.add(alias_norm)
obj_dict = { obj_dict = {
"pk": pk_alias, "pk": pk_alias,
@ -191,7 +195,6 @@ class Command(ImportCommand):
bulk_mgr.add(Alias(**obj_dict)) bulk_mgr.add(Alias(**obj_dict))
bulk_mgr.done() bulk_mgr.done()
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
# default args, provided by ImportCommand. # default args, provided by ImportCommand.
nk15db, nk15user = kwargs['nk15db'], kwargs['nk15user'] nk15db, nk15user = kwargs['nk15db'], kwargs['nk15user']
@ -199,11 +202,12 @@ class Command(ImportCommand):
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)
self.import_account(cur,kwargs["chunk"]) self.import_special_account(cur)
self.import_account(cur, kwargs["chunk"])
# Alias Management # Alias Management
if kwargs["alias"]: if kwargs["alias"]:
self.import_alias(cur,kwargs["chunk"]) self.import_alias(cur, kwargs["chunk"])
#save to disk # save to disk
if kwargs["save"]: if kwargs["save"]:
filename = kwargs["save"] filename = kwargs["save"]
with open(filename, 'w') as fp: with open(filename, 'w') as fp: