fix: responsive
CI / test (push) Failing after 1m8s
CI / build (push) Has been skipped

This commit is contained in:
2026-07-23 18:36:07 +02:00
parent 332e0fc5f4
commit ec15d8ef2e
9 changed files with 112 additions and 56 deletions
+40 -2
View File
@@ -1,7 +1,18 @@
from decimal import Decimal
from django import forms
from django.core.exceptions import ValidationError
from shop.models import ProductVariant, Tax
from shop.models import ProductPrice, ProductVariant, Tax
def price_without_tax(price_with_tax, tax):
"""El staff introduce el precio con impuestos (lo que paga el cliente);
ProductPrice.price se guarda sin impuestos, que es lo que usa el resto de
la aplicación (carritos, pedidos, shop/utils.py) para calcular bases
imponibles/impuestos. ProductPrice.save() recalcula price_with_tax a
partir de este valor, así que no hace falta guardarlo aquí."""
return round(price_with_tax / (1 + Decimal(tax.value) / 100), 2)
class ProductInitialPriceForm(forms.Form):
@@ -12,7 +23,10 @@ class ProductInitialPriceForm(forms.Form):
max_digits=11,
decimal_places=2,
required=False,
widget=forms.NumberInput(attrs={'class': 'input input-bordered w-full', 'step': '0.01', 'placeholder': 'Precio'}),
label='Precio con impuestos',
widget=forms.NumberInput(
attrs={'class': 'input input-bordered w-full', 'step': '0.01', 'placeholder': 'Precio con impuestos'}
),
)
tax = forms.ModelChoiceField(
queryset=Tax.objects.all(),
@@ -31,6 +45,30 @@ class ProductInitialPriceForm(forms.Form):
return cleaned_data
def get_price_without_tax(self):
return price_without_tax(self.cleaned_data['price'], self.cleaned_data['tax'])
class ProductPriceForm(forms.ModelForm):
"""El campo `price` del formulario representa el precio CON impuestos (lo
que introduce el staff); al guardar se convierte al precio sin impuestos,
que es lo que almacena ProductPrice.price."""
price = forms.DecimalField(
max_digits=11,
decimal_places=2,
label='Precio con impuestos',
widget=forms.NumberInput(attrs={'step': '0.01'}),
)
class Meta:
model = ProductPrice
fields = ('price', 'tax', 'current')
def save(self, commit=True):
self.instance.price = price_without_tax(self.cleaned_data['price'], self.cleaned_data['tax'])
return super().save(commit=commit)
class ProductVariantForm(forms.ModelForm):
class Meta: