Compare commits

..

3 Commits

Author SHA1 Message Date
Yohann D'ANELLO 85568dd4f5 Import remittances 2020-07-26 01:01:17 +02:00
Yohann D'ANELLO 43734b9182 Scripts are not executable 2020-07-25 21:57:46 +02:00
Yohann D'ANELLO 441c8b9659 Fix linters 2020-07-25 17:42:32 +02:00
7 changed files with 81 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,6 @@
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import re
import psycopg2 as pg
import psycopg2.extras as pge
@ -21,8 +23,12 @@ from note.models import Note, NoteClub
from activity.models import Guest, GuestTransaction, Entry
from member.models import Membership
from treasury.models import Remittance, SpecialTransactionProxy
from ._import_utils import ImportCommand, BulkCreateManager, timed
MAP_TRANSACTION = dict()
MAP_REMITTANCE = dict()
# from member/fixtures/initial
BDE_PK = 1
KFET_PK = 2
@ -157,7 +163,7 @@ class Command(ImportCommand):
).first().pk
child_dict["entry_id"] = entry_id
else:
raise(f"Guest not Found {row['id']} {first_name}, last_name")
raise Exception(f"Guest not Found {row['id']} first_name, last_name")
return obj_dict, child_dict, GuestTransaction
@ -166,7 +172,7 @@ class Command(ImportCommand):
def import_transaction(self, cur, chunk_size, idmin):
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
cur.execute(
f"SELECT t.date AS transac_date, t.type, t.emetteur,\
f"SELECT t.id, t.date AS transac_date, t.type, t.emetteur,\
t.destinataire,t.quantite, t.montant, t.description,\
t.valide, t.cantinvalidate, t.categorie, \
a.idbde, a.annee, a.wei, a.date AS adh_date, a.section\
@ -179,6 +185,9 @@ class Command(ImportCommand):
pk_transaction = 1
for idx, row in enumerate(cur):
self.update_line(idx, n, row["description"])
MAP_TRANSACTION[row["id"]] = pk_transaction
try:
date = make_aware(row["transac_date"])
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
@ -225,7 +234,8 @@ class Command(ImportCommand):
}
pk_membership += 1
pk_transaction += 1
obj_dict, child_dict, child_transaction = self._membership_transaction(row, obj_dict, child_dict, pk_membership)
obj_dict, child_dict, child_transaction =\
self._membership_transaction(row, obj_dict, child_dict, pk_membership)
# Kfet membership
# BDE Membership
obj_dict["pk"] = pk_transaction
@ -270,6 +280,51 @@ class Command(ImportCommand):
pk_transaction += 1
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
def set_roles(self):
bulk_mgr = BulkCreateManager(chunk_size=10000)
@ -297,3 +352,5 @@ class Command(ImportCommand):
self.import_buttons(cur, kwargs["chunk"], kwargs["buttons"])
self.import_transaction(cur, kwargs["chunk"], kwargs["transactions"])
self.set_roles()
self.import_remittances(cur, kwargs["chunk"])
self.import_checks(cur)

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import timedelta
@ -18,10 +19,15 @@ class Command(BaseCommand):
return parser
def handle(self, *args, **kwargs):
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]
queryset = RecurrentTransaction.objects.filter(
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():
button_id = d["template"]
button = TransactionTemplate.objects.get(pk=button_id)
self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)...".format(name=button.name, count=d["transaction_count"])))
self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)..."
.format(name=button.name, count=d["transaction_count"])))
button.highlighted = True
button.save()

View File

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