diff --git a/objets.py b/objets.py index db1cfe0..fcc2190 100644 --- a/objets.py +++ b/objets.py @@ -1724,6 +1724,7 @@ class facture(CransLdapObject): proprio_save = True return proprio_save + if not self._recuPaiement: with self.proprio() as proprio: proprio_save = credite_arts(proprio) @@ -1748,6 +1749,38 @@ class facture(CransLdapObject): proprio.save() 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): u"""Renvoie le propriétaire de la facture""" if refresh or not self._proprio: