mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-26 01:12:25 +00:00
Import remittances
This commit is contained in:
parent
43734b9182
commit
85568dd4f5
@ -23,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
|
||||
@ -159,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
|
||||
|
||||
@ -168,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\
|
||||
@ -181,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):
|
||||
@ -227,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
|
||||
@ -272,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)
|
||||
@ -299,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)
|
||||
|
Loading…
Reference in New Issue
Block a user