diff --git a/RepostajesDj/requirements.txt b/RepostajesDj/requirements.txt index 9303601..67be145 100644 --- a/RepostajesDj/requirements.txt +++ b/RepostajesDj/requirements.txt @@ -10,3 +10,4 @@ pycodestyle==2.12.1 pyflakes==3.2.0 sqlparse==0.5.1 typing_extensions==4.12.2 +django-calculation==1.0.0 diff --git a/RepostajesDj/vehiculos/repostajes/forms.py b/RepostajesDj/vehiculos/repostajes/forms.py index 4cdfdb7..dc1f3ea 100644 --- a/RepostajesDj/vehiculos/repostajes/forms.py +++ b/RepostajesDj/vehiculos/repostajes/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import Vehiculo, Repostaje, ReyMotaUser +import calculation class VehiculoForm(forms.ModelForm): @@ -20,17 +21,34 @@ class VehiculoForm(forms.ModelForm): class RepostajeForm(forms.ModelForm): class Meta: model = Repostaje - fields = ['fecha', 'kms', 'litros', 'descuento'] + fields = ['fecha', 'vehiculo', 'kms', 'litros', 'importe'] fecha = forms.DateField( - widget=forms.TextInput(attrs={'class': 'form-control'})) - kms = forms.DecimalField( - widget=forms.TextInput(attrs={'class': 'form-control'})) + widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'})) - Vehiculo = forms.ModelChoiceField( + vehiculo = forms.ModelChoiceField( queryset=Vehiculo.objects.all(), widget=forms.Select(attrs={'class': 'form-control'})) + kms = forms.DecimalField( + widget=forms.TextInput(attrs={'class': 'form-control'})) + + litros = forms.DecimalField( + widget=forms.TextInput(attrs={'class': 'form-control'})) + + importe = forms.DecimalField( + widget=forms.TextInput(attrs={'class': 'form-control'})) + + aplica_descuento = forms.BooleanField(initial=False, required=False) + + descuento = forms.DecimalField( + widget=calculation.FormulaInput('aplica_descuento ? parseFloat(importe*0.03).toFixed(2) : 0.0') + ) + + precioxlitro = forms.DecimalField( + widget=calculation.FormulaInput('(importe-descuento)/litros') + ) + class ReyMotaUserCreationForm(UserCreationForm): diff --git a/RepostajesDj/vehiculos/repostajes/models.py b/RepostajesDj/vehiculos/repostajes/models.py index a65f628..a91f94b 100644 --- a/RepostajesDj/vehiculos/repostajes/models.py +++ b/RepostajesDj/vehiculos/repostajes/models.py @@ -31,6 +31,7 @@ class Repostaje(models.Model): kms = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) litros = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) descuento = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) + importe = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True) precioxlitro = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) kmsrecorridos = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True) consumo = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) diff --git a/RepostajesDj/vehiculos/repostajes/templates/_branding.html b/RepostajesDj/vehiculos/repostajes/templates/_branding.html index 0c08c5b..20a1037 100644 --- a/RepostajesDj/vehiculos/repostajes/templates/_branding.html +++ b/RepostajesDj/vehiculos/repostajes/templates/_branding.html @@ -3,6 +3,6 @@ {% load filtros_de_entorno %}
- + -
\ No newline at end of file + diff --git a/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html b/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html index ee79a2e..0cf2377 100644 --- a/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html +++ b/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html @@ -10,11 +10,13 @@

{{ repostaje.fecha }}

diff --git a/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_vehiculo.html b/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_vehiculo.html index 945b757..cbc9b7c 100644 --- a/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_vehiculo.html +++ b/RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_vehiculo.html @@ -28,14 +28,26 @@ Fecha + Kilómetros Litros + Importe + Descuento + Precio por litro + Kms recorridos + Consumo/100 kms {% for repostaje in repostajes %} {{ repostaje.fecha }} + {{ repostaje.kms }} {{ repostaje.litros }} + {{ repostaje.importe }} + {{ repostaje.descuento }} + {{ repostaje.precioxlitro }} + {{ repostaje.kmsrecorridos }} + {{ repostaje.consumo }} {% endfor %} diff --git a/RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html b/RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html index 8d2be48..d85edb9 100644 --- a/RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html +++ b/RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html @@ -11,6 +11,7 @@ + {{ form.media }} {% endblock %} diff --git a/RepostajesDj/vehiculos/repostajes/templates/repostajes/index.html b/RepostajesDj/vehiculos/repostajes/templates/repostajes/index.html index 0b7b6cd..53e7b5b 100644 --- a/RepostajesDj/vehiculos/repostajes/templates/repostajes/index.html +++ b/RepostajesDj/vehiculos/repostajes/templates/repostajes/index.html @@ -9,7 +9,7 @@