mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Add some tables for special transactions
This commit is contained in:
parent
2defb04d52
commit
95888ea316
@ -4,6 +4,8 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_tables2 import A
|
from django_tables2 import A
|
||||||
|
from note.models import SpecialTransaction
|
||||||
|
from note.templatetags.pretty_money import pretty_money
|
||||||
|
|
||||||
from .models import Invoice, Remittance
|
from .models import Invoice, Remittance
|
||||||
|
|
||||||
@ -33,6 +35,14 @@ class InvoiceTable(tables.Table):
|
|||||||
|
|
||||||
|
|
||||||
class RemittanceTable(tables.Table):
|
class RemittanceTable(tables.Table):
|
||||||
|
edit = tables.LinkColumn("treasury:remittance_update",
|
||||||
|
verbose_name=_("Edit"),
|
||||||
|
args=[A("pk")],
|
||||||
|
text=_("Edit"),
|
||||||
|
attrs={
|
||||||
|
'a': {'class': 'btn btn-primary'}
|
||||||
|
}, )
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
attrs = {
|
attrs = {
|
||||||
'class': 'table table-condensed table-striped table-hover'
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
@ -40,3 +50,32 @@ class RemittanceTable(tables.Table):
|
|||||||
model = Remittance
|
model = Remittance
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
fields = ('id', 'date', 'type', 'comment', 'size', 'amount', 'edit',)
|
fields = ('id', 'date', 'type', 'comment', 'size', 'amount', 'edit',)
|
||||||
|
|
||||||
|
|
||||||
|
class SpecialTransactionTable(tables.Table):
|
||||||
|
remittance_add = tables.LinkColumn("treasury:remittance_update",
|
||||||
|
verbose_name=_("Remittance"),
|
||||||
|
args=[A("pk")],
|
||||||
|
text=_("Add"),
|
||||||
|
attrs={
|
||||||
|
'a': {'class': 'btn btn-primary'}
|
||||||
|
}, )
|
||||||
|
|
||||||
|
remittance_remove = tables.LinkColumn("treasury:remittance_update",
|
||||||
|
verbose_name=_("Remittance"),
|
||||||
|
args=[A("pk")],
|
||||||
|
text=_("Remove"),
|
||||||
|
attrs={
|
||||||
|
'a': {'class': 'btn btn-primary btn-danger'}
|
||||||
|
}, )
|
||||||
|
|
||||||
|
def render_amount(self, value):
|
||||||
|
return pretty_money(value)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
|
}
|
||||||
|
model = SpecialTransaction
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
fields = ('id', 'source', 'destination', 'amount', 'last_name', 'first_name', 'bank',)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import InvoiceCreateView, InvoiceListView, InvoiceUpdateView, InvoiceRenderView, RemittanceListView,\
|
from .views import InvoiceCreateView, InvoiceListView, InvoiceUpdateView, InvoiceRenderView, RemittanceListView,\
|
||||||
RemittanceCreateView, RemittanceUpdateView
|
RemittanceCreateView, RemittanceUpdateView
|
||||||
|
|
||||||
app_name = 'treasury'
|
app_name = 'treasury'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -13,13 +13,14 @@ from django.http import HttpResponse
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.views.generic import CreateView, UpdateView
|
from django.views.generic import CreateView, UpdateView
|
||||||
from django.views.generic.base import View
|
from django.views.generic.base import View, TemplateView
|
||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
|
from note.models import SpecialTransaction
|
||||||
from note_kfet.settings.base import BASE_DIR
|
from note_kfet.settings.base import BASE_DIR
|
||||||
|
|
||||||
from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper, RemittanceForm
|
from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper, RemittanceForm
|
||||||
from .models import Invoice, Product, Remittance
|
from .models import Invoice, Product, Remittance
|
||||||
from .tables import InvoiceTable, RemittanceTable
|
from .tables import InvoiceTable, RemittanceTable, SpecialTransactionTable
|
||||||
|
|
||||||
|
|
||||||
class InvoiceCreateView(LoginRequiredMixin, CreateView):
|
class InvoiceCreateView(LoginRequiredMixin, CreateView):
|
||||||
@ -188,13 +189,36 @@ class RemittanceCreateView(LoginRequiredMixin, CreateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy('treasury:remittance_list')
|
return reverse_lazy('treasury:remittance_list')
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
class RemittanceListView(LoginRequiredMixin, SingleTableView):
|
ctx["table"] = RemittanceTable(data=Remittance.objects.all())
|
||||||
|
ctx["special_transactions"] = SpecialTransactionTable(data=SpecialTransaction.objects.none())
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
|
class RemittanceListView(LoginRequiredMixin, TemplateView):
|
||||||
"""
|
"""
|
||||||
List existing Remittances
|
List existing Remittances
|
||||||
"""
|
"""
|
||||||
model = Remittance
|
template_name = "treasury/remittance_list.html"
|
||||||
table_class = RemittanceTable
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
ctx["opened_remittances"] = RemittanceTable(data=Remittance.objects.filter(closed=False).all())
|
||||||
|
ctx["closed_remittances"] = RemittanceTable(data=Remittance.objects.filter(closed=True).reverse().all())
|
||||||
|
ctx["special_transactions_no_remittance"] = SpecialTransactionTable(
|
||||||
|
data=SpecialTransaction.objects.filter(source__polymorphic_ctype__model="notespecial",
|
||||||
|
specialtransactionproxy__remittance=None).all(),
|
||||||
|
exclude=('remittance_remove', ))
|
||||||
|
ctx["special_transactions_with_remittance"] = SpecialTransactionTable(
|
||||||
|
data=SpecialTransaction.objects.filter(source__polymorphic_ctype__model="notespecial",
|
||||||
|
specialtransactionproxy__remittance__closed=False).all(),
|
||||||
|
exclude=('remittance_add', ))
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
class RemittanceUpdateView(LoginRequiredMixin, UpdateView):
|
class RemittanceUpdateView(LoginRequiredMixin, UpdateView):
|
||||||
@ -206,3 +230,13 @@ class RemittanceUpdateView(LoginRequiredMixin, UpdateView):
|
|||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy('treasury:remittance_list')
|
return reverse_lazy('treasury:remittance_list')
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
ctx["table"] = RemittanceTable(data=Remittance.objects.all())
|
||||||
|
ctx["special_transactions"] = SpecialTransactionTable(
|
||||||
|
data=SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).all(),
|
||||||
|
exclude=('remittance_add', ))
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load crispy_forms_tags pretty_money %}
|
{% load crispy_forms_tags pretty_money %}
|
||||||
|
{% load render_table from django_tables2 %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p><a class="btn btn-default" href="{% url 'treasury:remittance_list' %}">{% trans "Remittances list" %}</a></p>
|
<p><a class="btn btn-default" href="{% url 'treasury:remittance_list' %}">{% trans "Remittances list" %}</a></p>
|
||||||
{% crispy form %}
|
{% crispy form %}
|
||||||
|
{% render_table special_transactions %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -3,8 +3,23 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% render_table table %}
|
<h2>{% trans "Opened remittances" %}</h2>
|
||||||
|
{% render_table opened_remittances %}
|
||||||
|
|
||||||
<a class="btn btn-primary" href="{% url 'treasury:remittance_create' %}">{% trans "New remittance" %}</a>
|
<a class="btn btn-primary" href="{% url 'treasury:remittance_create' %}">{% trans "New remittance" %}</a>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>{% trans "Transfers without remittances" %}</h2>
|
||||||
|
{% render_table special_transactions_no_remittance %}
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>{% trans "Transfers with opened remittances" %}</h2>
|
||||||
|
{% render_table special_transactions_with_remittance %}
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>{% trans "Closed remittances" %}</h2>
|
||||||
|
{% render_table closed_remittances %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user