mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
add pages to manage returnable products
This commit is contained in:
@ -15,19 +15,28 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.forms.models import modelform_factory
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import DetailView, ListView, TemplateView
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from core.auth.mixins import CanEditMixin, CanViewMixin
|
||||
from core.utils import get_semester_code, get_start_of_semester
|
||||
from counter.forms import CounterEditForm, ProductEditForm
|
||||
from counter.models import Counter, Product, ProductType, Refilling, Selling
|
||||
from counter.forms import CounterEditForm, ProductEditForm, ReturnableProductForm
|
||||
from counter.models import (
|
||||
Counter,
|
||||
Product,
|
||||
ProductType,
|
||||
Refilling,
|
||||
ReturnableProduct,
|
||||
Selling,
|
||||
)
|
||||
from counter.utils import is_logged_in_counter
|
||||
from counter.views.mixins import CounterAdminMixin, CounterAdminTabsMixin
|
||||
|
||||
@ -146,6 +155,69 @@ class ProductEditView(CounterAdminTabsMixin, CounterAdminMixin, UpdateView):
|
||||
current_tab = "products"
|
||||
|
||||
|
||||
class ReturnableProductListView(
|
||||
CounterAdminTabsMixin, PermissionRequiredMixin, ListView
|
||||
):
|
||||
model = ReturnableProduct
|
||||
queryset = model.objects.select_related("product", "returned_product")
|
||||
template_name = "counter/returnable_list.jinja"
|
||||
current_tab = "returnable_products"
|
||||
permission_required = "counter.view_returnableproduct"
|
||||
|
||||
|
||||
class ReturnableProductCreateView(
|
||||
CounterAdminTabsMixin, PermissionRequiredMixin, CreateView
|
||||
):
|
||||
form_class = ReturnableProductForm
|
||||
template_name = "core/create.jinja"
|
||||
current_tab = "returnable_products"
|
||||
success_url = reverse_lazy("counter:returnable_list")
|
||||
permission_required = "counter.add_returnableproduct"
|
||||
|
||||
|
||||
class ReturnableProductUpdateView(
|
||||
CounterAdminTabsMixin, PermissionRequiredMixin, UpdateView
|
||||
):
|
||||
model = ReturnableProduct
|
||||
pk_url_kwarg = "returnable_id"
|
||||
queryset = model.objects.select_related("product", "returned_product")
|
||||
form_class = ReturnableProductForm
|
||||
template_name = "core/edit.jinja"
|
||||
current_tab = "returnable_products"
|
||||
success_url = reverse_lazy("counter:returnable_list")
|
||||
permission_required = "counter.change_returnableproduct"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"object_name": _("returnable product : %(returnable)s -> %(returned)s")
|
||||
% {
|
||||
"returnable": self.object.product.name,
|
||||
"returned": self.object.returned_product.name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ReturnableProductDeleteView(
|
||||
CounterAdminTabsMixin, PermissionRequiredMixin, DeleteView
|
||||
):
|
||||
model = ReturnableProduct
|
||||
pk_url_kwarg = "returnable_id"
|
||||
queryset = model.objects.select_related("product", "returned_product")
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
current_tab = "returnable_products"
|
||||
success_url = reverse_lazy("counter:returnable_list")
|
||||
permission_required = "counter.delete_returnableproduct"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"object_name": _("returnable product : %(returnable)s -> %(returned)s")
|
||||
% {
|
||||
"returnable": self.object.product.name,
|
||||
"returned": self.object.returned_product.name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class RefillingDeleteView(DeleteView):
|
||||
"""Delete a refilling (for the admins)."""
|
||||
|
||||
|
@ -98,6 +98,11 @@ class CounterAdminTabsMixin(TabedViewMixin):
|
||||
"slug": "product_types",
|
||||
"name": _("Product types"),
|
||||
},
|
||||
{
|
||||
"url": reverse_lazy("counter:returnable_list"),
|
||||
"slug": "returnable_products",
|
||||
"name": _("Returnable products"),
|
||||
},
|
||||
{
|
||||
"url": reverse_lazy("counter:cash_summary_list"),
|
||||
"slug": "cash_summary",
|
||||
|
Reference in New Issue
Block a user