78 lines
1.7 KiB
Python
78 lines
1.7 KiB
Python
from django import forms
|
|
from django.forms.models import inlineformset_factory
|
|
|
|
from django.forms.widgets import DateInput, DateTimeInput
|
|
|
|
from .models import Sale, SaleLine, ReconciliationJar, PaymentMethods
|
|
|
|
readonly_number_widget = forms.NumberInput(attrs={'readonly': 'readonly'})
|
|
|
|
|
|
class ImportProductsForm(forms.Form):
|
|
csv_file = forms.FileField()
|
|
|
|
|
|
class PurchaseForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Sale
|
|
fields = [
|
|
"customer",
|
|
"date",
|
|
"phone",
|
|
"description",
|
|
]
|
|
widgets = {
|
|
'date': DateInput(attrs={'type': 'date'})
|
|
}
|
|
|
|
|
|
class PurchaseLineForm(forms.ModelForm):
|
|
class Meta:
|
|
model = SaleLine
|
|
fields = [
|
|
"product",
|
|
"quantity",
|
|
"unit_price",
|
|
"description",
|
|
]
|
|
|
|
|
|
class PurchaseSummaryForm(forms.Form):
|
|
quantity_lines = forms.IntegerField(
|
|
widget=readonly_number_widget
|
|
)
|
|
quantity_products = forms.IntegerField(
|
|
widget=readonly_number_widget
|
|
)
|
|
ammount = forms.DecimalField(
|
|
max_digits=10,
|
|
decimal_places=2,
|
|
widget=readonly_number_widget
|
|
)
|
|
payment_method = forms.ChoiceField(
|
|
choices=[(PaymentMethods.CASH, PaymentMethods.CASH)],
|
|
)
|
|
|
|
|
|
SaleLineFormSet = inlineformset_factory(
|
|
Sale,
|
|
SaleLine,
|
|
extra=1,
|
|
fields='__all__'
|
|
)
|
|
|
|
|
|
class ReconciliationJarForm(forms.ModelForm):
|
|
class Meta:
|
|
model = ReconciliationJar
|
|
fields = [
|
|
'date_time',
|
|
'description',
|
|
'reconcilier',
|
|
'cash_taken',
|
|
'cash_discrepancy',
|
|
]
|
|
widgets = {
|
|
'date_time': DateTimeInput(attrs={'type': 'datetime-local'})
|
|
}
|