mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Consos
This commit is contained in:
@ -8,7 +8,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \
|
||||
PolymorphicChildModelFilter, PolymorphicParentModelAdmin
|
||||
|
||||
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .models.transactions import Transaction, TransactionTemplate
|
||||
from .models.transactions import Transaction, TransactionCategory, TransactionTemplate
|
||||
|
||||
|
||||
class AliasInlines(admin.TabularInline):
|
||||
@ -146,3 +146,12 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
|
||||
return str(obj.destination)
|
||||
|
||||
poly_destination.short_description = _('destination')
|
||||
|
||||
|
||||
@admin.register(TransactionCategory)
|
||||
class TransactionCategoryAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for TransactionTemplate
|
||||
"""
|
||||
list_display = ('name',)
|
||||
list_filter = ('name',)
|
||||
|
@ -1,9 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from django import forms
|
||||
from .models import TransactionTemplate
|
||||
from .models import TransactionTemplate, Transaction
|
||||
|
||||
class TransactionTemplateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = TransactionTemplate
|
||||
fields ='__all__'
|
||||
|
||||
class ConsoForm(forms.ModelForm):
|
||||
def save(self, commit=True):
|
||||
button: TransactionTemplate = TransactionTemplate.objects.filter(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
|
||||
super().save(commit)
|
||||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = ('source',)
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .transactions import MembershipTransaction, Transaction, \
|
||||
TransactionTemplate
|
||||
TransactionCategory, TransactionTemplate
|
||||
|
||||
__all__ = [
|
||||
# Notes
|
||||
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
|
||||
# Transactions
|
||||
'MembershipTransaction', 'Transaction', 'TransactionTemplate',
|
||||
'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate',
|
||||
]
|
||||
|
@ -13,10 +13,28 @@ from .notes import Note,NoteClub
|
||||
Defines transactions
|
||||
"""
|
||||
|
||||
class TransactionCategory(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 category")
|
||||
verbose_name_plural = _("transaction categories")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
class TransactionTemplate(models.Model):
|
||||
"""
|
||||
Defined a reccurent transaction
|
||||
Defined a recurrent transaction
|
||||
|
||||
associated to selling something (a burger, a beer, ...)
|
||||
"""
|
||||
@ -35,7 +53,9 @@ class TransactionTemplate(models.Model):
|
||||
verbose_name=_('amount'),
|
||||
help_text=_('in centimes'),
|
||||
)
|
||||
template_type = models.CharField(
|
||||
template_type = models.ForeignKey(
|
||||
TransactionCategory,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_('type'),
|
||||
max_length=31
|
||||
)
|
||||
|
@ -11,5 +11,7 @@ urlpatterns = [
|
||||
path('transfer/', views.TransactionCreate.as_view(), name='transfer'),
|
||||
path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'),
|
||||
path('buttons/update/<int:pk>/',views.TransactionTemplateUpdateView.as_view(),name='template_update'),
|
||||
path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list')
|
||||
path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list'),
|
||||
path('consos/<str:template_type>/',views.ConsoView.as_view(),name='consos'),
|
||||
path('consos/',views.ConsoView.as_view(),name='consos'),
|
||||
]
|
||||
|
@ -3,11 +3,12 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
||||
|
||||
from .models import Transaction,TransactionTemplate
|
||||
from .forms import TransactionTemplateForm
|
||||
from .models import Transaction,TransactionCategory,TransactionTemplate
|
||||
from .forms import TransactionTemplateForm, ConsoForm
|
||||
|
||||
class TransactionCreate(LoginRequiredMixin, CreateView):
|
||||
"""
|
||||
@ -45,4 +46,31 @@ class TransactionTemplateUpdateView(LoginRequiredMixin,UpdateView):
|
||||
"""
|
||||
"""
|
||||
model = TransactionTemplate
|
||||
form_class=TransactionTemplateForm
|
||||
form_class = TransactionTemplateForm
|
||||
|
||||
class ConsoView(LoginRequiredMixin,CreateView):
|
||||
"""
|
||||
Consume
|
||||
"""
|
||||
model = Transaction
|
||||
template_name = "note/conso_form.html"
|
||||
form_class = ConsoForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
Add some context variables in template such as page title
|
||||
"""
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['template_types'] = TransactionCategory.objects.all()
|
||||
|
||||
if 'template_type' not in self.kwargs.keys():
|
||||
return context
|
||||
|
||||
template_type = TransactionCategory.objects.filter(name=self.kwargs.get('template_type')).get()
|
||||
context['buttons'] = TransactionTemplate.objects.filter(template_type=template_type)
|
||||
context['title'] = template_type
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('note:consos',args=(self.kwargs.get('template_type'),))
|
||||
|
Reference in New Issue
Block a user