Ejemplo n.º 1
0
def modificar_pago(request, pago_id):
    pago = Pago.objects.get(pk=pago_id)
    student = pago.alumno
    st_debt = student.get_deuda()
    dictionary = model_to_dict(pago, fields=[], exclude=[])

    if request.method == 'POST':
        form = PagoForm(student=student, data=request.POST)
        if form.is_valid():
            payment = form.save(commit=False)
            payment.alumno = student
            realizar_pago(payment.abona, student.id)
            payment.save()
            #return HttpResponseRedirect(reverse('f_students'))
            return HttpResponseRedirect(reverse('f_student_report', args=[payment.id]))

    else:
        form = PagoForm(dictionary,student=student)

    context = {
        'form': form, 'st': student, 'st_debt': st_debt,
    }
    return render_to_response(
        'finance/f_modificar_pago.html',
         context,
         context_instance = RequestContext(request),
    )
Ejemplo n.º 2
0
def new_payment(request, st_id):
    student = Alumno.objects.get(pk=st_id)
    st_debt = student.get_deuda()
    unpaid_cuotas = Cuota.objects.filter(alumno=st_id, paga=False)
    unpaid_unicos = UnicoPago.objects.filter(alumno=st_id, paga=False)

    if request.method == 'POST':
        form = PagoForm(student=student, data=request.POST)
        if form.is_valid():
            payment = form.save(commit=False)
            payment.alumno = student
            servicios_pagados = realizar_pago(payment.abona, student.id)
            #modificar pago(pago anterior, pago actual, student id)
            payment.save()
            for item in servicios_pagados:
                #FIXME: las cuotas se guardan con el total del pago - ver descarga(30).pdf
                it = ItemPago(pago=payment, importe=item[1], descripcion=item[0])
                it.save()

            if request.is_ajax():
                response = [{'pdf':reverse('f_student_report_nuevo', args=[payment.id]), 'success': reverse('f_students')}] 
                data = json.dumps(response, cls=DjangoJSONEncoder)
                return HttpResponse(data, mimetype='application/json')
        else:
            if request.is_ajax():
                errors_dict = {}
                if form.errors:
                    for error in form.errors:
                        e = form.errors[error]
                        errors_dict[error] = unicode(e)

                return HttpResponseBadRequest(json.dumps(errors_dict))
            
    else:
        form = PagoForm(student=student)

    context = {
        'form': form, 'st': student, 'st_debt': st_debt,
        'unpaid_cuotas': unpaid_cuotas, 'unpaid_unicos': unpaid_unicos,
    }
    return render_to_response(
        'finance/f_new_payment.html',
         context,
         context_instance = RequestContext(request),
    )
Ejemplo n.º 3
0
def modificar_pago(request, pago_id):
    pago = Pago.objects.get(pk=pago_id)
    student = pago.alumno
    st_debt = student.get_deuda()
    dictionary = model_to_dict(pago, fields=[], exclude=[])

    if request.method == 'POST':
        form = PagoForm(student=student, data=request.POST)
        if form.is_valid():
            payment = form.save(commit=False)
            payment.alumno = student
            realizar_pago(payment.abona, student.id)
            payment.save()
            #return HttpResponseRedirect(reverse('f_students'))
            return HttpResponseRedirect(
                reverse('f_student_report', args=[payment.id]))

    else:
        form = PagoForm(dictionary, student=student)

    context = {
        'form': form,
        'st': student,
        'st_debt': st_debt,
    }
    return render_to_response(
        'finance/f_modificar_pago.html',
        context,
        context_instance=RequestContext(request),
    )
Ejemplo n.º 4
0
def new_payment(request, st_id):
    student = Alumno.objects.get(pk=st_id)
    st_debt = student.get_deuda()
    unpaid_cuotas = Cuota.objects.filter(alumno=st_id, paga=False)
    unpaid_unicos = UnicoPago.objects.filter(alumno=st_id, paga=False)

    if request.method == 'POST':
        form = PagoForm(student=student, data=request.POST)
        if form.is_valid():
            payment = form.save(commit=False)
            payment.alumno = student
            servicios_pagados = realizar_pago(payment.abona, student.id)
            #modificar pago(pago anterior, pago actual, student id)
            payment.save()
            for item in servicios_pagados:
                #FIXME: las cuotas se guardan con el total del pago - ver descarga(30).pdf
                it = ItemPago(pago=payment,
                              importe=item[1],
                              descripcion=item[0])
                it.save()

            if request.is_ajax():
                response = [{
                    'pdf':
                    reverse('f_student_report_nuevo', args=[payment.id]),
                    'success':
                    reverse('f_students')
                }]
                data = json.dumps(response, cls=DjangoJSONEncoder)
                return HttpResponse(data, mimetype='application/json')
        else:
            if request.is_ajax():
                errors_dict = {}
                if form.errors:
                    for error in form.errors:
                        e = form.errors[error]
                        errors_dict[error] = unicode(e)

                return HttpResponseBadRequest(json.dumps(errors_dict))

    else:
        form = PagoForm(student=student)

    context = {
        'form': form,
        'st': student,
        'st_debt': st_debt,
        'unpaid_cuotas': unpaid_cuotas,
        'unpaid_unicos': unpaid_unicos,
    }
    return render_to_response(
        'finance/f_new_payment.html',
        context,
        context_instance=RequestContext(request),
    )