|
|
|
@ -87,10 +87,6 @@ def nuevo_repostaje(request): |
|
|
|
if form.is_valid(): |
|
|
|
instancia = form.save(commit=False) |
|
|
|
|
|
|
|
print("nuevo_repostaje: descuento: ", instancia.descuento) |
|
|
|
|
|
|
|
print("nuevo_repostaje: form_cleaned data: ", form.cleaned_data) |
|
|
|
|
|
|
|
aplica_descuento = form.cleaned_data['aplica_descuento'] |
|
|
|
|
|
|
|
if aplica_descuento: |
|
|
|
@ -101,6 +97,20 @@ def nuevo_repostaje(request): |
|
|
|
instancia.importe = float(instancia.importe) - instancia.descuento |
|
|
|
instancia.precioxlitro = instancia.importe / float(instancia.litros) |
|
|
|
|
|
|
|
# lee todos los repostajes del vehículo |
|
|
|
# repostajes = Repostajes.query.filter_by(vehiculo_id=vehiculo_id).all() |
|
|
|
|
|
|
|
if Repostaje.objects.all(): |
|
|
|
repostajes = Repostaje.objects.filter(vehiculo_id=instancia.vehiculo).order_by('-fecha')[0] |
|
|
|
|
|
|
|
instancia.kmsrecorridos = instancia.kms - repostajes.kms |
|
|
|
|
|
|
|
if instancia.kmsrecorridos > 0: |
|
|
|
instancia.consumo = instancia.litros*100/instancia.kmsrecorridos |
|
|
|
else: |
|
|
|
instancia.kmsrecorridos = 0 |
|
|
|
instancia.consumo = 0 |
|
|
|
|
|
|
|
instancia.save() |
|
|
|
|
|
|
|
return redirect('lista_repostajes') |
|
|
|
@ -114,6 +124,7 @@ def nuevo_repostaje(request): |
|
|
|
@login_required |
|
|
|
def editar_repostaje(request, repostaje_id): |
|
|
|
repostaje = get_object_or_404(Repostaje, pk=repostaje_id) |
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
form = RepostajeForm(request.POST, request.FILES, instance=repostaje) |
|
|
|
if form.is_valid(): |
|
|
|
@ -126,6 +137,7 @@ def editar_repostaje(request, repostaje_id): |
|
|
|
|
|
|
|
@login_required |
|
|
|
def eliminar_repostaje(request, repostaje_id): |
|
|
|
repostaje = get_object_or_404(Repostaje, pk=repostaje_id) |
|
|
|
repostaje = Repostaje.objects.get(pk=repostaje_id) |
|
|
|
repostaje.delete() |
|
|
|
return redirect('lista_repostajes') |
|
|
|
|