Nouvelle fonction de facture qui rempli les attributs finadh, debutadh , debu con et fin con sur une facture adh ou connexion

This commit is contained in:
Gabriel Detraz 2015-10-23 19:24:44 +02:00
parent 2a806bb367
commit 5b57476ab4

View file

@ -1724,6 +1724,7 @@ class facture(CransLdapObject):
proprio_save = True proprio_save = True
return proprio_save return proprio_save
if not self._recuPaiement: if not self._recuPaiement:
with self.proprio() as proprio: with self.proprio() as proprio:
proprio_save = credite_arts(proprio) proprio_save = credite_arts(proprio)
@ -1748,6 +1749,38 @@ class facture(CransLdapObject):
proprio.save() proprio.save()
raise raise
def adhesion_connexion(self):
u"""Effectue l'adhésion ou la connexion, rempli les attribus ldap correspondants"""
def do_adh_conn(proprio):
u"""Rempli les attribus qu'il faut sur les factures d'adhésion et de connexion"""
# On parse les art et on update les attribus
_now = crans_utils.localized_datetime()
for art in self['article']:
if 'ADH' in art['code']:
self['debutAdhesion'] = max(proprio.fin_adhesion(), _now)
self['finAdhesion'] = max(proprio.fin_adhesion(), _now).replace(year=max(proprio.fin_adhesion(), _now).year + 1)
if 'CAI' in art['code']:
nbr_mois = int(art['code'].replace('CAI',''))
self['debutConnexion'] = max(proprio.fin_connexion(), _now)
con_month = max(proprio.fin_connexion(), _now).month
con_year = max(proprio.fin_connexion(), _now).year
self['finConnexion'] = max(proprio.fin_connexion(), _now).replace(year=con_year + ((con_month + nbr_mois) // 12), month= (con_month + nbr_mois) % 12)
return
# On effectue les opérations
do_adh_conn(self.proprio())
self['recuPaiement'] = crans_utils.datetime_to_generalized_time_format(crans_utils.localized_datetime())
self._recuPaiement = True
# On force l'enregistrement de la facture après avoir crédité
if self.exists():
self.save()
else:
self.create()
def proprio(self, refresh=False): def proprio(self, refresh=False):
u"""Renvoie le propriétaire de la facture""" u"""Renvoie le propriétaire de la facture"""
if refresh or not self._proprio: if refresh or not self._proprio: