Browse Source

Ruta consumo para actualizar el consumo y los km recorridos

politica
Celestino Rey 1 year ago
parent
commit
9bd1eedf84
3 changed files with 193 additions and 1 deletions
  1. +103
    -0
      RepostajesPy/servicios/instance/automoviles20240802.sql
  2. +27
    -1
      RepostajesPy/servicios/repostajes/paginas.py
  3. +63
    -0
      RepostajesPy/servicios/repostajes/templates/consumo.html

+ 103
- 0
RepostajesPy/servicios/instance/automoviles20240802.sql View File

@ -0,0 +1,103 @@
DELETE FROM VEHICULOS;
DELETE FROM REPOSTAJES;
INSERT INTO `repostajes` (`id`, `fecha`, `vehiculo_id`, `kms`, `litros`, `descuento`, `precioxlitro`, `importe`, `kmsrecorridos`, `consumo`) VALUES
(1, '2021-12-14', '2', 52731, 0.000, 0.00, 0.000, 0.00, 0.00, 0.00),
(2, '2021-12-23', '2', 53162, 52.800, 0.00, 1.280, 67.32, 0.00, 0.00),
(3, '2021-12-31', '2', 54122, 49.990, 0.00, 1.280, 63.74, 0.00, 0.00),
(4, '2022-01-22', '2', 54946, 49.140, 0.00, 1.270, 62.65, 0.00, 0.00),
(5, '2022-02-09', '2', 55908, 49.240, 0.00, 1.320, 65.24, 0.00, 0.00),
(6, '2022-03-03', '2', 56909, 48.610, 0.00, 1.380, 67.03, 0.00, 0.00),
(7, '2022-03-18', '2', 57542, 30.060, 0.00, 1.750, 52.54, 0.00, 0.00),
(8, '2022-04-10', '2', 58497, 46.630, 0.00, 1.500, 69.98, 0.00, 0.00),
(9, '2022-05-12', '2', 59447, 47.140, 0.00, 1.530, 72.11, 0.00, 0.00),
(10, '2022-05-19', '2', 60414, 48.570, 0.00, 1.640, 79.81, 0.00, 0.00),
(11, '2022-06-09', '2', 61147, 36.200, 0.00, 1.720, 62.12, 0.00, 0.00),
(12, '2022-06-25', '2', 62116, 49.170, 0.00, 1.840, 90.29, 0.00, 0.00),
(16, '2022-09-14', '2', 66359, 53.240, 0.00, 1.590, 84.83, 0.00, 0.00),
(17, '2022-09-23', '2', 67107, 37.260, 0.00, 1.490, 55.48, 0.00, 0.00),
(19, '2023-01-24', '2', 71790, 43.040, 2.12, 1.590, 70.54, 0.00, 0.00),
(21, '2022-12-03', '2', 70061, 46.380, 2.04, 1.420, 68.13, 0.00, 0.00),
(22, '2022-12-26', '2', 70919, 44.580, 1.85, 1.340, 61.68, 0.00, 0.00),
(23, '2023-03-05', '2', 73711, 47.850, 0.00, 1.490, 71.20, 0.00, 0.00),
(24, '2023-03-25', '2', 74749, 49.840, 0.00, 1.450, 72.17, 0.00, 0.00),
(25, '2023-02-19', '2', 72763, 49.380, 2.34, 1.530, 77.97, 0.00, 0.00),
(27, '2023-05-06', '2', 76434, 32.280, 0.00, 1.370, 44.09, 0.00, 0.00),
(28, '2023-05-22', '2', 77366, 45.040, 0.00, 1.300, 58.46, 0.00, 0.00),
(45, '2022-07-09', '2', 63129, 47.030, 0.00, 1.690, 79.38, 0.00, 0.00),
(46, '2022-08-12', '2', 64088, 43.730, 0.00, 1.500, 65.55, 0.00, 0.00),
(47, '2022-08-22', '2', 65185, 52.780, 0.00, 1.490, 78.80, 0.00, 0.00),
(50, '2022-10-12', '2', 68204, 52.040, 2.51, 1.560, 83.73, 0.00, 0.00),
(51, '2022-11-11', '2', 69158, 45.280, 2.37, 1.690, 78.91, 0.00, 0.00),
(61, '2023-06-10', '2', 78170, 41.090, 0.00, 1.320, 54.16, 0.00, 0.00),
(62, '2023-06-19', '2', 79038, 40.780, 1.95, 1.430, 60.11, 0.00, 0.00),
(151, '2022-06-28', '1', 219, 9.880, 0.00, 1.920, 18.96, 0.00, 0.00),
(152, '2022-06-28', '1', 236, 27.360, 0.00, 1.880, 51.33, 0.00, 0.00),
(153, '2022-07-14', '1', 904, 32.240, 0.00, 1.720, 55.58, 0.00, 0.00),
(154, '2022-07-26', '1', 1433, 30.490, 0.00, 1.590, 48.43, 0.00, 0.00),
(155, '2022-08-21', '1', 2030, 32.920, 0.00, 1.420, 46.72, 0.00, 0.00),
(156, '2022-09-26', '1', 2627, 23.920, 0.00, 1.390, 33.16, 0.00, 0.00),
(157, '2022-10-18', '1', 3169, 22.970, 0.00, 1.430, 32.74, 0.00, 0.00),
(158, '2022-11-09', '1', 3791, 29.600, 0.00, 1.410, 41.88, 0.00, 0.00),
(159, '2022-11-27', '1', 4363, 28.800, 1.20, 1.350, 38.80, 0.00, 0.00),
(160, '2022-12-22', '1', 4851, 26.740, 1.06, 1.280, 34.18, 0.00, 0.00),
(161, '2023-01-12', '1', 5291, 23.520, 1.09, 1.500, 35.34, 0.00, 0.00),
(162, '2023-02-01', '1', 5702, 27.360, 1.28, 1.520, 41.52, 0.00, 0.00),
(163, '2023-02-20', '1', 6141, 24.090, 1.13, 1.520, 36.67, 0.00, 0.00),
(164, '2023-03-15', '1', 6631, 25.520, 1.21, 1.530, 38.96, 0.00, 0.00),
(165, '2023-04-17', '1', 7325, 29.400, 1.47, 1.620, 47.62, 0.00, 0.00),
(166, '2023-05-28', '1', 8413, 24.160, 1.17, 1.560, 37.70, 0.00, 0.00),
(167, '2023-06-25', '1', 8956, 26.380, 1.30, 1.590, 41.94, 0.00, 0.00),
(168, '2023-07-10', '1', 9471, 29.040, 1.35, 1.497, 43.49, 0.00, 0.00),
(176, '2023-07-14', '2', 79875, 40.560, 1.74, 1.407, 56.26, 0.00, 0.00),
(177, '2023-07-22', '2', 80806, 46.290, 1.95, 1.371, 63.05, 0.00, 0.00),
(178, '2023-07-25', '1', 10043, 24.850, 1.40, 1.622, 40.32, 0.00, 0.00),
(182, '2023-08-07', '2', 81695, 44.390, 0.00, 1.439, 63.88, 0.00, 0.00),
(201, '2023-08-09', '1', 10582, 26.490, 1.39, 1.696, 44.94, 0.00, 0.00),
(202, '2023-08-23', '1', 11050, 24.050, 1.22, 1.638, 39.40, 0.00, 0.00),
(203, '2023-08-27', '2', 82715, 50.400, 0.00, 1.529, 77.06, 0.00, 0.00),
(204, '2023-09-14', '1', 11508, 21.440, 1.14, 1.726, 37.00, 0.00, 0.00),
(205, '2023-09-19', '2', 83709, 48.350, 0.00, 1.598, 77.26, 0.00, 0.00),
(206, '2023-09-27', '2', 84171, 23.010, 0.00, 1.558, 35.85, 0.00, 0.00),
(207, '2023-10-10', '2', 85104, 48.000, 0.00, 1.509, 72.43, 0.00, 0.00),
(212, '2023-10-15', '1', 12006, 25.090, 1.25, 1.609, 40.37, 0.00, 0.00),
(213, '2023-10-27', '2', 86021, 46.770, 0.00, 1.499, 70.11, 0.00, 0.00),
(214, '2023-11-04', '1', 12427, 25.640, 1.17, 1.474, 37.78, 0.00, 0.00),
(215, '2023-11-11', '2', 86757, 39.580, 1.71, 1.398, 55.33, 0.00, 0.00),
(216, '2023-11-20', '1', 12933, 26.160, 0.00, 1.529, 40.00, 0.00, 0.00),
(217, '2023-11-23', '2', 87503, 42.410, 1.75, 1.331, 56.45, 0.00, 0.00),
(218, '2023-12-04', '2', 88256, 41.190, 0.00, 1.399, 57.62, 0.00, 0.00),
(219, '2023-12-17', '2', 88964, 41.200, 1.66, 1.305, 53.78, 0.00, 0.00),
(220, '2024-01-06', '1', 13414, 30.720, 1.34, 1.411, 43.36, 0.00, 0.00),
(222, '2024-01-07', '2', 89802, 47.770, 1.91, 1.293, 61.75, 0.00, 0.00),
(223, '2024-01-22', '1', 13903, 25.080, 0.00, 1.479, 37.09, 0.00, 0.00),
(224, '2024-01-27', '2', 90723, 45.250, 0.00, 1.334, 60.37, 0.00, 0.00),
(226, '2024-02-11', '1', 14365, 28.450, 0.00, 1.454, 41.37, 0.00, 0.00),
(233, '2024-02-12', '2', 91672, 48.310, 0.00, 1.449, 70.00, 0.00, 0.00),
(235, '2024-02-27', '2', 92489, 41.990, 0.00, 1.379, 57.91, 0.00, 0.00),
(236, '2024-02-29', '1', 14857, 23.960, 1.12, 1.517, 36.35, 0.00, 0.00),
(237, '2024-03-18', '1', 15287, 13.000, 0.00, 1.538, 20.00, 0.00, 0.00),
(239, '2024-03-19', '2', 93327, 43.850, 0.00, 1.374, 60.25, 0.00, 0.00),
(240, '2024-03-25', '1', 15537, 19.240, 0.00, 1.559, 30.00, 0.00, 0.00),
(241, '2024-04-06', '1', 15935, 29.390, 0.00, 1.479, 43.47, 0.00, 0.00),
(242, '2024-04-08', '2', 94167, 41.110, 0.00, 1.374, 56.49, 0.00, 0.00),
(243, '2024-04-22', '1', 16465, 25.920, 0.00, 1.569, 40.66, 0.00, 0.00),
(244, '2024-04-29', '2', 95042, 43.630, 0.00, 1.445, 63.03, 0.00, 0.00),
(247, '2024-05-13', '1', 16963, 26.800, 0.00, 1.549, 41.51, 0.00, 0.00),
(248, '2024-05-21', '2', 96585, 28.330, 0.00, 1.399, 39.63, 0.00, 0.00),
(249, '2024-05-27', '2', 97597, 49.480, 0.00, 1.373, 67.96, 0.00, 0.00),
(250, '2024-05-06', '2', 96013, 50.590, 0.00, 1.449, 73.32, 0.00, 0.00),
(251, '2024-06-03', '2', 98067, 23.970, 0.00, 1.364, 32.69, 0.00, 0.00),
(252, '2024-06-08', '2', 98609, 28.280, 1.25, 1.430, 40.44, 0.00, 0.00),
(253, '2024-06-10', '1', 17494, 26.720, 0.00, 1.494, 39.92, 0.00, 0.00),
(254, '2024-06-17', '2', 99166, 26.910, 0.00, 1.354, 36.43, 0.00, 0.00),
(255, '2024-06-26', '1', 17879, 18.910, 0.00, 1.504, 28.44, 0.00, 0.00),
(257, '2024-06-30', '2', 100048, 44.390, 0.00, 1.387, 61.57, 0.00, 0.00),
(258, '2024-07-10', '1', 18397, 25.420, 0.00, 1.514, 38.49, 0.00, 0.00),
(259, '2024-07-21', '1', 18944, 27.710, 0.00, 1.454, 40.29, 0.00, 0.00),
(260, '2024-07-23', '2', 101010, 45.250, 0.00, 1.337, 60.52, 0.00, 0.00);
INSERT INTO `vehiculos` (`id`, `marca`, `modelo`, `matricula`) VALUES
(1, 'Toyota', 'Corolla', '7630LYR'),
(2, 'BMW', '318d', '1018KPD');

+ 27
- 1
RepostajesPy/servicios/repostajes/paginas.py View File

@ -1,7 +1,7 @@
from flask import Blueprint, render_template, request, redirect, url_for, current_app, send_from_directory from flask import Blueprint, render_template, request, redirect, url_for, current_app, send_from_directory
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from flask_login import login_user, logout_user, login_required from flask_login import login_user, logout_user, login_required
from sqlalchemy import desc
from sqlalchemy import desc, asc
import datetime import datetime
import os import os
@ -187,3 +187,29 @@ def searchvehiculo():
else: else:
vehiculos = [] vehiculos = []
return render_template('searchvehiculo.html', query=query, vehiculos=vehiculos) return render_template('searchvehiculo.html', query=query, vehiculos=vehiculos)
@bp.route('/consumo')
@login_required
def consumo():
vehiculos = Vehiculos.query.all()
for vehiculo in vehiculos:
kmsanterior = 0
print("Consumo. Tratando vehículo '", vehiculo.matricula,"'")
repostajes = Repostajes.query.filter_by(vehiculo_id=vehiculo.id).order_by(Repostajes.fecha.asc()).all()
for repostaje in repostajes:
kmsrecorridos = repostaje.kms - kmsanterior
if kmsrecorridos > 0:
consumo = repostaje.litros*100/kmsrecorridos
print("Consumo: kms anteriores -> ", kmsanterior, " kms actuales ->", repostaje.kms, " recorridos ->", kmsrecorridos, " consumo ->", consumo)
kmsanterior = repostaje.kms
repostaje.kmsrecorridos = kmsrecorridos
repostaje.consumo = consumo
db.session.commit()
return render_template('consumo.html', repostajes=repostajes)

+ 63
- 0
RepostajesPy/servicios/repostajes/templates/consumo.html View File

@ -0,0 +1,63 @@
{% extends 'base.html' %}
{% block content %}
<div class="container-xl">
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<h1 class="app-page-title mb-0">Actualización de consumo</h1>
</div>
</div><!--//row-->
<nav id="orders-table-tab" class="orders-table-tab app-nav-tabs nav shadow-sm flex-column flex-sm-row mb-4">
<a class="flex-sm-fill text-sm-center nav-link active" id="repostajes-tab" data-bs-toggle="tab" href="#repostajes" role="tab" aria-controls="repostajes" aria-selected="true">Repostajes</a>
</nav>
<div class="tab-content" id="orders-table-tab-content">
<div class="tab-pane fade show active" id="repostajes" role="tabpanel" aria-labelledby="repostajes-tab">
<div class="app-card app-card-orders-table shadow-sm mb-5">
<div class="app-card-body">
<div class="table-responsive">
<!--
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell">#</th>
<th class="cell">Fecha</th>
<th class="cell">Vehículo</th>
<th style="text-align: right" class="cell">Kilómetros</th>
<th style="text-align: right" class="cell">Litros</th>
<th style="text-align: right" class="cell">Descuento</th>
<th style="text-align: right" class="cell">Precio por litro</th>
<th style="text-align: right" class="cell">Importe</th>
<th style="text-align: right" class="cell">Kms recorridos</th>
<th style="text-align: right" class="cell">Consumo</th>
</tr>
</thead>
<tbody>
{% for repostaje in repostajes %}
<tr>
<td class="cell">{{ repostaje.id }}</td>
<td class="cell">{{ repostaje.fecha }}</td>
<td class="cell">{{ repostaje.vehiculos.matricula }}</td>
<td style="text-align: right" class="cell">{{ "%.0f"|format(repostaje.kms) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.litros) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.descuento) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.precioxlitro) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.importe) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.kmsrecorridos) }}</td>
<td style="text-align: right" class="cell">{{ "%.2f €"|format(repostaje.consumo) }}</td>
</tr>
{% endfor %}
</tbody>
</table>
-->
</div><!--//table-responsive-->
</div><!--//app-card-body-->
</div><!--//app-card-->
</div><!--//tab-pane-->
</div><!--//tab-content-->
</div><!--//container-fluid-->
{% endblock %}

Loading…
Cancel
Save