mirror of https://gitlab.crans.org/bde/nk20
Merge branch 'import_nk15' of gitlab.crans.org:bde/nk20 into import_nk15
This commit is contained in:
commit
5421943fba
|
@ -7,7 +7,8 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \
|
|||
PolymorphicChildModelFilter, PolymorphicParentModelAdmin
|
||||
|
||||
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .models.transactions import Transaction, TemplateCategory, TransactionTemplate, TransactionType
|
||||
from .models.transactions import Transaction, TemplateCategory, TransactionTemplate, \
|
||||
TemplateTransaction, MembershipTransaction
|
||||
|
||||
|
||||
class AliasInlines(admin.TabularInline):
|
||||
|
@ -97,13 +98,14 @@ class NoteUserAdmin(PolymorphicChildModelAdmin):
|
|||
|
||||
|
||||
@admin.register(Transaction)
|
||||
class TransactionAdmin(admin.ModelAdmin):
|
||||
class TransactionAdmin(PolymorphicParentModelAdmin):
|
||||
"""
|
||||
Admin customisation for Transaction
|
||||
"""
|
||||
child_models = (TemplateTransaction, MembershipTransaction)
|
||||
list_display = ('created_at', 'poly_source', 'poly_destination',
|
||||
'quantity', 'amount', 'transaction_type', 'valid')
|
||||
list_filter = ('transaction_type', 'valid')
|
||||
'quantity', 'amount', 'valid')
|
||||
list_filter = ('valid',)
|
||||
autocomplete_fields = (
|
||||
'source',
|
||||
'destination',
|
||||
|
@ -132,7 +134,7 @@ class TransactionAdmin(admin.ModelAdmin):
|
|||
"""
|
||||
if obj: # user is editing an existing object
|
||||
return 'created_at', 'source', 'destination', 'quantity',\
|
||||
'amount', 'transaction_type'
|
||||
'amount'
|
||||
return []
|
||||
|
||||
|
||||
|
@ -161,11 +163,3 @@ class TemplateCategoryAdmin(admin.ModelAdmin):
|
|||
"""
|
||||
list_display = ('name', )
|
||||
list_filter = ('name', )
|
||||
|
||||
@admin.register(TransactionType)
|
||||
class TransactionTypeAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for TransactionTemplate
|
||||
"""
|
||||
list_display = ('name', )
|
||||
list_filter = ('name', )
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
from dal import autocomplete
|
||||
from django import forms
|
||||
|
||||
from .models import Transaction, TransactionTemplate
|
||||
from .models import Transaction, TransactionTemplate, TemplateTransaction
|
||||
|
||||
|
||||
class TransactionTemplateForm(forms.ModelForm):
|
||||
|
@ -71,12 +71,13 @@ class ConsoForm(forms.ModelForm):
|
|||
name=self.data['button']).get()
|
||||
self.instance.destination = button.destination
|
||||
self.instance.amount = button.amount
|
||||
self.instance.transaction_type = 'bouton'
|
||||
self.instance.reason = button.name
|
||||
self.instance.reason = '{} ({})'.format(button.name, button.category)
|
||||
self.instance.name = button.name
|
||||
self.instance.category = button.category
|
||||
super().save(commit)
|
||||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
model = TemplateTransaction
|
||||
fields = ('source', )
|
||||
|
||||
# Le champ d'utilisateur est remplacé par un champ d'auto-complétion.
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .transactions import MembershipTransaction, Transaction, \
|
||||
TemplateCategory, TransactionTemplate, TransactionType
|
||||
TemplateCategory, TransactionTemplate, TemplateTransaction
|
||||
|
||||
__all__ = [
|
||||
# Notes
|
||||
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
|
||||
# Transactions
|
||||
'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate','TransactionType',
|
||||
'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate',
|
||||
'TemplateTransaction',
|
||||
]
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.db import models
|
|||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.urls import reverse
|
||||
from polymorphic.models import PolymorphicModel
|
||||
|
||||
from .notes import Note, NoteClub
|
||||
|
||||
|
@ -77,27 +78,7 @@ class TransactionTemplate(models.Model):
|
|||
return reverse('note:template_update', args=(self.pk, ))
|
||||
|
||||
|
||||
class TransactionType(models.Model):
|
||||
"""
|
||||
Defined a recurrent transaction category
|
||||
|
||||
Example: food, softs, ...
|
||||
"""
|
||||
name = models.CharField(
|
||||
verbose_name=_("name"),
|
||||
max_length=31,
|
||||
unique=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("transaction type")
|
||||
verbose_name_plural = _("transaction types")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
class Transaction(PolymorphicModel):
|
||||
"""
|
||||
General transaction between two :model:`note.Note`
|
||||
|
||||
|
@ -128,12 +109,6 @@ class Transaction(models.Model):
|
|||
default=1,
|
||||
)
|
||||
amount = models.PositiveIntegerField(verbose_name=_('amount'), )
|
||||
transaction_type = models.ForeignKey(
|
||||
TransactionType,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_('type'),
|
||||
max_length=31,
|
||||
)
|
||||
reason = models.CharField(
|
||||
verbose_name=_('reason'),
|
||||
max_length=255,
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.urls import reverse
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, ListView, UpdateView
|
||||
|
||||
from .models import Transaction, TransactionTemplate, Alias
|
||||
from .models import Transaction, TransactionTemplate, Alias, TemplateTransaction
|
||||
from .forms import TransactionForm, TransactionTemplateForm, ConsoForm
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ class ConsoView(LoginRequiredMixin, CreateView):
|
|||
"""
|
||||
Consume
|
||||
"""
|
||||
model = Transaction
|
||||
model = TemplateTransaction
|
||||
template_name = "note/conso_form.html"
|
||||
form_class = ConsoForm
|
||||
|
||||
|
@ -152,3 +152,4 @@ class ConsoView(LoginRequiredMixin, CreateView):
|
|||
When clicking a button, reload the same page
|
||||
"""
|
||||
return reverse('note:consos')
|
||||
|
||||
|
|
Loading…
Reference in New Issue