fix: improved UI
This commit is contained in:
+29
-1
@@ -1,7 +1,35 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from shop.models import ProductVariant
|
||||
from shop.models import ProductVariant, Tax
|
||||
|
||||
|
||||
class ProductInitialPriceForm(forms.Form):
|
||||
"""Precio opcional que se puede fijar al crear un producto, junto con el
|
||||
resto de datos, en el mismo envío (ver backoffice/views/products.py:ProductCreateView)."""
|
||||
|
||||
price = forms.DecimalField(
|
||||
max_digits=11,
|
||||
decimal_places=2,
|
||||
required=False,
|
||||
widget=forms.NumberInput(attrs={'class': 'input input-bordered w-full', 'step': '0.01', 'placeholder': 'Precio'}),
|
||||
)
|
||||
tax = forms.ModelChoiceField(
|
||||
queryset=Tax.objects.all(),
|
||||
required=False,
|
||||
widget=forms.Select(attrs={'class': 'select select-bordered w-full'}),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if cleaned_data.get('price') is not None and not cleaned_data.get('tax'):
|
||||
raise ValidationError('Selecciona un impuesto para el precio.')
|
||||
|
||||
if cleaned_data.get('tax') and cleaned_data.get('price') is None:
|
||||
raise ValidationError('Indica un precio para el impuesto seleccionado.')
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class ProductVariantForm(forms.ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user