2020-02-18 20:30:26 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-09-01 13:53:56 +00:00
|
|
|
from datetime import datetime
|
2019-08-11 17:55:04 +00:00
|
|
|
|
|
|
|
from django import forms
|
2020-03-27 15:19:33 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2020-08-03 16:49:15 +00:00
|
|
|
from django.forms import CheckboxSelectMultiple
|
2020-09-01 13:53:56 +00:00
|
|
|
from django.utils.timezone import make_aware
|
2020-02-27 16:22:59 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-08-03 16:49:15 +00:00
|
|
|
from note_kfet.inputs import Autocomplete, AmountInput, DateTimePickerInput
|
2020-02-18 20:14:29 +00:00
|
|
|
|
2020-08-03 16:49:15 +00:00
|
|
|
from .models import TransactionTemplate, NoteClub, Alias
|
2020-03-07 21:28:59 +00:00
|
|
|
|
2020-02-28 12:37:31 +00:00
|
|
|
|
2019-08-11 17:55:04 +00:00
|
|
|
class TransactionTemplateForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = TransactionTemplate
|
2020-02-18 11:31:15 +00:00
|
|
|
fields = '__all__'
|
2020-02-08 19:23:17 +00:00
|
|
|
|
|
|
|
widgets = {
|
2020-02-18 11:31:15 +00:00
|
|
|
'destination':
|
2020-03-29 22:42:32 +00:00
|
|
|
Autocomplete(
|
2020-03-27 15:19:33 +00:00
|
|
|
NoteClub,
|
2020-03-07 21:28:59 +00:00
|
|
|
attrs={
|
2020-03-27 15:19:33 +00:00
|
|
|
'api_url': '/api/note/note/',
|
2020-03-27 15:32:46 +00:00
|
|
|
# We don't evaluate the content type at launch because the DB might be not initialized
|
|
|
|
'api_url_suffix':
|
2020-03-27 21:48:20 +00:00
|
|
|
lambda: '&polymorphic_ctype=' + str(ContentType.objects.get_for_model(NoteClub).pk),
|
2020-03-27 15:19:33 +00:00
|
|
|
'placeholder': 'Note ...',
|
2020-03-07 21:28:59 +00:00
|
|
|
},
|
|
|
|
),
|
2020-04-27 01:21:13 +00:00
|
|
|
'amount': AmountInput(),
|
2020-02-08 19:23:17 +00:00
|
|
|
}
|
2020-08-03 16:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SearchTransactionForm(forms.Form):
|
|
|
|
source = forms.ModelChoiceField(
|
|
|
|
queryset=Alias.objects.all(),
|
|
|
|
label=_("Source"),
|
|
|
|
required=False,
|
|
|
|
widget=Autocomplete(
|
|
|
|
Alias,
|
|
|
|
resetable=True,
|
|
|
|
attrs={
|
|
|
|
'api_url': '/api/note/alias/',
|
|
|
|
'placeholder': 'Note ...',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
destination = forms.ModelChoiceField(
|
|
|
|
queryset=Alias.objects.all(),
|
|
|
|
label=_("Destination"),
|
|
|
|
required=False,
|
|
|
|
widget=Autocomplete(
|
|
|
|
Alias,
|
|
|
|
resetable=True,
|
|
|
|
attrs={
|
|
|
|
'api_url': '/api/note/alias/',
|
|
|
|
'placeholder': 'Note ...',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
type = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=ContentType.objects.filter(app_label="note", model__endswith="transaction"),
|
|
|
|
initial=ContentType.objects.filter(app_label="note", model__endswith="transaction"),
|
|
|
|
label=_("Type"),
|
|
|
|
required=False,
|
|
|
|
widget=CheckboxSelectMultiple(),
|
|
|
|
)
|
|
|
|
|
|
|
|
reason = forms.CharField(
|
|
|
|
label=_("Reason"),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
valid = forms.BooleanField(
|
|
|
|
label=_("Valid"),
|
|
|
|
initial=False,
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
amount_gte = forms.Field(
|
|
|
|
label=_("Total amount greater than"),
|
|
|
|
initial=0,
|
|
|
|
required=False,
|
|
|
|
widget=AmountInput(),
|
|
|
|
)
|
|
|
|
|
|
|
|
amount_lte = forms.Field(
|
|
|
|
initial=2 ** 31 - 1,
|
|
|
|
label=_("Total amount less than"),
|
|
|
|
required=False,
|
|
|
|
widget=AmountInput(),
|
|
|
|
)
|
|
|
|
|
2020-09-01 13:53:56 +00:00
|
|
|
created_after = forms.DateTimeField(
|
2020-08-03 16:49:15 +00:00
|
|
|
label=_("Created after"),
|
2020-09-01 13:53:56 +00:00
|
|
|
initial=make_aware(datetime(year=2000, month=1, day=1, hour=0, minute=0)),
|
2020-08-03 16:49:15 +00:00
|
|
|
required=False,
|
|
|
|
widget=DateTimePickerInput(),
|
|
|
|
)
|
|
|
|
|
2020-09-01 13:53:56 +00:00
|
|
|
created_before = forms.DateTimeField(
|
2020-08-03 16:49:15 +00:00
|
|
|
label=_("Created before"),
|
2020-09-01 13:53:56 +00:00
|
|
|
initial=make_aware(datetime(year=2042, month=12, day=31, hour=21, minute=42)),
|
2020-08-03 16:49:15 +00:00
|
|
|
required=False,
|
|
|
|
widget=DateTimePickerInput(),
|
|
|
|
)
|