-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
45 lines (40 loc) · 1.41 KB
/
forms.py
File metadata and controls
45 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from django import forms
from django.core.exceptions import ValidationError
from .models import Outflow
class OutflowForm(forms.ModelForm):
class Meta:
model = Outflow
fields = [
'geladinho', 'quantity', 'description', 'selling_price_outflow',
]
widgets = {
'supplier': forms.Select(
attrs={'class': 'form-control'}
),
'geladinho': forms.Select(
attrs={'class': 'form-control'}
),
'quantity': forms.TextInput(
attrs={'class': 'form-control'}
),
'description': forms.Textarea(
attrs={'class': 'form-control', 'rows': 3}
),
'selling_price_outflow': forms.NumberInput(
attrs={'class': 'form-control'}
),
}
labels = {
'geladinho': 'Produto',
'quantity': 'Quantidade',
'description': 'Descrição',
'selling_price_outflow': 'Preco de venda de saída',
}
def clean_quantity(self):
quantity = self.cleaned_data.get('quantity')
geladinho = self.cleaned_data.get('geladinho')
if quantity > geladinho.quantity:
raise ValidationError(
f'A quantidade disponível em estoque para o geladinho {geladinho.flavor} é de {geladinho.quantity}'
)
return quantity