[gest_crans,ldap_crans] Vente avec paiement de la facture via solde crans
This commit is contained in:
parent
8bd394dbe8
commit
4a7b5a2399
2 changed files with 135 additions and 91 deletions
|
@ -975,105 +975,145 @@ def set_vente(proprio):
|
|||
"""
|
||||
from config.factures import items
|
||||
|
||||
# Construction de la boîte de dialogue
|
||||
checklist = []
|
||||
texte = []
|
||||
def choose_items():
|
||||
# Construction de la boîte de dialogue
|
||||
checklist = []
|
||||
texte = []
|
||||
|
||||
for key,value in items.items():
|
||||
checklist.append(u'"%s" "%s (%s€)" "%s"' % (key, value['designation'], value['pu'], on_off(False)))
|
||||
for key,value in items.items():
|
||||
checklist.append(u'"%s" "%s (%s€)" "%s"' % (key, value['designation'], value['pu'], on_off(False)))
|
||||
|
||||
if not checklist:
|
||||
# Il n'y a rien de modifiable
|
||||
dialog(u'--title "Rien n\'est en vente pour le moment" --msgbox "Rien n\'est en vente pour le moment\n" 0 0 ')
|
||||
return
|
||||
if not checklist:
|
||||
# Il n'y a rien de modifiable
|
||||
dialog(u'--title "Rien n\'est en vente pour le moment" --msgbox "Rien n\'est en vente pour le moment\n" 0 0 ')
|
||||
return
|
||||
|
||||
|
||||
# Il y a qqch de modifiable, on construit la checklist
|
||||
arg = u'--title "Vente de consomables à %s" ' % proprio.Nom()
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "%s\n" 0 0 0 ' % '\n'.join(texte)
|
||||
arg += u' '.join(checklist)
|
||||
# Il y a qqch de modifiable, on construit la checklist
|
||||
arg = u'--title "Vente de consomables à %s" ' % proprio.Nom()
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "%s\n" 0 0 0 ' % '\n'.join(texte)
|
||||
arg += u' '.join(checklist)
|
||||
|
||||
annul, result = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
f = Facture(proprio)
|
||||
# Traitement
|
||||
for key in items.keys():
|
||||
if '%s\n' % key in result:
|
||||
while 1:
|
||||
arg = u'--title "Nombre de %s ?" ' % items[key]['designation']
|
||||
arg += u'--inputbox "" 0 0 "1" '
|
||||
annul, res = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
try:
|
||||
nombre=int(res[0])
|
||||
break
|
||||
except ValueError, c:
|
||||
arg = u'--title "Opération impossible" '
|
||||
arg += u'--msgbox "%s\n\n\n" 0 0' % to_unicode(c.args[0])
|
||||
dialog(arg)
|
||||
f.ajoute({'nombre': nombre, 'code': key, 'designation': items[key]['designation'], 'pu': items[key]['pu']})
|
||||
|
||||
checklist = []
|
||||
texte = []
|
||||
|
||||
checklist.append(u'"1" "Espèce" "%s"' % (on_off(False)))
|
||||
checklist.append(u'"2" "Chèque" "%s"' % (on_off(False)))
|
||||
|
||||
|
||||
# Il y a qqch de modifiable, on construit la checklist
|
||||
arg = u'--title "Vente de consomables à %s" ' % proprio.Nom()
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "" 0 0 0 '
|
||||
arg += u' '.join(checklist)
|
||||
|
||||
while True:
|
||||
annul, result = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
if len(result) != 1 or not result[0]:
|
||||
arg_err = u'--title "Opération impossible" '
|
||||
arg_err += u'--msgbox "Merci de choisir un seul mode de paiement\n\n\n" 0 0'
|
||||
dialog(arg_err)
|
||||
f = Facture(proprio)
|
||||
# Traitement
|
||||
for key in items.keys():
|
||||
if '%s\n' % key in result:
|
||||
while 1:
|
||||
arg = u'--title "Nombre de %s ?" ' % items[key]['designation']
|
||||
arg += u'--inputbox "" 0 0 "1" '
|
||||
annul, res = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
try:
|
||||
nombre=int(res[0])
|
||||
break
|
||||
except ValueError, c:
|
||||
arg = u'--title "Opération impossible" '
|
||||
arg += u'--msgbox "%s\n\n\n" 0 0' % to_unicode(c.args[0])
|
||||
dialog(arg)
|
||||
f.ajoute({'nombre': nombre, 'code': key, 'designation': items[key]['designation'], 'pu': items[key]['pu']})
|
||||
|
||||
texte = []
|
||||
for art in f.articles():
|
||||
texte.append(u"%dx %s à %s€" % (art['nombre'], art['designation'], art['pu']))
|
||||
texte.append(u"Total à payer: %s€" % f.total())
|
||||
arg = u'--title "Résumé de la facture à payer" '
|
||||
arg += u'--msgbox "%s\n" 0 0' % '\n'.join(texte)
|
||||
dialog(arg)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def choose_paiement(f):
|
||||
checklist = []
|
||||
texte = []
|
||||
|
||||
checklist.append(u'"1" "Espèce" "%s"' % (on_off(False)))
|
||||
checklist.append(u'"2" "Chèque" "%s"' % (on_off(False)))
|
||||
checklist.append(u'"3" "Solde Crans (actuel : %s€)" "%s"' % (proprio.solde(), on_off(False)))
|
||||
|
||||
|
||||
# Il y a qqch de modifiable, on construit la checklist
|
||||
arg = u'--title "Vente de consomables à %s" ' % proprio.Nom()
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "" 0 0 0 '
|
||||
arg += u' '.join(checklist)
|
||||
|
||||
while True:
|
||||
annul, result = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
if len(result) != 1 or not result[0]:
|
||||
arg_err = u'--title "Opération impossible" '
|
||||
arg_err += u'--msgbox "Merci de choisir un seul mode de paiement\n\n\n" 0 0'
|
||||
dialog(arg_err)
|
||||
else:
|
||||
break
|
||||
print result
|
||||
|
||||
# Ajout du commentaire
|
||||
arg = u'--title "Crédit / débit du compte de %s" ' % proprio.Nom()
|
||||
arg += u'--inputbox "Commentaire à insérer ?" 0 0'
|
||||
if "1\n" in result:
|
||||
f.modePaiement('liquide')
|
||||
paiement=u"Espèce"
|
||||
annul, comment = dialog(arg)
|
||||
elif "2\n" in result:
|
||||
f.modePaiement('cheque')
|
||||
paiement=u"Chèque"
|
||||
annul, comment = dialog(arg)
|
||||
elif "3\n" in result:
|
||||
f.modePaiement('solde')
|
||||
paiement=u"Solde Crans"
|
||||
comment = None
|
||||
|
||||
if comment and comment[0]:
|
||||
comment = comment[0]
|
||||
else:
|
||||
break
|
||||
print result
|
||||
if "1\n" in result:
|
||||
f.modePaiement('liquide')
|
||||
paiement=u"Espèce"
|
||||
elif "2\n" in result:
|
||||
f.modePaiement('cheque')
|
||||
paiement=u"Chèque"
|
||||
comment = None
|
||||
|
||||
texte = []
|
||||
for art in f.articles():
|
||||
texte.append(u"%dx %s à %s€" % (art['nombre'], art['designation'], art['pu']))
|
||||
texte.append(u"Total à payer: %s€" % f.total())
|
||||
arg = u'--title "Résumé de la facture à payer" '
|
||||
arg += u'--msgbox "%s\n" 0 0' % '\n'.join(texte)
|
||||
dialog(arg)
|
||||
return (f,paiement,comment)
|
||||
|
||||
arg = u'--title "Validation du paiement" '
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "Le paiement de %s€ a-t-il bien été reçu en %s ?\n" 0 0 0 ' % (f.total(), paiement)
|
||||
arg += ' '.join([u'"P" "Paiement de %s€ reçu" "%s"' % (f.total(), on_off(False))])
|
||||
annul, result = dialog(arg)
|
||||
if annul: return 1
|
||||
def comfirm_and_pay((f,paiement,comment)):
|
||||
|
||||
if not "P\n" in result:
|
||||
arg = u'--title "Annulation de la vente" '
|
||||
arg += u'--msgbox "Le paiement n\'ayant pas été reçue\nla vente est annulée\n" 0 0'
|
||||
dialog(arg)
|
||||
return 1
|
||||
else:
|
||||
f.recuPaiement(strftime("%Y-%m-%d %H:%M:%S"))
|
||||
f.save()
|
||||
arg = u'--title "Vente terminée" '
|
||||
arg += u'--msgbox "Vous pouvez remettre à l\'adherent les articles suivant :\n%s" 0 0' % '\n'.join(
|
||||
["%s %s" % (art['nombre'], art['designation']) for art in f.articles()])
|
||||
dialog(arg)
|
||||
arg = u'--title "Validation du paiement" '
|
||||
arg += u'--separate-output '
|
||||
arg += u'--checklist "Le paiement de %s€ a-t-il bien été reçu en %s ?\n" 0 0 0 ' % (f.total(), paiement)
|
||||
arg += ' '.join([u'"P" "Paiement de %s€ reçu" "%s"' % (f.total(), on_off(False))])
|
||||
annul, result = dialog(arg)
|
||||
if annul: return 1
|
||||
|
||||
if not "P\n" in result:
|
||||
arg = u'--title "Annulation de la vente" '
|
||||
arg += u'--msgbox "Le paiement n\'ayant pas été reçue\nla vente est annulée\n" 0 0'
|
||||
dialog(arg)
|
||||
return 1
|
||||
else:
|
||||
try:
|
||||
f.recuPaiement(strftime("%Y-%m-%d %H:%M:%S"))
|
||||
f.save()
|
||||
arg = u'--title "Vente terminée" '
|
||||
arg += u'--msgbox "Vous pouvez remettre à l\'adherent les articles suivant :\n%s" 0 0' % '\n'.join(
|
||||
["%s %s" % (art['nombre'], art['designation']) for art in f.articles()])
|
||||
dialog(arg)
|
||||
except ValueError as error:
|
||||
f.delete()
|
||||
arg = u'--title "Annulation de la vente" '
|
||||
arg += u'--msgbox "%s\n" 0 0' % error
|
||||
dialog(arg)
|
||||
return 1
|
||||
|
||||
f = choose_items()
|
||||
if isinstance(f, int):
|
||||
return f
|
||||
ret = choose_paiement(f)
|
||||
if isinstance(ret, int):
|
||||
return ret
|
||||
return comfirm_and_pay(ret)
|
||||
|
||||
|
||||
def confirm(clas):
|
||||
|
|
|
@ -3761,7 +3761,7 @@ class Facture(BaseClasseCrans):
|
|||
if not self._modifiable:
|
||||
raise NotImplementedError, "La facture n'est pas modifiable"
|
||||
|
||||
if new not in ['liquide', 'cheque', 'paypal']:
|
||||
if new not in ['liquide', 'cheque', 'paypal', 'solde']:
|
||||
raise ValueError, u'Mode de paiement non accepté'
|
||||
|
||||
self._set('modePaiement', [new])
|
||||
|
@ -3820,6 +3820,10 @@ class Facture(BaseClasseCrans):
|
|||
proprio = self.proprietaire()
|
||||
proprio.solde(operation=art['nombre']*art["pu"], comment="Facture n°%s : %s" % (self.numero(), art['designation']))
|
||||
proprio.save()
|
||||
elif self.modePaiement() == 'solde':
|
||||
proprio = self.proprietaire()
|
||||
proprio.solde(operation=0.0 - self.total(), comment="Facture n°%s" % self.numero())
|
||||
proprio.save()
|
||||
|
||||
def _frais(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue