diff --git a/apps/treasury/forms.py b/apps/treasury/forms.py index ad7e2c5c11b318386184f73844a9d637cf2d9481..3189694dc1fbbba9dbd91bc76e7548f2391861c9 100644 --- a/apps/treasury/forms.py +++ b/apps/treasury/forms.py @@ -4,9 +4,11 @@ import datetime from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit from django import forms +from django.utils.translation import gettext_lazy as _ -from .models import Invoice, Product +from .models import Invoice, Product, Remittance class InvoiceForm(forms.ModelForm): @@ -38,3 +40,14 @@ class ProductFormSetHelper(FormHelper): self.form_method = 'POST' self.form_class = 'form-inline' self.template = 'bootstrap4/table_inline_formset.html' + + +class RemittanceForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.add_input(Submit('submit', _("Submit"), attr={'class': 'btn btn-block btn-primary'})) + + class Meta: + model = Remittance + fields = ('type', 'comment', ) diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 7c634fdddf03448272a0e5fcc5dad31a539849e7..52b251576ee60d5460eb96712534c96c555fbcc9 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -1,5 +1,6 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later + from django.core.exceptions import ValidationError from django.db import models from django.db.models import Q @@ -88,7 +89,7 @@ class Product(models.Model): class Remittance(models.Model): - date = models.DateField( + date = models.DateTimeField( auto_now_add=True, verbose_name=_("Date"), ) @@ -104,6 +105,11 @@ class Remittance(models.Model): verbose_name=_("Comment"), ) + closed = models.BooleanField( + default=False, + verbose_name=_("Closed"), + ) + @property def size(self): return self.specialtransaction_set.count() diff --git a/apps/treasury/tables.py b/apps/treasury/tables.py index 5dcfbcd65070b4c9ba1e4dcd0d2f2203f67ee2be..ebc642c78f9af1b79668e4a2ea00d5ad144dd000 100644 --- a/apps/treasury/tables.py +++ b/apps/treasury/tables.py @@ -5,7 +5,7 @@ import django_tables2 as tables from django.utils.translation import gettext_lazy as _ from django_tables2 import A -from .models import Invoice +from .models import Invoice, Remittance class InvoiceTable(tables.Table): @@ -30,3 +30,13 @@ class InvoiceTable(tables.Table): model = Invoice template_name = 'django_tables2/bootstrap4.html' fields = ('id', 'name', 'object', 'acquitted', 'invoice',) + + +class RemittanceTable(tables.Table): + class Meta: + attrs = { + 'class': 'table table-condensed table-striped table-hover' + } + model = Remittance + template_name = 'django_tables2/bootstrap4.html' + fields = ('id', 'date', 'type', 'comment', 'size', 'amount', 'edit',) diff --git a/apps/treasury/urls.py b/apps/treasury/urls.py index 1afccabb5779f7e2ca1ddfcc3ff9387516a53410..029466e05c9aee0ebd5d1a3351fc3fcbd2fe93d8 100644 --- a/apps/treasury/urls.py +++ b/apps/treasury/urls.py @@ -3,12 +3,17 @@ from django.urls import path -from .views import InvoiceCreateView, InvoiceListView, InvoiceUpdateView, InvoiceRenderView +from .views import InvoiceCreateView, InvoiceListView, InvoiceUpdateView, InvoiceRenderView, RemittanceListView,\ + RemittanceCreateView, RemittanceUpdateView app_name = 'treasury' urlpatterns = [ - path('invoice/', InvoiceListView.as_view(), name='invoice'), + path('invoice/', InvoiceListView.as_view(), name='invoice_list'), path('invoice/create/', InvoiceCreateView.as_view(), name='invoice_create'), path('invoice/<int:pk>/', InvoiceUpdateView.as_view(), name='invoice_update'), path('invoice/render/<int:pk>/', InvoiceRenderView.as_view(), name='invoice_render'), + + path('remittance/', RemittanceListView.as_view(), name='remittance_list'), + path('remittance/create/', RemittanceCreateView.as_view(), name='remittance_create'), + path('remittance/<int:pk>/', RemittanceUpdateView.as_view(), name='remittance_update'), ] diff --git a/apps/treasury/views.py b/apps/treasury/views.py index 8b5446d6dd711a0a7bb2b79ef402a066e44f7ade..6f6c256c1a0be91fd1231338504f6d32286ae7e2 100644 --- a/apps/treasury/views.py +++ b/apps/treasury/views.py @@ -17,9 +17,9 @@ from django.views.generic.base import View from django_tables2 import SingleTableView from note_kfet.settings.base import BASE_DIR -from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper -from .models import Invoice, Product -from .tables import InvoiceTable +from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper, RemittanceForm +from .models import Invoice, Product, Remittance +from .tables import InvoiceTable, RemittanceTable class InvoiceCreateView(LoginRequiredMixin, CreateView): @@ -64,7 +64,7 @@ class InvoiceCreateView(LoginRequiredMixin, CreateView): return ret def get_success_url(self): - return reverse_lazy('treasury:invoice') + return reverse_lazy('treasury:invoice_list') class InvoiceListView(LoginRequiredMixin, SingleTableView): @@ -121,7 +121,7 @@ class InvoiceUpdateView(LoginRequiredMixin, UpdateView): return ret def get_success_url(self): - return reverse_lazy('treasury:invoice') + return reverse_lazy('treasury:invoice_list') class InvoiceRenderView(LoginRequiredMixin, View): @@ -176,3 +176,33 @@ class InvoiceRenderView(LoginRequiredMixin, View): shutil.rmtree(tmp_dir) return response + + +class RemittanceCreateView(LoginRequiredMixin, CreateView): + """ + Create Remittance + """ + model = Remittance + form_class = RemittanceForm + + def get_success_url(self): + return reverse_lazy('treasury:remittance_list') + + +class RemittanceListView(LoginRequiredMixin, SingleTableView): + """ + List existing Remittances + """ + model = Remittance + table_class = RemittanceTable + + +class RemittanceUpdateView(LoginRequiredMixin, UpdateView): + """ + Update Remittance + """ + model = Remittance + form_class = RemittanceForm + + def get_success_url(self): + return reverse_lazy('treasury:remittance_list') diff --git a/templates/base.html b/templates/base.html index c6bb88b36d6936b7c0daaf3860247d559f8a2a9a..384535b2acdca1998c3d99faf25d85095d3259e7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -99,7 +99,7 @@ SPDX-License-Identifier: GPL-3.0-or-later </li> {% if "treasury.invoice"|not_empty_model_change_list %} <li class="nav-item active"> - <a class="nav-link" href="{% url 'treasury:invoice' %}"><i class="fa fa-money"></i>{% trans 'Treasury' %} </a> + <a class="nav-link" href="{% url 'treasury:invoice_list' %}"><i class="fa fa-money"></i>{% trans 'Treasury' %} </a> </li> {% endif %} </ul> diff --git a/templates/treasury/invoice_form.html b/templates/treasury/invoice_form.html index 2177d0f766a933e6dba3b6c3b5c6d50d8b78badf..f6e2a10670337cf3834477613d756098ad4358ca 100644 --- a/templates/treasury/invoice_form.html +++ b/templates/treasury/invoice_form.html @@ -3,7 +3,7 @@ {% load i18n %} {% load crispy_forms_tags pretty_money %} {% block content %} - <p><a class="btn btn-default" href="{% url 'treasury:invoice' %}">{% trans "Invoices list" %}</a></p> + <p><a class="btn btn-default" href="{% url 'treasury:invoice_list' %}">{% trans "Invoices list" %}</a></p> <form method="post" action=""> {% csrf_token %} {% crispy form %} diff --git a/templates/treasury/remittance_form.html b/templates/treasury/remittance_form.html new file mode 100644 index 0000000000000000000000000000000000000000..500711363ac53866bb25f165525ae291a76fafac --- /dev/null +++ b/templates/treasury/remittance_form.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% load static %} +{% load i18n %} +{% load crispy_forms_tags pretty_money %} +{% block content %} + <p><a class="btn btn-default" href="{% url 'treasury:remittance_list' %}">{% trans "Remittances list" %}</a></p> + {% crispy form %} +{% endblock %} diff --git a/templates/treasury/remittance_list.html b/templates/treasury/remittance_list.html new file mode 100644 index 0000000000000000000000000000000000000000..e775fbaaab30be6819ce58101ac42f1d31d6dfdd --- /dev/null +++ b/templates/treasury/remittance_list.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load render_table from django_tables2 %} +{% load i18n %} +{% block content %} + +{% render_table table %} + +<a class="btn btn-primary" href="{% url 'treasury:remittance_create' %}">{% trans "New remittance" %}</a> + +{% endblock %}