add NoteSpecial update and cleaning
This commit is contained in:
parent
3a636ce189
commit
5a4e3473be
|
@ -44,6 +44,12 @@ class Command(ImportCommand):
|
|||
def add_arguments(self, parser):
|
||||
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
|
||||
@transaction.atomic
|
||||
|
@ -67,13 +73,13 @@ class Command(ImportCommand):
|
|||
self.update_line(idx, n, pseudo)
|
||||
# clean pseudo (normalized pseudo must be unique)
|
||||
if pseudo_norm in ALIAS_SET:
|
||||
pseudo = pseudo+str(row["idbde"])
|
||||
pseudo = pseudo + str(row["idbde"])
|
||||
else:
|
||||
ALIAS_SET.add(pseudo_norm)
|
||||
# clean date
|
||||
note_dict = {
|
||||
"pk": pk_note,
|
||||
"balance": 0,
|
||||
"balance": row['solde'],
|
||||
"last_negative": None,
|
||||
"is_active": True,
|
||||
"display_image": "",
|
||||
|
@ -157,7 +163,6 @@ class Command(ImportCommand):
|
|||
MAP_IDBDE[row["idbde"]] = pk_note
|
||||
pk_note += 1
|
||||
bulk_mgr.done()
|
||||
self.print_success("comptes table imported")
|
||||
|
||||
@timed
|
||||
def import_alias(self, cur, chunk_size):
|
||||
|
@ -179,7 +184,6 @@ class Command(ImportCommand):
|
|||
if alias_norm in ALIAS_SET:
|
||||
continue
|
||||
else:
|
||||
print(alias_norm)
|
||||
ALIAS_SET.add(alias_norm)
|
||||
obj_dict = {
|
||||
"pk": pk_alias,
|
||||
|
@ -191,19 +195,19 @@ class Command(ImportCommand):
|
|||
bulk_mgr.add(Alias(**obj_dict))
|
||||
bulk_mgr.done()
|
||||
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
# default args, provided by ImportCommand.
|
||||
nk15db, nk15user = kwargs['nk15db'], kwargs['nk15user']
|
||||
# connecting to nk15 database
|
||||
conn = pg.connect(database=nk15db, user=nk15user)
|
||||
cur = conn.cursor(cursor_factory=pge.DictCursor)
|
||||
|
||||
self.import_account(cur,kwargs["chunk"])
|
||||
# Alias Management
|
||||
|
||||
self.import_special_account(cur)
|
||||
self.import_account(cur, kwargs["chunk"])
|
||||
# Alias Management
|
||||
if kwargs["alias"]:
|
||||
self.import_alias(cur,kwargs["chunk"])
|
||||
#save to disk
|
||||
self.import_alias(cur, kwargs["chunk"])
|
||||
# save to disk
|
||||
if kwargs["save"]:
|
||||
filename = kwargs["save"]
|
||||
with open(filename, 'w') as fp:
|
||||
|
|
Loading…
Reference in New Issue