From 47adbcc9465ee0d156b61f74bff186f7153a9e1d Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Tue, 2 Dec 2014 12:59:34 +0100 Subject: [PATCH] =?UTF-8?q?Adh=C3=A9sion/Connexion=20moar=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/dialog/adherent.py | 68 ++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/gestion/dialog/adherent.py b/gestion/dialog/adherent.py index 2534bd35..e7cb42f9 100644 --- a/gestion/dialog/adherent.py +++ b/gestion/dialog/adherent.py @@ -206,6 +206,14 @@ class Dialog(proprio.Dialog): return adherent def adherent_adhesion(self, cont, adherent, cancel_cont=None, tag_paiment=None, comment_paiement=None, crediter=True, facture=None): + """ + Gestion de l'adhésion à l'association d'un adhérent + Si cancel_cont est à None, cont est utilisé en cas d'annulation + tag_paiment : un mode de paiement + comment_paiement : un commentaire pour la facture + crediter : Doit-on ou non créditer tout de suite la facture + facture : Doit-t-on éditer une facture existante + """ # Boite si on ne peux pas réahdérer def box_already(end): @@ -225,6 +233,7 @@ class Dialog(proprio.Dialog): adherer = self.confirm(text="Adhésion pour un an, continuer ?", title="Adhésion de %s %s" % (adherent.get("prenom", [''])[0], adherent["nom"][0])) return adherer + # Suppression d'une facture si elle est généré mais non validé def delete_facture(facture, cont): if facture: with self.conn.search(dn=facture.dn, scope=0, mode='rw')[0] as facture: @@ -232,17 +241,24 @@ class Dialog(proprio.Dialog): raise Continue(cont) # Génération de la facture pour adhésion - def paiement(tag_paiement, adherent, finadhesion, comment, cancel_cont, cont): + def paiement(tag_paiement, adherent, finadhesion, comment, facture, cancel_cont, cont): now = time.time() new_finadhesion = datetime.datetime.fromtimestamp(max(finadhesion, now)) new_finadhesion = time.mktime(new_finadhesion.replace(year=new_finadhesion.year + config.cotisation.duree_adh_an).timetuple()) + 86400 new_debutadhesion = now - with self.conn.newFacture(adherent.dn, {}) as facture: + if facture: + facture = self.conn.search(dn=facture.dn, scope=0, mode='rw')[0] + to_create = False + else: + facture = self.conn.newFacture(adherent.dn, {}) + to_create = True + with facture: facture['modePaiement'] = unicode(tag_paiement, 'utf-8') - facture['article'].append(config.cotisation.dico_adh) facture['info'] = unicode(comment, 'utf-8') + facture['article'].append(config.cotisation.dico_adh) facture["finAdhesion"] = unicode(new_finadhesion) facture["debutAdhesion"] = unicode(new_debutadhesion) + # On peut retarder le credit pour ajouter des contribution pour la connexion internet à la facture if crediter: if self.confirm_item(item=facture, text=u"Le paiement de %sEUR a-t-il bien été reçu (mode : %s) ?\n" % (facture.total(), tag_paiement), @@ -254,9 +270,16 @@ class Dialog(proprio.Dialog): if not self.confirm(text=u"Le paiement n'a pas été reçue.\n Annuler ?", title="Annulation de l'adhésion", defaultno=True): raise Continue(cancel_cont) else: - facture.create() + if to_create: + facture.create() + else: + facture.validate_changes() + facture.history_gen() + facture.save() raise Continue(cont(facture=facture)) raise Continue(cont(adherent=adherent)) + + finadhesion = adherent.fin_adhesion() # Si fin de l'adhésion trop loin dans le futur, rien a faire if finadhesion and finadhesion - config.cotisation.delai_readh > time.time(): @@ -277,7 +300,7 @@ class Dialog(proprio.Dialog): output=[], cancel_cont=lcont, error_cont=lcont, - codes_todo=[([self.dialog.DIALOG_OK], paiement, [tag_paiment, adherent, finadhesion, comment_paiement, lcont, cont])] + codes_todo=[([self.dialog.DIALOG_OK], paiement, [tag_paiment, adherent, finadhesion, comment_paiement, facture, lcont, cont])] ) else: return self.handle_dialog_result( @@ -289,6 +312,15 @@ class Dialog(proprio.Dialog): ) def adherent_connexion(self, cont, adherent, cancel_cont=None, facture=None, mois=None, default_item=None, tag_paiment=None, comment_paiement=None): + """ + Prolonger la connexion d'un adhérent + Si cancel_cont est à None, cont sera utilisé + facture : doit-on éditer une facture existante + mois : de combien de mois prolonger la connexion + default_item : le nombre de mois selectionné par defaut + tag_paiment : le mode de paiement a utiliser si on crée une facture + comment_paiement : un commentaire à mettre si on crée une facture + """ menu = { "An": {'text':"Prolonger d'un an (pour %s€)" % config.cotisation.plafond_contribution, 'callback':TailCall(self.adherent_connexion, cont, adherent, cancel_cont, facture, 12, default_item, tag_paiment, comment_paiement)}, "NC": {'text':"Pas de connexion", 'callback':TailCall(self.adherent_connexion, cont, adherent, cancel_cont, facture, 12, default_item, tag_paiment, comment_paiement)} @@ -302,6 +334,7 @@ class Dialog(proprio.Dialog): if facture: menu_order.append("NC") + # Une boite pour choisir un nombre de mois pour prolonger la connexion def box(finconnexion, default_item=None): t_end = time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(finconnexion)) return self.dialog.menu( @@ -318,6 +351,7 @@ class Dialog(proprio.Dialog): backtitle=u"Vous êtes connecté en tant que %s" % self.conn.current_login, choices=[(k, menu[k]['text']) for k in menu_order]) + # Génération et crédit de la facture def todo(adherent, mois, finconnexion, cancel_cont, cont, facture=None, tag_paiment=None, comment=None): now = time.time() new_finconnexion = datetime.datetime.fromtimestamp(max(finconnexion, now)) @@ -325,6 +359,7 @@ class Dialog(proprio.Dialog): # pourraient subir le changement d'heure. new_finconnexion = time.mktime((new_finconnexion + dateutil.relativedelta.relativedelta(months=mois)).timetuple()) + 3600 new_debutconnexion = max(now, finconnexion) + # On édite une facture existante if facture: with self.conn.search(dn=facture.dn, scope=0, mode='rw')[0] as facture: if mois: @@ -368,29 +403,40 @@ class Dialog(proprio.Dialog): def todo_mois(tag, self_cont): if tag == 'An': mois = 12 + elif tag == 'NC': + mois = 0 else: mois = int(tag.split(' ', 1)[0]) raise Continue(self_cont(mois=mois, default_item=tag)) - self_cont = TailCall(self.adherent_connexion, cont=cont, adherent=adherent, cancel_cont=cancel_cont, facture=facture, mois=mois, default_item=default_item, tag_paiment=tag_paiment, comment_paiement=comment_paiement) + self_cont = TailCall(self.adherent_connexion, cont=cont, adherent=adherent, cancel_cont=cancel_cont, + facture=facture, mois=mois, default_item=default_item, tag_paiment=tag_paiment, + comment_paiement=comment_paiement) finadhesion = adherent.fin_adhesion() - if facture: - finadhesion = max(finadhesion, facture["finAdhesion"][0] if facture["finAdhesion"] else 0) + # Si on édite une facture, on prolonge la date de finadhesion + if facture and facture["finAdhesion"]: + finadhesion = max(finadhesion, facture["finAdhesion"][0]) finconnexion = adherent.fin_connexion() # Si l'adhésion fini avant la connexion if finadhesion <= time.time() or finadhesion < finconnexion: if finadhesion: + # Si l'adhésion est déjà fini if finadhesion <= time.time(): self.dialog.msgbox(text=u"L'adhésion a expiré, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout) + # Sinon si elle fini avant la fin de la connexion courante elif finadhesion < finconnexion: self.dialog.msgbox(text=u"L'adhésion de termine avant la fin de la connexion, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout) # Échouera si on essaie de prolonger la connexion au dela de l'adhésion et que l'adhésion est encore valable plus de quinze jours return self.adherent_adhesion(cont=self_cont, cancel_cont=cont, adherent=adherent, crediter=False) - if facture: - cancel_cont = TailCall(self.adherent_adhesion, cont=self_cont, adherent=adherent, cancel_cont=cont, tag_paiment=str(facture['modePaiement'][0]), comment_paiement=None, crediter=False, facture=facture) + + # Si on édite une facture, elle vient actuellement forcement de adherent_adhesion + if facture and cancel_cont is None: + cancel_cont = TailCall(self.adherent_adhesion, cont=self_cont, adherent=adherent, cancel_cont=cont, tag_paiment=str(facture['modePaiement'][0]) if facture['modePaiement'] else None, comment_paiement=None, crediter=False, facture=facture) self_cont(cancel_cont=cancel_cont) + + # On choisi le nombre de mois pour prolonger la connexion if mois is None: (code, tag) = self.handle_dialog(cont, box, finconnexion, default_item) return self.handle_dialog_result( @@ -400,6 +446,7 @@ class Dialog(proprio.Dialog): error_cont=self_cont, codes_todo=[([self.dialog.DIALOG_OK], todo_mois, [tag, self_cont])] ) + # Si on connait le moyen de paiement (il peut être a l'intérieure de la facture existante) elif tag_paiment or facture: lcont = self_cont.copy() if facture: @@ -413,6 +460,7 @@ class Dialog(proprio.Dialog): error_cont=lcont, codes_todo=[([self.dialog.DIALOG_OK], todo, [adherent, mois, finconnexion, lcont, cont, facture, tag_paiment, comment_paiement])] ) + # Sinon, il faut choisir une méthode de paiement else: lcont = self_cont.copy() lcont(mois=None)