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:
Romain Beuque 2014-03-04 11:58:47 +01:00
parent 872dbc62a0
commit 11c212be38
2 changed files with 47 additions and 11 deletions

View File

@ -162,8 +162,16 @@ class MemberModificationController(AuthenticatedRestController):
#end for
now = datetime.now()
available_months = CotisationComputes.get_available_months(now.month, 8, paid_months)
#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
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
month_price = 0
@ -178,6 +186,8 @@ class MemberModificationController(AuthenticatedRestController):
available_months_prices = []
index = 1
anniversary = CotisationComputes.generate_new_anniversary_from_ldap_items(cotisations)
for available_month in available_months:
if available_month == 8:
available_months_prices.append(
@ -185,7 +195,7 @@ class MemberModificationController(AuthenticatedRestController):
)
else:
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
index += 1

View File

@ -100,35 +100,61 @@ class CotisationComputes:
def anniversary_from_ldap_items(ldap_cotisations):
result = []
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:
cotisation_months = []
anniversary_data = cotisation.get("x-time").first()
anniversary_datetime = datetime.datetime.strptime(anniversary_data,
"%Y-%m-%d %H:%M:%S.%f")
for month in cotisation.get("x-validMonth").all():
months.append(int(month))
cotisation_months.append(int(month))
#end for
result.append((anniversary_datetime, months))
cotisation_months.sort(key=lambda val: SORT_ORDER[val])
result.append((anniversary_datetime, cotisation_months))
#end for
anniversary = 0
# tri par ordre d'inscription
result = sorted(result)
if result != []:
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])
previousMonth = -1
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
if anniversary_month == 13:
anniversary_month = 1
if anniversary_month > 9:
anniversary_year = result[0][0].year
anniversary_year = resultat[0].year
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))
#end if
#end for
return anniversary
#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
# old = SDF or no cotisation this year
def is_old_member(member, user_session, residence_dn):