[dialog/proprio] Externalisation de la fonction de choix d'un mode de paiement
This commit is contained in:
parent
5a50ac5c37
commit
af3806d9a3
1 changed files with 62 additions and 34 deletions
|
@ -399,26 +399,21 @@ class Dialog(machine.Dialog, blacklist.Dialog):
|
||||||
)
|
)
|
||||||
|
|
||||||
@tailcaller
|
@tailcaller
|
||||||
def proprio_vente(self, proprio, cont, tags=[], tag_paiment=None, to_set=[], have_set=[]):
|
def proprio_choose_paiement(self, proprio, cont, cancel_cont, articles=[], tag_paiment=None, comment=True, text=""):
|
||||||
"""Menu de vente du crans. Permet également de recharger le solde crans"""
|
"""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 = {
|
box_paiement = {
|
||||||
"liquide" : "Espèces",
|
"liquide" : "Espèces",
|
||||||
"cheque" : "Chèque",
|
"cheque" : "Chèque",
|
||||||
|
"carte" : "Par carte bancaire",
|
||||||
"solde" : "Solde Crans (actuel : %s€)",
|
"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):
|
def box_choose_paiment(tag, articles):
|
||||||
box_paiement_order = ["liquide", "cheque"]
|
box_paiement_order = ["liquide", "cheque", "carte"]
|
||||||
if "cransAccount" in proprio['objectClass']:
|
if "cransAccount" in proprio['objectClass']:
|
||||||
if not "SOLDE" in [art['code'] for art in articles]:
|
if not "SOLDE" in [art['code'] for art in articles]:
|
||||||
box_paiement_order.append("solde")
|
box_paiement_order.append("solde")
|
||||||
|
@ -427,8 +422,45 @@ class Dialog(machine.Dialog, blacklist.Dialog):
|
||||||
for key in box_paiement_order:
|
for key in box_paiement_order:
|
||||||
choices.append((key, box_paiement[key], 1 if key == tag else 0))
|
choices.append((key, box_paiement[key], 1 if key == tag else 0))
|
||||||
return self.dialog.radiolist(
|
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="",
|
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,
|
choices=choices,
|
||||||
timeout=self.timeout)
|
timeout=self.timeout)
|
||||||
|
|
||||||
|
@ -464,14 +496,7 @@ class Dialog(machine.Dialog, blacklist.Dialog):
|
||||||
width=70, height=5+line, timeout=self.timeout)
|
width=70, height=5+line, timeout=self.timeout)
|
||||||
return self_cont(to_set=to_set[1:], have_set=have_set + [art])
|
return self_cont(to_set=to_set[1:], have_set=have_set + [art])
|
||||||
|
|
||||||
def choose_paiment(have_set, tag, proprio, lcont, self_cont, cont):
|
def paiement(have_set, tag, proprio, comment, cancel_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")
|
|
||||||
articles = copy.deepcopy(have_set)
|
articles = copy.deepcopy(have_set)
|
||||||
for article in articles:
|
for article in articles:
|
||||||
if article['pu'] == '*':
|
if article['pu'] == '*':
|
||||||
|
@ -499,10 +524,11 @@ class Dialog(machine.Dialog, blacklist.Dialog):
|
||||||
if [a for a in facture['article'] if art['code'] == 'SOLDE']:
|
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)
|
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:
|
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)
|
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é
|
# S'il y a des article dont il faut définir la quantité
|
||||||
if to_set:
|
if to_set:
|
||||||
return self.handle_dialog_result(
|
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])]
|
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
|
# 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 = self_cont.copy()
|
||||||
lcont(to_set=[have_set[-1]] + to_set, have_set=have_set[:-1])
|
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)
|
return self.proprio_choose_paiement(proprio=proprio, cont=self_cont, cancel_cont=lcont, articles=have_set, tag_paiment=tag_paiment)
|
||||||
self_cont=self_cont(tag_paiment=tag)
|
# Et si on a choisit le mode de paiement
|
||||||
lcont(tag_paiment=tag)
|
elif have_set and comment_paiement:
|
||||||
|
cancel_cont = self_cont(comment_paiement=None)
|
||||||
return self.handle_dialog_result(
|
return self.handle_dialog_result(
|
||||||
code=code,
|
code=self.dialog.DIALOG_OK,
|
||||||
output=tag,
|
output=[],
|
||||||
cancel_cont=lcont,
|
cancel_cont=cancel_cont,
|
||||||
error_cont=self_cont,
|
error_cont=cancel_cont,
|
||||||
codes_todo=[([self.dialog.DIALOG_OK], choose_paiment, [have_set, tag, proprio, lcont, self_cont, cont])]
|
codes_todo=[([self.dialog.DIALOG_OK], paiement, [have_set, tag_paiment, proprio, comment_paiement, cancel_cont, cont])]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sinon, on propose des articles à chosir
|
# Sinon, on propose des articles à chosir
|
||||||
else:
|
else:
|
||||||
(code, tags) = self.handle_dialog(cont, box_choose_item, tags)
|
(code, tags) = self.handle_dialog(cont, box_choose_item, tags)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue