-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
92 lines (70 loc) · 3.67 KB
/
forms.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from django import forms
from .models import *
from django.forms.widgets import SelectDateWidget
try:
from screener.models import Company
except ModuleNotFoundError:
Company = 'self' # O qualsiasi altro gestore che desideri in caso di mancanza dell'applicazione
class RecurringTransactionForm(forms.Form):
amount = forms.DecimalField(max_digits=10, decimal_places=2)
frequency = forms.ChoiceField(choices=[
('daily', 'Daily'),
('weekly', 'Weekly'),
('monthly', 'Monthly'),
('annual', 'Annual'),
])
type = forms.ChoiceField(choices=[
('income', 'Income'),
('expense', 'Expense'),
])
start_date = forms.DateField(widget=SelectDateWidget)
end_date = forms.DateField(widget=SelectDateWidget, required=False)
description = forms.CharField(max_length=100, required=False)
payment_method = forms.CharField()
income_type = forms.ChoiceField(choices=Income.Choices)
expenditure_type = forms.ChoiceField(choices=Expenditure.Choices)
class IncomeForm(forms.ModelForm):
class Meta:
model = Income
fields = ['date', 'time', 'amount', 'description', 'type', 'bank_account', 'cash']
error_messages = {
'date': {'invalid': 'Please enter a valid date.', 'required': 'This field is required.'},
'time': {'invalid': 'Please enter a valid time.', 'required': 'This field is required.'},
'type': {'required': 'Please select the expenditure type.'},
'amount': {'invalid': 'Please enter a valid amount.', 'required': 'This field is required.'},
'bank_account': {'required': 'Please select a bank account.'},
'cash': {'required': 'Please select a cash entity.'},
}
class ExpenditureForm(forms.ModelForm):
class Meta:
model = Expenditure
fields = ['date', 'time', 'amount', 'description', 'type', 'bank_account', 'cash']
error_messages = {
'date': {'invalid': 'Please enter a valid date.', 'required': 'This field is required.'},
'time': {'invalid': 'Please enter a valid time.', 'required': 'This field is required.'},
'type': {'required': 'Please select the expenditure type.'},
'amount': {'invalid': 'Please enter a valid amount.', 'required': 'This field is required.'},
'bank_account': {'required': 'Please select a bank account.'},
'cash': {'required': 'Please select a cash entity.'},
}
class DepositForm(forms.Form):
amount = forms.DecimalField(max_digits=10, decimal_places=2)
bank_account = forms.ModelChoiceField(queryset=BankAccount.objects.all())
class AddBankForm(forms.Form):
name = forms.CharField()
balance = forms.DecimalField(max_digits=10, decimal_places=2)
start_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}))
class AddCashAmountForm(forms.Form):
amount = forms.DecimalField(max_digits=10, decimal_places=2)
start_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}))
class TransactionStockForm(forms.Form):
#company = forms.ModelChoiceField(queryset=Company.objects.all())
quantity = forms.IntegerField()
price = forms.DecimalField(max_digits=10, decimal_places=2)
commission = forms.DecimalField(max_digits=10, decimal_places=2)
transaction_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'})) # Aggiunto widget
transaction_type = forms.ChoiceField(choices=[('BUY', 'Buy'), ('SELL', 'Sell')])
class ManageCashForm(forms.Form):
amount = forms.DecimalField(max_digits=10, decimal_places=2)
transaction_type = forms.ChoiceField(choices=[('DEPOSIT', 'Deposit'), ('WITHDRAW', 'Withdraw')])
commission = forms.DecimalField(max_digits=10, decimal_places=2)