diff --git a/gestion/dialog/proprio.py b/gestion/dialog/proprio.py index 636cf438..ed67c0df 100644 --- a/gestion/dialog/proprio.py +++ b/gestion/dialog/proprio.py @@ -399,26 +399,21 @@ class Dialog(machine.Dialog, blacklist.Dialog): ) @tailcaller - def proprio_vente(self, proprio, cont, tags=[], tag_paiment=None, to_set=[], have_set=[]): - """Menu de vente du crans. Permet également de recharger le solde crans""" + def proprio_choose_paiement(self, proprio, cont, cancel_cont, articles=[], tag_paiment=None, comment=True, text=""): + """Pour choisir un mode de paiement. + Si `articles` est donné, empêche le paiement par solde si soldes est dans articles + La continuation `cont` doit accepter en paramètre `tag_paiment` pour le mode de paiement + et `comment_paiement` pour un commentaire. + """ box_paiement = { "liquide" : "Espèces", "cheque" : "Chèque", + "carte" : "Par carte bancaire", "solde" : "Solde Crans (actuel : %s€)", } - def box_choose_item(tags): - choices = [] - for code, article in gestion.config.factures.items.items(): - choices.append((code, u"%s%s" % (article['designation'], (u' (%s€)' % article['pu']) if article['pu'] != '*' else ""), 1 if code in tags else 0)) - return self.dialog.checklist( - text="", - title="Vente de truc à %s %s" % (proprio.get("prenom", [''])[0], proprio["nom"][0]), - choices=choices, - timeout=self.timeout) - def box_choose_paiment(tag, articles): - box_paiement_order = ["liquide", "cheque"] + box_paiement_order = ["liquide", "cheque", "carte"] if "cransAccount" in proprio['objectClass']: if not "SOLDE" in [art['code'] for art in articles]: box_paiement_order.append("solde") @@ -427,8 +422,45 @@ class Dialog(machine.Dialog, blacklist.Dialog): for key in box_paiement_order: choices.append((key, box_paiement[key], 1 if key == tag else 0)) return self.dialog.radiolist( + text=text, + title="Choix d'un mode de paiement pour %s %s" % (proprio.get("prenom", [''])[0], proprio["nom"][0]), + choices=choices, + timeout=self.timeout) + + def choose_paiment(tag_paiement, proprio, self_cont, cont): + if not tag_paiement: + raise ValueError("Il faut choisir un moyen de paiement") + if comment: + code, comment_paiement = self.dialog.inputbox(text="Détail pour les espèce, nom de la note ou banque du chèque", title="Commentaire", width=70, timeout=self.timeout) + if code != self.dialog.DIALOG_OK: + raise Continue(self_cont) + if not comment_paiement: + raise ValueError("Commentaire nécessaire") + raise Continue(cont(tag_paiment=tag_paiement, comment_paiement=comment_paiement)) + + self_cont=TailCall(self.proprio_choose_paiement, proprio=proprio, cont=cont, cancel_cont=cancel_cont, tag_paiment=tag_paiment, comment=comment) + (code, tag) = self.handle_dialog(cancel_cont, box_choose_paiment, tag_paiment, articles) + self_cont=self_cont(tag_paiment=tag) + return self.handle_dialog_result( + code=code, + output=tag, + cancel_cont=cancel_cont, + error_cont=self_cont, + codes_todo=[([self.dialog.DIALOG_OK], choose_paiment, [tag, proprio, self_cont, cont])] + ) + + + @tailcaller + def proprio_vente(self, proprio, cont, tags=[], tag_paiment=None, to_set=[], have_set=[], comment_paiement=None): + """Menu de vente du crans. Permet également de recharger le solde crans""" + + def box_choose_item(tags): + choices = [] + for code, article in gestion.config.factures.items.items(): + choices.append((code, u"%s%s" % (article['designation'], (u' (%s€)' % article['pu']) if article['pu'] != '*' else ""), 1 if code in tags else 0)) + return self.dialog.checklist( text="", - title="Choix d'un mode de paiement pour %s %s" % (proprio.get("prenom", [''])[0], proprio["nom"][0]), + title="Vente de truc à %s %s" % (proprio.get("prenom", [''])[0], proprio["nom"][0]), choices=choices, timeout=self.timeout) @@ -464,14 +496,7 @@ class Dialog(machine.Dialog, blacklist.Dialog): width=70, height=5+line, timeout=self.timeout) return self_cont(to_set=to_set[1:], have_set=have_set + [art]) - def choose_paiment(have_set, tag, proprio, lcont, self_cont, cont): - if not tag: - raise ValueError("Il faut choisir un moyen de paiement") - code, comment = self.dialog.inputbox(text="Détail pour les espèce, nom de la note ou banque du chèque", title="Commentaire", width=70, timeout=self.timeout) - if code != self.dialog.DIALOG_OK: - raise Continue(self_cont) - if not comment: - raise ValueError("Commentaire nécessaire") + def paiement(have_set, tag, proprio, comment, cancel_cont, cont): articles = copy.deepcopy(have_set) for article in articles: if article['pu'] == '*': @@ -499,10 +524,11 @@ class Dialog(machine.Dialog, blacklist.Dialog): if [a for a in facture['article'] if art['code'] == 'SOLDE']: self.dialog.msgbox(text=u"Le solde de l'adhérent à bien été crédité", title="Solde crédité", width=0, height=0, timeout=self.timeout) else: - self.dialog.msgbox(text=u"Le paiement n'ayant pas été reçue\nla vente est annulée", title="Annulation de la vente", width=0, height=0, timeout=self.timeout) + if not self.confirm(text=u"Le paiement n'a pas été reçue.\n Annuler la vente ?", title="Annulation de la vente", defaultno=True): + raise Continue(cancel_cont) raise Continue(cont) - self_cont=TailCall(self.proprio_vente, proprio=proprio, cont=cont, tags=tags, tag_paiment=tag_paiment, to_set=to_set, have_set=have_set) + self_cont=TailCall(self.proprio_vente, proprio=proprio, cont=cont, tags=tags, tag_paiment=tag_paiment, to_set=to_set, have_set=have_set, comment_paiement=comment_paiement) # S'il y a des article dont il faut définir la quantité if to_set: return self.handle_dialog_result( @@ -513,19 +539,21 @@ class Dialog(machine.Dialog, blacklist.Dialog): codes_todo=[([self.dialog.DIALOG_OK], number_of_items, [to_set, have_set, self_cont])] ) # Sinon, si tous les quantités de tous les articles sont définis - elif have_set: + elif have_set and (not comment_paiement or not tag_paiment): lcont = self_cont.copy() lcont(to_set=[have_set[-1]] + to_set, have_set=have_set[:-1]) - (code, tag) = self.handle_dialog(lcont, box_choose_paiment, tag_paiment, have_set) - self_cont=self_cont(tag_paiment=tag) - lcont(tag_paiment=tag) + return self.proprio_choose_paiement(proprio=proprio, cont=self_cont, cancel_cont=lcont, articles=have_set, tag_paiment=tag_paiment) + # Et si on a choisit le mode de paiement + elif have_set and comment_paiement: + cancel_cont = self_cont(comment_paiement=None) return self.handle_dialog_result( - code=code, - output=tag, - cancel_cont=lcont, - error_cont=self_cont, - codes_todo=[([self.dialog.DIALOG_OK], choose_paiment, [have_set, tag, proprio, lcont, self_cont, cont])] - ) + code=self.dialog.DIALOG_OK, + output=[], + cancel_cont=cancel_cont, + error_cont=cancel_cont, + codes_todo=[([self.dialog.DIALOG_OK], paiement, [have_set, tag_paiment, proprio, comment_paiement, cancel_cont, cont])] + ) + # Sinon, on propose des articles à chosir else: (code, tags) = self.handle_dialog(cont, box_choose_item, tags)