Correction des problèmes de dates de cotisations quand il y a des discontinuités dans les cotisations. On prends le jour anniversaire de la dernière cotisation sans discontinuité, on vérifie que si on refait cotiser quelqu'un en retard, on ne soit pas perdant en lui offrant 1 mois et demi (problème si date anniversaire 15 février et qu'il recotise 2 mars, ça indiquait 2 avril - 6€)
Normalement c'est bug-free :D
This commit is contained in:
parent
872dbc62a0
commit
11c212be38
@ -162,8 +162,16 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
#end for
|
#end for
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
#si le membre est en retard, on doit pas lui faire de cadeau sur sa cotisation si nous sommes dans le mois calendaire suivant de sa due date
|
||||||
available_months = CotisationComputes.get_available_months(now.month, 8, paid_months)
|
if CotisationComputes.is_cotisation_late(show_values["member_ldap"], self.user, residence_dn) and CotisationComputes.anniversary_from_ldap_items(cotisations).day > now.day:
|
||||||
|
start_month = now.month - 1
|
||||||
|
if start_month < 0:
|
||||||
|
start_month = 12
|
||||||
|
#end if
|
||||||
|
else :
|
||||||
|
start_month = now.month
|
||||||
|
#end if
|
||||||
|
available_months = CotisationComputes.get_available_months(start_month, 8, paid_months)
|
||||||
|
|
||||||
year_price = 0
|
year_price = 0
|
||||||
month_price = 0
|
month_price = 0
|
||||||
@ -178,6 +186,8 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
available_months_prices = []
|
available_months_prices = []
|
||||||
index = 1
|
index = 1
|
||||||
|
|
||||||
|
anniversary = CotisationComputes.generate_new_anniversary_from_ldap_items(cotisations)
|
||||||
|
|
||||||
for available_month in available_months:
|
for available_month in available_months:
|
||||||
if available_month == 8:
|
if available_month == 8:
|
||||||
available_months_prices.append(
|
available_months_prices.append(
|
||||||
@ -185,7 +195,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
available_months_prices.append(
|
available_months_prices.append(
|
||||||
(available_month, str(now.day) + " " + month_names[available_month % 12], CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
(available_month, str(anniversary.day) + " " + month_names[available_month % 12], CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
||||||
)
|
)
|
||||||
#end if
|
#end if
|
||||||
index += 1
|
index += 1
|
||||||
|
@ -100,35 +100,61 @@ class CotisationComputes:
|
|||||||
def anniversary_from_ldap_items(ldap_cotisations):
|
def anniversary_from_ldap_items(ldap_cotisations):
|
||||||
result = []
|
result = []
|
||||||
months = []
|
months = []
|
||||||
|
SORT_ORDER = {9: 0, 10: 1, 11: 2, 12: 3, 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10, 8: 11}
|
||||||
for cotisation in ldap_cotisations:
|
for cotisation in ldap_cotisations:
|
||||||
|
cotisation_months = []
|
||||||
anniversary_data = cotisation.get("x-time").first()
|
anniversary_data = cotisation.get("x-time").first()
|
||||||
anniversary_datetime = datetime.datetime.strptime(anniversary_data,
|
anniversary_datetime = datetime.datetime.strptime(anniversary_data,
|
||||||
"%Y-%m-%d %H:%M:%S.%f")
|
"%Y-%m-%d %H:%M:%S.%f")
|
||||||
for month in cotisation.get("x-validMonth").all():
|
for month in cotisation.get("x-validMonth").all():
|
||||||
months.append(int(month))
|
months.append(int(month))
|
||||||
|
cotisation_months.append(int(month))
|
||||||
#end for
|
#end for
|
||||||
result.append((anniversary_datetime, months))
|
cotisation_months.sort(key=lambda val: SORT_ORDER[val])
|
||||||
|
result.append((anniversary_datetime, cotisation_months))
|
||||||
#end for
|
#end for
|
||||||
|
|
||||||
anniversary = 0
|
anniversary = 0
|
||||||
# tri par ordre d'inscription
|
# tri par ordre d'inscription
|
||||||
result = sorted(result)
|
result = sorted(result)
|
||||||
if result != []:
|
previousMonth = -1
|
||||||
anniversary_day = result[0][0].day
|
|
||||||
SORT_ORDER = {9: 0, 10: 1, 11: 2, 12: 3, 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10, 8: 11}
|
|
||||||
months.sort(key=lambda val: SORT_ORDER[val])
|
months.sort(key=lambda val: SORT_ORDER[val])
|
||||||
|
#on scanne chaque cotisation
|
||||||
|
for resultat in result:
|
||||||
|
#si on n'est pas la premiere cotisation et que les cotisations sont sans interruptions (pas de mois manquants)
|
||||||
|
#la date anniversaire reste la meme
|
||||||
|
if previousMonth != -1 and ( (resultat[1][0] == 1 and previousMonth == 12) or (resultat[1][0] == previousMonth + 1) ):
|
||||||
|
previousMonth = resultat[1][-1]
|
||||||
|
continue;
|
||||||
|
#sinon on recalcule la date anniversaire
|
||||||
|
else :
|
||||||
|
previousMonth = resultat[1][-1]
|
||||||
|
#end if
|
||||||
|
anniversary_day = resultat[0].day
|
||||||
anniversary_month = months[-1] + 1
|
anniversary_month = months[-1] + 1
|
||||||
if anniversary_month == 13:
|
if anniversary_month == 13:
|
||||||
anniversary_month = 1
|
anniversary_month = 1
|
||||||
if anniversary_month > 9:
|
if anniversary_month > 9:
|
||||||
anniversary_year = result[0][0].year
|
anniversary_year = resultat[0].year
|
||||||
else :
|
else :
|
||||||
anniversary_year = result[0][0].year + 1
|
anniversary_year = resultat[0].year + 1
|
||||||
anniversary = datetime.datetime.strptime(str(anniversary_year) + "-" + str(anniversary_month) + "-1 0:0", "%Y-%m-%d %H:%M") + datetime.timedelta(days=(anniversary_day - 1))
|
anniversary = datetime.datetime.strptime(str(anniversary_year) + "-" + str(anniversary_month) + "-1 0:0", "%Y-%m-%d %H:%M") + datetime.timedelta(days=(anniversary_day - 1))
|
||||||
#end if
|
#end for
|
||||||
return anniversary
|
return anniversary
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
# fonction de renvoi de la date anniversaire qui est la date actuelle au cas ou il n'a pas cotise depuis 30 jours, sinon date anniversaire actuelle
|
||||||
|
def generate_new_anniversary_from_ldap_items(ldap_cotisations):
|
||||||
|
anniversary = CotisationComputes.anniversary_from_ldap_items(ldap_cotisations)
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
if anniversary == 0 or (now - anniversary).days > 30:
|
||||||
|
return now
|
||||||
|
else :
|
||||||
|
return anniversary
|
||||||
|
#end if
|
||||||
|
#end def
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# old = SDF or no cotisation this year
|
# old = SDF or no cotisation this year
|
||||||
def is_old_member(member, user_session, residence_dn):
|
def is_old_member(member, user_session, residence_dn):
|
||||||
|
Loading…
Reference in New Issue
Block a user