Merge branch 'import_nk15' of gitlab.crans.org:bde/nk20 into import_nk15

This commit is contained in:
Pierre-antoine Comby 2020-02-24 18:44:10 +01:00
commit 5421943fba
5 changed files with 20 additions and 48 deletions

View File

@ -7,7 +7,8 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \
PolymorphicChildModelFilter, PolymorphicParentModelAdmin PolymorphicChildModelFilter, PolymorphicParentModelAdmin
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser 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): class AliasInlines(admin.TabularInline):
@ -97,13 +98,14 @@ class NoteUserAdmin(PolymorphicChildModelAdmin):
@admin.register(Transaction) @admin.register(Transaction)
class TransactionAdmin(admin.ModelAdmin): class TransactionAdmin(PolymorphicParentModelAdmin):
""" """
Admin customisation for Transaction Admin customisation for Transaction
""" """
child_models = (TemplateTransaction, MembershipTransaction)
list_display = ('created_at', 'poly_source', 'poly_destination', list_display = ('created_at', 'poly_source', 'poly_destination',
'quantity', 'amount', 'transaction_type', 'valid') 'quantity', 'amount', 'valid')
list_filter = ('transaction_type', 'valid') list_filter = ('valid',)
autocomplete_fields = ( autocomplete_fields = (
'source', 'source',
'destination', 'destination',
@ -132,7 +134,7 @@ class TransactionAdmin(admin.ModelAdmin):
""" """
if obj: # user is editing an existing object if obj: # user is editing an existing object
return 'created_at', 'source', 'destination', 'quantity',\ return 'created_at', 'source', 'destination', 'quantity',\
'amount', 'transaction_type' 'amount'
return [] return []
@ -161,11 +163,3 @@ class TemplateCategoryAdmin(admin.ModelAdmin):
""" """
list_display = ('name', ) list_display = ('name', )
list_filter = ('name', ) list_filter = ('name', )
@admin.register(TransactionType)
class TransactionTypeAdmin(admin.ModelAdmin):
"""
Admin customisation for TransactionTemplate
"""
list_display = ('name', )
list_filter = ('name', )

View File

@ -4,7 +4,7 @@
from dal import autocomplete from dal import autocomplete
from django import forms from django import forms
from .models import Transaction, TransactionTemplate from .models import Transaction, TransactionTemplate, TemplateTransaction
class TransactionTemplateForm(forms.ModelForm): class TransactionTemplateForm(forms.ModelForm):
@ -71,12 +71,13 @@ class ConsoForm(forms.ModelForm):
name=self.data['button']).get() name=self.data['button']).get()
self.instance.destination = button.destination self.instance.destination = button.destination
self.instance.amount = button.amount self.instance.amount = button.amount
self.instance.transaction_type = 'bouton' self.instance.reason = '{} ({})'.format(button.name, button.category)
self.instance.reason = button.name self.instance.name = button.name
self.instance.category = button.category
super().save(commit) super().save(commit)
class Meta: class Meta:
model = Transaction model = TemplateTransaction
fields = ('source', ) fields = ('source', )
# Le champ d'utilisateur est remplacé par un champ d'auto-complétion. # Le champ d'utilisateur est remplacé par un champ d'auto-complétion.

View File

@ -3,11 +3,12 @@
from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
from .transactions import MembershipTransaction, Transaction, \ from .transactions import MembershipTransaction, Transaction, \
TemplateCategory, TransactionTemplate, TransactionType TemplateCategory, TransactionTemplate, TemplateTransaction
__all__ = [ __all__ = [
# Notes # Notes
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
# Transactions # Transactions
'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate','TransactionType', 'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate',
'TemplateTransaction',
] ]

View File

@ -5,6 +5,7 @@ from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.urls import reverse from django.urls import reverse
from polymorphic.models import PolymorphicModel
from .notes import Note, NoteClub from .notes import Note, NoteClub
@ -77,27 +78,7 @@ class TransactionTemplate(models.Model):
return reverse('note:template_update', args=(self.pk, )) return reverse('note:template_update', args=(self.pk, ))
class TransactionType(models.Model): class Transaction(PolymorphicModel):
"""
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):
""" """
General transaction between two :model:`note.Note` General transaction between two :model:`note.Note`
@ -128,12 +109,6 @@ class Transaction(models.Model):
default=1, default=1,
) )
amount = models.PositiveIntegerField(verbose_name=_('amount'), ) amount = models.PositiveIntegerField(verbose_name=_('amount'), )
transaction_type = models.ForeignKey(
TransactionType,
on_delete=models.PROTECT,
verbose_name=_('type'),
max_length=31,
)
reason = models.CharField( reason = models.CharField(
verbose_name=_('reason'), verbose_name=_('reason'),
max_length=255, max_length=255,

View File

@ -8,7 +8,7 @@ from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, ListView, UpdateView 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 from .forms import TransactionForm, TransactionTemplateForm, ConsoForm
@ -129,7 +129,7 @@ class ConsoView(LoginRequiredMixin, CreateView):
""" """
Consume Consume
""" """
model = Transaction model = TemplateTransaction
template_name = "note/conso_form.html" template_name = "note/conso_form.html"
form_class = ConsoForm form_class = ConsoForm
@ -152,3 +152,4 @@ class ConsoView(LoginRequiredMixin, CreateView):
When clicking a button, reload the same page When clicking a button, reload the same page
""" """
return reverse('note:consos') return reverse('note:consos')