Browse Source

Añado kmsrecorridos y consumo

politica
Celestino Rey 1 year ago
parent
commit
7aa53c681e
11 changed files with 218 additions and 104 deletions
  1. +1
    -1
      RepostajesPy/K8S/Makefile
  2. +40
    -0
      RepostajesPy/servicios/migrations/versions/9e2101dd8240_añado_campos_para_kms_recorridos_y_.py
  3. +40
    -0
      RepostajesPy/servicios/migrations/versions/d880c87e5133_añado_campos_para_kms_recorridos_y_.py
  4. +40
    -0
      RepostajesPy/servicios/migrations/versions/df26e0c43964_añado_campos_para_kms_recorridos_y_.py
  5. +3
    -0
      RepostajesPy/servicios/repostajes/models.py
  6. +17
    -3
      RepostajesPy/servicios/repostajes/paginas.py
  7. +28
    -0
      RepostajesPy/servicios/repostajes/templates/_tablarepostajes.html
  8. +39
    -0
      RepostajesPy/servicios/repostajes/templates/_tablarepostajescompleta.html
  9. +2
    -2
      RepostajesPy/servicios/repostajes/templates/add_repostaje.html
  10. +4
    -69
      RepostajesPy/servicios/repostajes/templates/index.html
  11. +4
    -29
      RepostajesPy/servicios/repostajes/templates/vehiculo.html

+ 1
- 1
RepostajesPy/K8S/Makefile View File

@ -1,4 +1,4 @@
export IMG_VERSION = 1.1
export IMG_VERSION = 1.2
# limpia todo # limpia todo
all: imagen clean install all: imagen clean install


+ 40
- 0
RepostajesPy/servicios/migrations/versions/9e2101dd8240_añado_campos_para_kms_recorridos_y_.py View File

@ -0,0 +1,40 @@
"""Añado campos para kms recorridos y consumo
Revision ID: 9e2101dd8240
Revises:
Create Date: 2024-08-02 10:21:54.566834
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '9e2101dd8240'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.add_column(sa.Column('kmsrecorridos', sa.Integer(), nullable=False))
batch_op.add_column(sa.Column('consumo', sa.Integer(), nullable=False))
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_unique_constraint(batch_op.f('uq_user_username'), ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('uq_user_username'), type_='unique')
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.drop_column('consumo')
batch_op.drop_column('kmsrecorridos')
# ### end Alembic commands ###

+ 40
- 0
RepostajesPy/servicios/migrations/versions/d880c87e5133_añado_campos_para_kms_recorridos_y_.py View File

@ -0,0 +1,40 @@
"""Añado campos para kms recorridos y consumo. Valor por defecto = 0
Revision ID: d880c87e5133
Revises: df26e0c43964
Create Date: 2024-08-02 10:27:56.828732
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd880c87e5133'
down_revision = 'df26e0c43964'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.add_column(sa.Column('kmsrecorridos', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('consumo', sa.Integer(), nullable=True))
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_unique_constraint(batch_op.f('uq_user_username'), ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('uq_user_username'), type_='unique')
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.drop_column('consumo')
batch_op.drop_column('kmsrecorridos')
# ### end Alembic commands ###

+ 40
- 0
RepostajesPy/servicios/migrations/versions/df26e0c43964_añado_campos_para_kms_recorridos_y_.py View File

@ -0,0 +1,40 @@
"""Añado campos para kms recorridos y consumo. Valor por defecto = 0
Revision ID: df26e0c43964
Revises: 9e2101dd8240
Create Date: 2024-08-02 10:26:40.424171
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'df26e0c43964'
down_revision = '9e2101dd8240'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.add_column(sa.Column('kmsrecorridos', sa.Integer(), nullable=False))
batch_op.add_column(sa.Column('consumo', sa.Integer(), nullable=False))
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_unique_constraint(batch_op.f('uq_user_username'), ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('uq_user_username'), type_='unique')
with op.batch_alter_table('repostajes', schema=None) as batch_op:
batch_op.drop_column('consumo')
batch_op.drop_column('kmsrecorridos')
# ### end Alembic commands ###

+ 3
- 0
RepostajesPy/servicios/repostajes/models.py View File

@ -29,6 +29,9 @@ class Repostajes(db.Model):
descuento = db.Column(db.Integer, nullable=False) descuento = db.Column(db.Integer, nullable=False)
precioxlitro = db.Column(db.Integer, nullable=False) precioxlitro = db.Column(db.Integer, nullable=False)
importe = db.Column(db.Integer, nullable=False) importe = db.Column(db.Integer, nullable=False)
kmsrecorridos = db.Column(db.Integer, nullable=True, default=0)
consumo = db.Column(db.Integer, nullable=True, default=0)
vehiculo_id = db.Column(db.Integer, db.ForeignKey('vehiculos.id'), nullable=False) vehiculo_id = db.Column(db.Integer, db.ForeignKey('vehiculos.id'), nullable=False)


+ 17
- 3
RepostajesPy/servicios/repostajes/paginas.py View File

@ -66,10 +66,24 @@ def add_repostaje():
else : else :
descuento = 0 # no se marcó la casilla de descuento ING descuento = 0 # no se marcó la casilla de descuento ING
totalcondto = int(importe) - descuento
precioxlitro = totalcondto / int(litros)
totalcondto = float(importe) - descuento
precioxlitro = totalcondto / float(litros)
new_repostaje = Repostajes(fecha=fecha, vehiculo_id=vehiculo_id, kms=kms, litros=litros, importe=totalcondto, descuento=descuento, precioxlitro=precioxlitro)
# lee todos los repostajes del vehículo
#repostajes = Repostajes.query.filter_by(vehiculo_id=vehiculo_id).all()
repostajes = Repostajes.query.filter_by(vehiculo_id=vehiculo_id).order_by(Repostajes.fecha.desc()).first()
#for i in repostajes:
# print("add_repostaje: ", i.fecha, i.kms)
kmsrecorridos = int(kms)-int(repostajes.kms)
if kmsrecorridos > 0:
consumo = float(litros)*100/kmsrecorridos
print("add_repostaje kms recorridos: ", kmsrecorridos, " consumo: ", consumo)
new_repostaje = Repostajes(fecha=fecha, vehiculo_id=vehiculo_id, kms=kms, litros=litros, importe=totalcondto, descuento=descuento, precioxlitro=precioxlitro, kmsrecorridos=kmsrecorridos, consumo=consumo)
db.session.add(new_repostaje) db.session.add(new_repostaje)
db.session.commit() db.session.commit()


+ 28
- 0
RepostajesPy/servicios/repostajes/templates/_tablarepostajes.html View File

@ -0,0 +1,28 @@
<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 class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Descuento</th>
<th class="cell">Precio/litro</th>
<th class="cell">Importe</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>
</tr>
{% endfor %}
</tbody>
</table>

+ 39
- 0
RepostajesPy/servicios/repostajes/templates/_tablarepostajescompleta.html View File

@ -0,0 +1,39 @@
<table class="table mb-0 text-left">
<thead>
<tr>
<th class="cell">#</th>
<th class="cell">Fecha</th>
<th class="cell">Vehículo</th>
<th class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Descuento</th>
<th class="cell">Precio/litro</th>
<th class="cell">Importe</th>
<th class="cell">Recorridos</th>
<th class="cell">Consumo/100kms</th>
</tr>
</thead>
<tbody>
{% for repostaje in repostajes %}
{% if repostaje.vehiculo_id == vehiculo.id %}
<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>
{% endif %}
{% endfor %}
</tbody>
</table>

+ 2
- 2
RepostajesPy/servicios/repostajes/templates/add_repostaje.html View File

@ -26,12 +26,12 @@
<div class="text mb-3"> <div class="text mb-3">
<label for="litros">Litros</label> <label for="litros">Litros</label>
<input class="form-control" type="number" id="litros" name="litros" required>
<input class="form-control" type="number" id="litros" name="litros" required step="0.01">
</div> </div>
<div class="text mb-3"> <div class="text mb-3">
<label for="importe">Importe</label> <label for="importe">Importe</label>
<input class="form-control" type="number" id="importe" name="importe" required>
<input class="form-control" type="number" id="importe" name="importe" required step="0.01">
</div> </div>
<div class="text mb-3"> <div class="text mb-3">


+ 4
- 69
RepostajesPy/servicios/repostajes/templates/index.html View File

@ -24,84 +24,19 @@
<div class="app-card app-card-orders-table shadow-sm mb-5"> <div class="app-card app-card-orders-table shadow-sm mb-5">
<div class="app-card-body"> <div class="app-card-body">
<div class="table-responsive"> <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 class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Descuento</th>
<th class="cell">Precio/litro</th>
<th class="cell">Importe</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>
</tr>
{% endfor %}
</tbody>
</table>
{% include '_tablarepostajes.html' %}
</div><!--//table-responsive--> </div><!--//table-responsive-->
</div><!--//app-card-body--> </div><!--//app-card-body-->
</div><!--//app-card--> </div><!--//app-card-->
</div><!--//tab-pane--> </div><!--//tab-pane-->
{% for micoche in vehiculos %}
{% for vehiculo in vehiculos %}
<div class="tab-pane fade" id="{{ micoche.matricula }}" role="tabpanel" aria-labelledby="orders-paid-tab">
<div class="tab-pane fade" id="{{ vehiculo.matricula }}" role="tabpanel" aria-labelledby="orders-paid-tab">
<div class="app-card app-card-orders-table mb-5"> <div class="app-card app-card-orders-table mb-5">
<div class="app-card-body"> <div class="app-card-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table mb-0 text-left">
<thead>
<tr>
<th class="cell">#</th>
<th class="cell">Fecha</th>
<th class="cell">Vehículo</th>
<th class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Descuento</th>
<th class="cell">Precio/litro</th>
<th class="cell">Importe</th>
<!--
<th class="cell">Recorridos</th>
<th class="cell">Consumo/100kms</th>
-->
</tr>
</thead>
<tbody>
{% for repostaje in repostajes %}
{% if repostaje.vehiculo_id == micoche.id %}
<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>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% include '_tablarepostajescompleta.html' %}
</div><!--//table-responsive--> </div><!--//table-responsive-->
</div><!--//app-card-body--> </div><!--//app-card-body-->
</div><!--//app-card--> </div><!--//app-card-->


+ 4
- 29
RepostajesPy/servicios/repostajes/templates/vehiculo.html View File

@ -25,35 +25,10 @@
</div> </div>
<div class="app-card-body p-4"> <div class="app-card-body p-4">
{% if repostajes %}
<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 class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Descuento</th>
<th class="cell">Precio por litro</th>
<th class="cell">Importe</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.vehiculo }}</td>
<td style="text-align: right" class="cell">{{ repostaje.kms }}</td>
<td style="text-align: right" class="cell">{{ 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>
</tr>
{% endfor %}
</tbody>
</table>
{% if repostajes %}
{% include '_tablarepostajescompleta.html' %}
{% else %} {% else %}
<p>No se han encontrado repostajes para este vehículo</p> <p>No se han encontrado repostajes para este vehículo</p>
{% endif %} {% endif %}


Loading…
Cancel
Save