Import remittances

This commit is contained in:
Yohann D'ANELLO 2020-04-27 02:08:01 +02:00
parent 60a6b3c704
commit f0aa426950
1 changed files with 53 additions and 1 deletions

View File

@ -19,6 +19,7 @@ from note.models import Alias
from note.models import TemplateCategory, TransactionTemplate, \ from note.models import TemplateCategory, TransactionTemplate, \
Transaction, RecurrentTransaction, SpecialTransaction Transaction, RecurrentTransaction, SpecialTransaction
from member.models import Club, Membership from member.models import Club, Membership
from treasury.models import RemittanceType, Remittance, SpecialTransactionProxy
""" """
Script d'import de la nk15: Script d'import de la nk15:
@ -43,6 +44,7 @@ MAP_IDBDE = {
MAP_IDACTIVITY = {} MAP_IDACTIVITY = {}
MAP_NAMEACTIVITY = {} MAP_NAMEACTIVITY = {}
MAP_NAMEGUEST = {} MAP_NAMEGUEST = {}
MAP_IDSPECIALTRANSACTION = {}
def update_line(n, total, content): def update_line(n, total, content):
@ -210,7 +212,9 @@ def import_transaction(cur):
obj_dict["last_name"] = actor.club.name obj_dict["last_name"] = actor.club.name
else: else:
raise Exception("You should'nt be there") raise Exception("You should'nt be there")
SpecialTransaction.objects.create(**obj_dict) tr = SpecialTransaction.objects.create(**obj_dict)
if "cheques" in row["description"]:
MAP_IDSPECIALTRANSACTION[row["id"]] = tr
elif ttype == "adhésion": elif ttype == "adhésion":
# Since BDE and Kfet are distinct, don't import membership transaction and use our custom transactions. # Since BDE and Kfet are distinct, don't import membership transaction and use our custom transactions.
pass pass
@ -389,6 +393,50 @@ def import_memberships(cur):
raise e raise e
@transaction.atomic
def import_remittances(cur):
cur.execute("SELECT * FROM remises ORDER by id")
map_idremittance = {}
n = cur.rowcount
check_type = RemittanceType.objects.get(note__name="Chèque")
for idx, row in enumerate(cur):
update_line(idx, n, row["date"])
obj_dict = {
"date": row["date"][10:],
"remittance_type": check_type,
"comment": row["commentaire"],
"closed": row["close"],
}
try:
with transaction.atomic():
remittance = Remittance.objects.get_or_create(**obj_dict)
map_idremittance[row["id"]] = remittance
except IntegrityError as e:
raise e
print("remittances are imported")
print("imported checks")
cur.execute("SELECT * FROM cheques ORDER by id")
n = cur.rowcount
for idx, row in enumerate(cur):
update_line(idx, n, row["date"])
obj_dict = {
"date": row["date"][10:],
"remittance_type": check_type,
"comment": row["commentaire"],
"closed": row["close"],
}
tr = MAP_IDSPECIALTRANSACTION[row["idtransaction"]]
proxy = SpecialTransactionProxy.objects.get_or_create(transaction=tr)
proxy.remittance = map_idremittance[row["idremise"]]
try:
with transaction.atomic():
proxy.save()
except IntegrityError as e:
raise e
class Command(BaseCommand): class Command(BaseCommand):
""" """
Command for importing the database of NK15. Command for importing the database of NK15.
@ -405,6 +453,7 @@ class Command(BaseCommand):
parser.add_argument('-al', '--aliases', action='store_true', help="import aliases") parser.add_argument('-al', '--aliases', action='store_true', help="import aliases")
parser.add_argument('-ac', '--activities', action='store_true', help="import activities") parser.add_argument('-ac', '--activities', action='store_true', help="import activities")
parser.add_argument('-M', '--memberships', action='store_true', help="import memberships") parser.add_argument('-M', '--memberships', action='store_true', help="import memberships")
parser.add_argument('-r', '--remittances', action='store_true', help="import check remittances")
parser.add_argument('-s', '--save', action='store', help="save mapping of idbde") parser.add_argument('-s', '--save', action='store', help="save mapping of idbde")
parser.add_argument('-m', '--map', action='store', help="import mapping of idbde") parser.add_argument('-m', '--map', action='store', help="import mapping of idbde")
parser.add_argument('-d', '--nk15db', action='store', default='nk15', help='NK15 database name') parser.add_argument('-d', '--nk15db', action='store', default='nk15', help='NK15 database name')
@ -452,3 +501,6 @@ class Command(BaseCommand):
if kwargs["memberships"]: if kwargs["memberships"]:
import_memberships(cur) import_memberships(cur)
self.print_success("memberships imported\n") self.print_success("memberships imported\n")
if kwargs["remittances"]:
import_remittances(cur)
self.print_success("remittances imported\n")