mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-10-31 07:49:57 +01:00 
			
		
		
		
	Create, view and update remittances
This commit is contained in:
		| @@ -4,9 +4,11 @@ | |||||||
| import datetime | import datetime | ||||||
|  |  | ||||||
| from crispy_forms.helper import FormHelper | from crispy_forms.helper import FormHelper | ||||||
|  | from crispy_forms.layout import Submit | ||||||
| from django import forms | 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): | class InvoiceForm(forms.ModelForm): | ||||||
| @@ -38,3 +40,14 @@ class ProductFormSetHelper(FormHelper): | |||||||
|         self.form_method = 'POST' |         self.form_method = 'POST' | ||||||
|         self.form_class = 'form-inline' |         self.form_class = 'form-inline' | ||||||
|         self.template = 'bootstrap4/table_inline_formset.html' |         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', ) | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay | # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay | ||||||
| # SPDX-License-Identifier: GPL-3.0-or-later | # SPDX-License-Identifier: GPL-3.0-or-later | ||||||
|  |  | ||||||
| from django.core.exceptions import ValidationError | from django.core.exceptions import ValidationError | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.db.models import Q | from django.db.models import Q | ||||||
| @@ -88,7 +89,7 @@ class Product(models.Model): | |||||||
|  |  | ||||||
|  |  | ||||||
| class Remittance(models.Model): | class Remittance(models.Model): | ||||||
|     date = models.DateField( |     date = models.DateTimeField( | ||||||
|         auto_now_add=True, |         auto_now_add=True, | ||||||
|         verbose_name=_("Date"), |         verbose_name=_("Date"), | ||||||
|     ) |     ) | ||||||
| @@ -104,6 +105,11 @@ class Remittance(models.Model): | |||||||
|         verbose_name=_("Comment"), |         verbose_name=_("Comment"), | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     closed = models.BooleanField( | ||||||
|  |         default=False, | ||||||
|  |         verbose_name=_("Closed"), | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def size(self): |     def size(self): | ||||||
|         return self.specialtransaction_set.count() |         return self.specialtransaction_set.count() | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ 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 .models import Invoice | from .models import Invoice, Remittance | ||||||
|  |  | ||||||
|  |  | ||||||
| class InvoiceTable(tables.Table): | class InvoiceTable(tables.Table): | ||||||
| @@ -30,3 +30,13 @@ class InvoiceTable(tables.Table): | |||||||
|         model = Invoice |         model = Invoice | ||||||
|         template_name = 'django_tables2/bootstrap4.html' |         template_name = 'django_tables2/bootstrap4.html' | ||||||
|         fields = ('id', 'name', 'object', 'acquitted', 'invoice',) |         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',) | ||||||
|   | |||||||
| @@ -3,12 +3,17 @@ | |||||||
|  |  | ||||||
| from django.urls import path | 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' | app_name = 'treasury' | ||||||
| urlpatterns = [ | 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/create/', InvoiceCreateView.as_view(), name='invoice_create'), | ||||||
|     path('invoice/<int:pk>/', InvoiceUpdateView.as_view(), name='invoice_update'), |     path('invoice/<int:pk>/', InvoiceUpdateView.as_view(), name='invoice_update'), | ||||||
|     path('invoice/render/<int:pk>/', InvoiceRenderView.as_view(), name='invoice_render'), |     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'), | ||||||
| ] | ] | ||||||
|   | |||||||
| @@ -17,9 +17,9 @@ from django.views.generic.base import View | |||||||
| from django_tables2 import SingleTableView | from django_tables2 import SingleTableView | ||||||
| from note_kfet.settings.base import BASE_DIR | from note_kfet.settings.base import BASE_DIR | ||||||
|  |  | ||||||
| from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper | from .forms import InvoiceForm, ProductFormSet, ProductFormSetHelper, RemittanceForm | ||||||
| from .models import Invoice, Product | from .models import Invoice, Product, Remittance | ||||||
| from .tables import InvoiceTable | from .tables import InvoiceTable, RemittanceTable | ||||||
|  |  | ||||||
|  |  | ||||||
| class InvoiceCreateView(LoginRequiredMixin, CreateView): | class InvoiceCreateView(LoginRequiredMixin, CreateView): | ||||||
| @@ -64,7 +64,7 @@ class InvoiceCreateView(LoginRequiredMixin, CreateView): | |||||||
|         return ret |         return ret | ||||||
|  |  | ||||||
|     def get_success_url(self): |     def get_success_url(self): | ||||||
|         return reverse_lazy('treasury:invoice') |         return reverse_lazy('treasury:invoice_list') | ||||||
|  |  | ||||||
|  |  | ||||||
| class InvoiceListView(LoginRequiredMixin, SingleTableView): | class InvoiceListView(LoginRequiredMixin, SingleTableView): | ||||||
| @@ -121,7 +121,7 @@ class InvoiceUpdateView(LoginRequiredMixin, UpdateView): | |||||||
|         return ret |         return ret | ||||||
|  |  | ||||||
|     def get_success_url(self): |     def get_success_url(self): | ||||||
|         return reverse_lazy('treasury:invoice') |         return reverse_lazy('treasury:invoice_list') | ||||||
|  |  | ||||||
|  |  | ||||||
| class InvoiceRenderView(LoginRequiredMixin, View): | class InvoiceRenderView(LoginRequiredMixin, View): | ||||||
| @@ -176,3 +176,33 @@ class InvoiceRenderView(LoginRequiredMixin, View): | |||||||
|             shutil.rmtree(tmp_dir) |             shutil.rmtree(tmp_dir) | ||||||
|  |  | ||||||
|         return response |         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') | ||||||
|   | |||||||
| @@ -99,7 +99,7 @@ SPDX-License-Identifier: GPL-3.0-or-later | |||||||
|                 </li> |                 </li> | ||||||
|                 {% if "treasury.invoice"|not_empty_model_change_list %} |                 {% if "treasury.invoice"|not_empty_model_change_list %} | ||||||
|                     <li class="nav-item active"> |                     <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> |                     </li> | ||||||
|                 {% endif %} |                 {% endif %} | ||||||
|             </ul> |             </ul> | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| {% load i18n %} | {% load i18n %} | ||||||
| {% load crispy_forms_tags pretty_money %} | {% load crispy_forms_tags pretty_money %} | ||||||
| {% block content %} | {% 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=""> |     <form method="post" action=""> | ||||||
|         {% csrf_token %} |         {% csrf_token %} | ||||||
|         {% crispy form %} |         {% crispy form %} | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								templates/treasury/remittance_form.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								templates/treasury/remittance_form.html
									
									
									
									
									
										Normal file
									
								
							| @@ -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 %} | ||||||
							
								
								
									
										10
									
								
								templates/treasury/remittance_list.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								templates/treasury/remittance_list.html
									
									
									
									
									
										Normal file
									
								
							| @@ -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 %} | ||||||
		Reference in New Issue
	
	Block a user