add support for membership, needs testing

This commit is contained in:
Pierre-antoine Comby 2020-05-10 14:59:54 +02:00
parent f9bac69aad
commit 98addc1db9
1 changed files with 15 additions and 13 deletions

View File

@ -235,37 +235,39 @@ def import_transaction(cur):
tr = SpecialTransaction.objects.create(**obj_dict)
if "cheques" in row["description"]:
MAP_IDSPECIALTRANSACTION[row["id"]] = tr
elif ttype == "adhésion":
montant = row["montant"]
m = re.search("Adhésion (\d\d\d\d)( \+ WEI)?", row["description"])
year = m.group(1)
wei = m.group(2)
if montant == 0: # old format for SoGé registration (before )
montant = 400
# Since BDE and Kfet are distinct, don't import membership transaction and use our custom transactions.
# Create Double membership to Kfet and Bde
# sometimes montant = 0, fees are modified accordingly.
bde_dict = {
"user": MAP_IDBDE[row["idbde"]],
"club": bde,
"date_start": row["date"].date(), # Only date, not time
"fee": 500,
"fee": min(500, montant)
}
kfet_dict = {
"user": MAP_IDBDE[row["idbde"]],
"club": kfet,
"date_start": row["date"].date(), # Only date, not time
"fee": montant - 500
"fee": max(montant - 500, 0),
}
try:
if row["valide"]:
with transaction.atomic():
# membership save triggers MembershipTransaction creation
bde_membership = Membership.objects.get_or_create(**bde_dict)
kfet_membership = Membership.objects.get_or_create(**kfet_dict)
bde_membership.transaction.created_at = row["date"]
bde_membership.transaction.created_at = row["transac_date"]
bde_membership.transaction.description = row["description"]
bde_membership.transaction.save()
kfet_membership.transaction.created_at = row["date"]
kfet_membership.transaction.created_at = row["transac_date"]
kfet_membership.transaction.description = row["description"] + "(Kfet)"
kfet_membership.transaction.save()
except IntegrityError as e:
raise e
else:
# don't create membership
MembershipTransaction.objects.create(**obj_dict)
elif ttype == "invitation":
m = re.search(r"Invitation (.*?) \((.*?)\)", row["description"])
if m is None: