Exemplo n.º 1
0
def save_payment(request, bill_id):
    """Enregistre le paiement
    """
    bill = get_object_or_404(Facture, pk=bill_id)
    if bill.in_use_by != request.user:
        messages.add_message(request, messages.ERROR, "Facture en cours"
                             " d'édition par %s" % request.user)
        return redirect('bill_view', bill.id)
    if request.session.get('type_selected', False):
        type_payment = request.session['type_selected']
    else:
        messages.add_message(request, messages.ERROR, "Paiement invalide")
        return redirect('prepare_payment', bill_id)
    if type(type_payment) != type(PaiementType()):
        messages.add_message(request, messages.ERROR, "Paiement invalide")
        return redirect('prepare_payment', bill_id)
    left = request.session.get('left', "0")
    right = request.session.get('right', "0")
    montant = "%s.%s" % (left, right)
    if type_payment.fixed_value:
        count = request.session.get('tickets_count', 1)
        try:
            result = bill.add_payment(type_payment, count, montant)
        except:
            messages.add_message(request, messages.ERROR, "Paiement invalide")
            return redirect('prepare_payment', bill_id)
    else:
        try:
            result = bill.add_payment(type_payment, montant)
        except:
            messages.add_message(request, messages.ERROR, "Paiement invalide")
            return redirect('prepare_payment', bill_id)
    if not result:
        messages.add_message(request,
                             messages.ERROR,
                             "Le paiement n'a pu être enregistré.")
        return redirect('prepare_payment', bill_id)
    cleanup_payment(request)
    if bill.est_soldee():
        messages.add_message(request,
                             messages.SUCCESS,
                             "La facture a été soldée.")
#        bill.used_by()
#        if "bill_in_use" in request.session.keys():
#            request.session.pop("bill_in_use")
        remove_edition(request)
        return redirect('bill_home')
    else:
        messages.add_message(request,
                             messages.SUCCESS,
                             "Le paiement a été enregistré.")
        return redirect('prepare_payment', bill_id)
Exemplo n.º 2
0
def save_payment(request, bill_id):
    """Enregistre le paiement
    :param HttpRequest request:
    :param bill_id:
    """
    bill = get_object_or_404(Facture, pk=bill_id)
    if bill.in_use_by != request.user:
        messages.add_message(request, messages.ERROR, "%s %s" % (
                             _("Bill is being edited by"), request.user))
        return redirect('bill_view', bill.id)
    if request.session.get('type_selected', False):
        type_payment = request.session['type_selected']
    else:
        messages.add_message(request, messages.ERROR, _("Invalid payment"))
        return redirect('prepare_payment', bill_id)
    if not isinstance(type_payment, type(PaiementType())):
        messages.add_message(request, messages.ERROR, _("Invalid payment"))
        return redirect('prepare_payment', bill_id)
    left = request.session.get('left', "0")
    right = request.session.get('right', "0")
    montant = "%s.%s" % (left, right)
    if type_payment.fixed_value:
        count = request.session.get('tickets_count', 1)
        try:
            result = bill.add_payment(type_payment, count, montant)
        except:
            messages.add_message(request, messages.ERROR, _("Invalid payment"))
            return redirect('prepare_payment', bill_id)
    else:
        try:
            result = bill.add_payment(type_payment, montant)
        except:
            messages.add_message(request, messages.ERROR, _("Invalid payment"))
            return redirect('prepare_payment', bill_id)
    if not result:
        messages.add_message(request, messages.ERROR,
                             _("Payment could not be saved"))
        return redirect('prepare_payment', bill_id)
    cleanup_payment(request)
    if bill.est_soldee():
        messages.add_message(request, messages.SUCCESS,
                             _("This invoice has been ended"))
#        bill.used_by()
#        if "bill_in_use" in request.session.keys():
#            request.session.pop("bill_in_use")
        remove_edition(request)
        return redirect('bill_home')
    else:
        return redirect('prepare_payment', bill_id)
Exemplo n.º 3
0
def save_payment(request, bill_id):
    """Enregistre le paiement
    """
    bill = get_object_or_404(Facture, pk=bill_id)
    if bill.in_use_by != request.user:
        messages.add_message(
            request, messages.ERROR,
            "%s %s" % (_("Bill is being edited by"), request.user))
        return redirect('bill_view', bill.id)
    if request.session.get('type_selected', False):
        type_payment = request.session['type_selected']
    else:
        messages.add_message(request, messages.ERROR, _("Invalid payment"))
        return redirect('prepare_payment', bill_id)
    if type(type_payment) != type(PaiementType()):
        messages.add_message(request, messages.ERROR, _("Invalid payment"))
        return redirect('prepare_payment', bill_id)
    left = request.session.get('left', "0")
    right = request.session.get('right', "0")
    montant = "%s.%s" % (left, right)
    if type_payment.fixed_value:
        count = request.session.get('tickets_count', 1)
        try:
            result = bill.add_payment(type_payment, count, montant)
        except:
            messages.add_message(request, messages.ERROR, _("Invalid payment"))
            return redirect('prepare_payment', bill_id)
    else:
        try:
            result = bill.add_payment(type_payment, montant)
        except:
            messages.add_message(request, messages.ERROR, _("Invalid payment"))
            return redirect('prepare_payment', bill_id)
    if not result:
        messages.add_message(request, messages.ERROR,
                             _("Payment could not be saved"))
        return redirect('prepare_payment', bill_id)
    cleanup_payment(request)
    if bill.est_soldee():
        messages.add_message(request, messages.SUCCESS,
                             _("This invoice has been ended"))
        #        bill.used_by()
        #        if "bill_in_use" in request.session.keys():
        #            request.session.pop("bill_in_use")
        remove_edition(request)
        return redirect('bill_home')
    else:
        messages.add_message(request, messages.SUCCESS, _("Payment saved"))
        return redirect('prepare_payment', bill_id)