2019-08-11 17:55:04 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-02-08 22:24:49 +00:00
|
|
|
from dal import autocomplete, forward
|
2019-08-11 17:55:04 +00:00
|
|
|
from django import forms
|
2020-02-08 19:23:17 +00:00
|
|
|
from .models import Transaction, TransactionTemplate
|
2019-08-11 17:55:04 +00:00
|
|
|
|
2020-02-18 11:31:15 +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
|
|
|
|
2020-02-08 20:40:32 +00:00
|
|
|
# Le champ de destination est remplacé par un champ d'auto-complétion.
|
|
|
|
# Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion
|
|
|
|
# et récupère les aliases valides
|
2020-02-08 22:24:49 +00:00
|
|
|
# Pour force le type d'une note, il faut rajouter le paramètre :
|
|
|
|
# forward=(forward.Const('TYPE', 'note_type') où TYPE est dans {user, club, special}
|
2020-02-08 19:23:17 +00:00
|
|
|
widgets = {
|
2020-02-18 11:31:15 +00:00
|
|
|
'destination':
|
|
|
|
autocomplete.ModelSelect2(
|
|
|
|
url='note:note_autocomplete',
|
|
|
|
attrs={
|
|
|
|
'data-placeholder': 'Note ...',
|
|
|
|
'data-minimum-input-length': 1,
|
|
|
|
},
|
|
|
|
),
|
2020-02-08 19:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TransactionForm(forms.ModelForm):
|
2020-02-08 22:24:49 +00:00
|
|
|
def save(self, commit=True):
|
|
|
|
self.instance.transaction_type = 'transfert'
|
|
|
|
|
|
|
|
super().save(commit)
|
|
|
|
|
2020-02-08 19:23:17 +00:00
|
|
|
class Meta:
|
|
|
|
model = Transaction
|
2020-02-18 11:31:15 +00:00
|
|
|
fields = (
|
|
|
|
'source',
|
|
|
|
'destination',
|
|
|
|
'reason',
|
|
|
|
'amount',
|
|
|
|
)
|
2020-02-08 19:23:17 +00:00
|
|
|
|
2020-02-08 20:40:32 +00:00
|
|
|
# Voir ci-dessus
|
2020-02-08 19:23:17 +00:00
|
|
|
widgets = {
|
2020-02-18 11:31:15 +00:00
|
|
|
'source':
|
|
|
|
autocomplete.ModelSelect2(
|
|
|
|
url='note:note_autocomplete',
|
|
|
|
attrs={
|
|
|
|
'data-placeholder': 'Note ...',
|
|
|
|
'data-minimum-input-length': 1,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
'destination':
|
|
|
|
autocomplete.ModelSelect2(
|
|
|
|
url='note:note_autocomplete',
|
|
|
|
attrs={
|
|
|
|
'data-placeholder': 'Note ...',
|
|
|
|
'data-minimum-input-length': 1,
|
|
|
|
},
|
|
|
|
),
|
2020-02-08 19:23:17 +00:00
|
|
|
}
|
2020-02-16 21:25:00 +00:00
|
|
|
|
2020-02-16 22:27:59 +00:00
|
|
|
|
2020-02-18 11:31:15 +00:00
|
|
|
class ConsoForm(forms.ModelForm):
|
2020-02-04 00:18:03 +00:00
|
|
|
def save(self, commit=True):
|
2020-02-18 11:31:15 +00:00
|
|
|
button: TransactionTemplate = TransactionTemplate.objects.filter(
|
|
|
|
name=self.data['button']).get()
|
2020-02-04 00:18:03 +00:00
|
|
|
self.instance.destination = button.destination
|
|
|
|
self.instance.amount = button.amount
|
|
|
|
self.instance.transaction_type = 'bouton'
|
|
|
|
self.instance.reason = button.name
|
|
|
|
super().save(commit)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Transaction
|
2020-02-18 11:31:15 +00:00
|
|
|
fields = ('source', )
|
2020-02-16 22:27:59 +00:00
|
|
|
|
|
|
|
# Le champ d'utilisateur est remplacé par un champ d'auto-complétion.
|
|
|
|
# Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion
|
|
|
|
# et récupère les aliases de note valides
|
|
|
|
widgets = {
|
2020-02-18 11:31:15 +00:00
|
|
|
'source':
|
|
|
|
autocomplete.ModelSelect2(
|
|
|
|
url='note:note_autocomplete',
|
|
|
|
attrs={
|
|
|
|
'data-placeholder': 'Note ...',
|
|
|
|
'data-minimum-input-length': 1,
|
|
|
|
},
|
|
|
|
),
|
2020-02-16 22:27:59 +00:00
|
|
|
}
|