Compare commits

..

No commits in common. "85568dd4f5e24770fb2e3321100aeddcc28580a7" and "580948fe1da1904ba6418daafb48a0a64824a11b" have entirely different histories.

7 changed files with 12 additions and 81 deletions

View File

@ -1,5 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
import json import json
import time import time

View File

@ -1,5 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
import psycopg2 as pg import psycopg2 as pg
import psycopg2.extras as pge import psycopg2.extras as pge

View File

@ -1,5 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
import psycopg2 as pg import psycopg2 as pg
import psycopg2.extras as pge import psycopg2.extras as pge

View File

@ -1,6 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/env/bin python3
# SPDX-License-Identifier: GPL-3.0-or-later
import subprocess import subprocess
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand

View File

@ -1,6 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
import re import re
import psycopg2 as pg import psycopg2 as pg
import psycopg2.extras as pge import psycopg2.extras as pge
@ -23,12 +21,8 @@ from note.models import Note, NoteClub
from activity.models import Guest, GuestTransaction, Entry from activity.models import Guest, GuestTransaction, Entry
from member.models import Membership from member.models import Membership
from treasury.models import Remittance, SpecialTransactionProxy
from ._import_utils import ImportCommand, BulkCreateManager, timed from ._import_utils import ImportCommand, BulkCreateManager, timed
MAP_TRANSACTION = dict()
MAP_REMITTANCE = dict()
# from member/fixtures/initial # from member/fixtures/initial
BDE_PK = 1 BDE_PK = 1
KFET_PK = 2 KFET_PK = 2
@ -163,7 +157,7 @@ class Command(ImportCommand):
).first().pk ).first().pk
child_dict["entry_id"] = entry_id child_dict["entry_id"] = entry_id
else: else:
raise Exception(f"Guest not Found {row['id']} first_name, last_name") raise(f"Guest not Found {row['id']} {first_name}, last_name")
return obj_dict, child_dict, GuestTransaction return obj_dict, child_dict, GuestTransaction
@ -172,7 +166,7 @@ class Command(ImportCommand):
def import_transaction(self, cur, chunk_size, idmin): def import_transaction(self, cur, chunk_size, idmin):
bulk_mgr = BulkCreateManager(chunk_size=chunk_size) bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
cur.execute( cur.execute(
f"SELECT t.id, t.date AS transac_date, t.type, t.emetteur,\ f"SELECT t.date AS transac_date, t.type, t.emetteur,\
t.destinataire,t.quantite, t.montant, t.description,\ t.destinataire,t.quantite, t.montant, t.description,\
t.valide, t.cantinvalidate, t.categorie, \ t.valide, t.cantinvalidate, t.categorie, \
a.idbde, a.annee, a.wei, a.date AS adh_date, a.section\ a.idbde, a.annee, a.wei, a.date AS adh_date, a.section\
@ -185,9 +179,6 @@ class Command(ImportCommand):
pk_transaction = 1 pk_transaction = 1
for idx, row in enumerate(cur): for idx, row in enumerate(cur):
self.update_line(idx, n, row["description"]) self.update_line(idx, n, row["description"])
MAP_TRANSACTION[row["id"]] = pk_transaction
try: try:
date = make_aware(row["transac_date"]) date = make_aware(row["transac_date"])
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError): except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
@ -234,8 +225,7 @@ class Command(ImportCommand):
} }
pk_membership += 1 pk_membership += 1
pk_transaction += 1 pk_transaction += 1
obj_dict, child_dict, child_transaction =\ obj_dict, child_dict, child_transaction = self._membership_transaction(row, obj_dict, child_dict, pk_membership)
self._membership_transaction(row, obj_dict, child_dict, pk_membership)
# Kfet membership # Kfet membership
# BDE Membership # BDE Membership
obj_dict["pk"] = pk_transaction obj_dict["pk"] = pk_transaction
@ -280,51 +270,6 @@ class Command(ImportCommand):
pk_transaction += 1 pk_transaction += 1
bulk_mgr.done() bulk_mgr.done()
@timed
@transaction.atomic
def import_remittances(self, cur, chunk_size):
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
cur.execute("SELECT id, date, commentaire, close FROM remises WHERE id = 105 ORDER BY id;")
n = cur.rowcount
pk_remittance = 1
for idx, row in enumerate(cur):
self.update_line(idx, n, row["commentaire"])
MAP_REMITTANCE[row["id"]] = pk_remittance
remittance_dict = {
"pk": pk_remittance,
"date": make_aware(row["date"]),
"remittance_type_id": 1, # Only Bank checks are supported in NK15
"comment": row["commentaire"],
"closed": row["close"],
}
bulk_mgr.add(Remittance(**remittance_dict))
pk_remittance += 1
bulk_mgr.done()
@timed
def import_checks(self, cur):
cur.execute("SELECT id, nom, prenom, banque, idtransaction, idremise "
"FROM cheques WHERE idremise = 105 ORDER BY id;")
n = cur.rowcount
for idx, row in enumerate(cur):
self.update_line(idx, n, row["nom"])
tr = SpecialTransactionProxy.objects.get(transaction__id=MAP_TRANSACTION[row["idtransaction"]])
tr.remittance_id = MAP_REMITTANCE[row["idremise"]]
tr.save()
tr = tr.transaction
tr.last_name = row["nom"]
tr.first_name = row["prenom"]
tr.bank = row["banque"]
tr.save()
@timed @timed
def set_roles(self): def set_roles(self):
bulk_mgr = BulkCreateManager(chunk_size=10000) bulk_mgr = BulkCreateManager(chunk_size=10000)
@ -352,5 +297,3 @@ class Command(ImportCommand):
self.import_buttons(cur, kwargs["chunk"], kwargs["buttons"]) self.import_buttons(cur, kwargs["chunk"], kwargs["buttons"])
self.import_transaction(cur, kwargs["chunk"], kwargs["transactions"]) self.import_transaction(cur, kwargs["chunk"], kwargs["transactions"])
self.set_roles() self.set_roles()
self.import_remittances(cur, kwargs["chunk"])
self.import_checks(cur)

View File

@ -1,5 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import timedelta from datetime import timedelta
@ -19,15 +18,10 @@ class Command(BaseCommand):
return parser return parser
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
queryset = RecurrentTransaction.objects.filter( queryset = RecurrentTransaction.objects.filter(template__display=True, created_at__gte=timezone.now() - timedelta(days=30)).values("template").annotate(transaction_count=Count("template")).order_by("-transaction_count")[:10]
template__display=True,
valid=True,
created_at__gte=timezone.now() - timedelta(days=30),
).values("template").annotate(transaction_count=Count("template")).order_by("-transaction_count")[:10]
for d in queryset.all(): for d in queryset.all():
button_id = d["template"] button_id = d["template"]
button = TransactionTemplate.objects.get(pk=button_id) button = TransactionTemplate.objects.get(pk=button_id)
self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)..." self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)...".format(name=button.name, count=d["transaction_count"])))
.format(name=button.name, count=d["transaction_count"])))
button.highlighted = True button.highlighted = True
button.save() button.save()

View File

@ -1,5 +1,4 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.apps import apps from django.apps import apps