mirror of https://gitlab.crans.org/bde/nk20
Merge branch 'consos' into 'master'
Consos See merge request bde/nk20!7
This commit is contained in:
commit
9cc0731ded
|
@ -118,6 +118,9 @@ class Role(models.Model):
|
||||||
verbose_name = _('role')
|
verbose_name = _('role')
|
||||||
verbose_name_plural = _('roles')
|
verbose_name_plural = _('roles')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.name)
|
||||||
|
|
||||||
|
|
||||||
class Membership(models.Model):
|
class Membership(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -8,7 +8,7 @@ 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, TransactionTemplate
|
from .models.transactions import Transaction, TransactionCategory, TransactionTemplate
|
||||||
|
|
||||||
|
|
||||||
class AliasInlines(admin.TabularInline):
|
class AliasInlines(admin.TabularInline):
|
||||||
|
@ -146,3 +146,12 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
|
||||||
return str(obj.destination)
|
return str(obj.destination)
|
||||||
|
|
||||||
poly_destination.short_description = _('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
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from .models import TransactionTemplate
|
from .models import TransactionTemplate, Transaction
|
||||||
|
|
||||||
class TransactionTemplateForm(forms.ModelForm):
|
class TransactionTemplateForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = TransactionTemplate
|
model = TransactionTemplate
|
||||||
fields ='__all__'
|
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 .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||||
from .transactions import MembershipTransaction, Transaction, \
|
from .transactions import MembershipTransaction, Transaction, \
|
||||||
TransactionTemplate
|
TransactionCategory, TransactionTemplate
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# Notes
|
# Notes
|
||||||
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
|
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
|
||||||
# Transactions
|
# Transactions
|
||||||
'MembershipTransaction', 'Transaction', 'TransactionTemplate',
|
'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate',
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,10 +13,28 @@ from .notes import Note,NoteClub
|
||||||
Defines transactions
|
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):
|
class TransactionTemplate(models.Model):
|
||||||
"""
|
"""
|
||||||
Defined a reccurent transaction
|
Defined a recurrent transaction
|
||||||
|
|
||||||
associated to selling something (a burger, a beer, ...)
|
associated to selling something (a burger, a beer, ...)
|
||||||
"""
|
"""
|
||||||
|
@ -35,7 +53,9 @@ class TransactionTemplate(models.Model):
|
||||||
verbose_name=_('amount'),
|
verbose_name=_('amount'),
|
||||||
help_text=_('in centimes'),
|
help_text=_('in centimes'),
|
||||||
)
|
)
|
||||||
template_type = models.CharField(
|
template_type = models.ForeignKey(
|
||||||
|
TransactionCategory,
|
||||||
|
on_delete=models.PROTECT,
|
||||||
verbose_name=_('type'),
|
verbose_name=_('type'),
|
||||||
max_length=31
|
max_length=31
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,5 +11,7 @@ urlpatterns = [
|
||||||
path('transfer/', views.TransactionCreate.as_view(), name='transfer'),
|
path('transfer/', views.TransactionCreate.as_view(), name='transfer'),
|
||||||
path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'),
|
path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'),
|
||||||
path('buttons/update/<int:pk>/',views.TransactionTemplateUpdateView.as_view(),name='template_update'),
|
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
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.urls import reverse_lazy, reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
||||||
|
|
||||||
from .models import Transaction,TransactionTemplate
|
from .models import Transaction,TransactionCategory,TransactionTemplate
|
||||||
from .forms import TransactionTemplateForm
|
from .forms import TransactionTemplateForm, ConsoForm
|
||||||
|
|
||||||
class TransactionCreate(LoginRequiredMixin, CreateView):
|
class TransactionCreate(LoginRequiredMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
|
@ -45,4 +46,31 @@ class TransactionTemplateUpdateView(LoginRequiredMixin,UpdateView):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
model = TransactionTemplate
|
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'),))
|
||||||
|
|
|
@ -46,7 +46,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item active">
|
<li class="nav-item active">
|
||||||
<a class="nav-link" href="#"><i class="fa fa-coffee"></i> Consos</a>
|
<a class="nav-link" href="{% url 'note:consos' %}"><i class="fa fa-coffee"></i> Consos</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item active">
|
<li class="nav-item active">
|
||||||
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> Clubs</a>
|
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> Clubs</a>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load i18n static pretty_money %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<fieldset class="module aligned">
|
||||||
|
{% for type in template_types %}
|
||||||
|
<a href="{% url 'note:consos' template_type=type %}"><button>{{ type }}</button></a>
|
||||||
|
{% endfor %}
|
||||||
|
</fieldset>
|
||||||
|
<form method="post" onsubmit="window.onbeforeunload=null">{% csrf_token %}
|
||||||
|
{% if form.non_field_errors %}
|
||||||
|
<p class="errornote">
|
||||||
|
{% for error in form.non_field_errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
<fieldset class="module aligned">
|
||||||
|
{% for field in form %}
|
||||||
|
<div class="form-row{% if field.errors %} errors{% endif %}">
|
||||||
|
{{ field.errors }}
|
||||||
|
<div>
|
||||||
|
{{ field.label_tag }}
|
||||||
|
{% if field.is_readonly %}
|
||||||
|
<div class="readonly">{{ field.contents }}</div>
|
||||||
|
{% else %}
|
||||||
|
{{ field }}
|
||||||
|
{% endif %}
|
||||||
|
{% if field.field.help_text %}
|
||||||
|
<div class="help">{{ field.field.help_text|safe }}</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% for button in buttons %}
|
||||||
|
<button name="button" value="{{ button.name }}">{{ button.name }} ({{ button.amount | pretty_money }})</button>
|
||||||
|
{% endfor %}
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue