diff --git a/core/urls.py b/core/urls.py index aa3549b..33901f0 100644 --- a/core/urls.py +++ b/core/urls.py @@ -4,7 +4,8 @@ from django.views.generic.base import RedirectView urlpatterns = [ path('admin/', admin.site.urls), - path("accounts/", include("django.contrib.auth.urls")), # new + path("accounts/", include("django.contrib.auth.urls")), path('', include('inventory.urls'), name='dashboard'), + path('', include('transaction.urls'), name='transaction'), path('', RedirectView.as_view(url='/overview/')), ] diff --git a/templates/nav.html b/templates/nav.html index 31a63aa..887d1d6 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -43,17 +43,9 @@ Storage Manage - - - diff --git a/templates/transaction/order_filter.html b/templates/transaction/order_filter.html new file mode 100644 index 0000000..760cb3c --- /dev/null +++ b/templates/transaction/order_filter.html @@ -0,0 +1,128 @@ +{% extends "base.html" %} + +{% block content %} + + + +
+ + {% include "nav.html" %} + + +
+ + + +
+ + + +
+ + +

{{ warehouse_name }}

+

Order Listing

+ +
+ + +
Filter
+
+ +
+
+ {{ filter.form.as_p }} +
+ +
+ +
+
+
+ + + + + + +
+
+
Order
+
+
+
+ + + + + + + + + + + + + + + + + + + + + {% if filter.is_bound %} + {% for order in filter.qs %} + + {% comment %} {% endcomment %} + + + + + + + {% endfor %} + {% else %} + {% for order in order_list %} + + {% comment %} {% endcomment %} + + + + + + + {% endfor %} + {% endif %} + +
IDCustomerItemOrder DateQuantity
IDCustomerItemOrder DateQuantity
{{ inventory.stock_identifier }}{{ order.id }}{{ order.customer }}{{ order.item }}{{ order.order_date }}{{ order.quantity }}
{{ inventory.stock_identifier }}{{ order.id }}{{ order.customer }}{{ order.item }}{{ order.order_date }}{{ order.quantity }}
+
+
+
+ +
+ + +
+ + + +
+ + +
+ + + + + + + + {% include "footer.html" %} + + +{% endblock content %} \ No newline at end of file diff --git a/transaction/filters.py b/transaction/filters.py new file mode 100644 index 0000000..a7b0f17 --- /dev/null +++ b/transaction/filters.py @@ -0,0 +1,12 @@ +from django import forms +import django_filters +from transaction.models import Order + +class OrderFilter(django_filters.FilterSet): + customer_name = django_filters.CharFilter(field_name='customer__name', lookup_expr='icontains', label='Customer Name') + item_name = django_filters.CharFilter(field_name='item__name', lookup_expr='icontains', label='Item Name') + order_date = django_filters.DateFilter(field_name='order_date', label='Order Date (YYYY-MM-DD)', widget=forms.DateInput(attrs={'type': 'date'})) + + class Meta: + model = Order + fields = ['customer_name', 'item_name', 'order_date'] diff --git a/transaction/urls.py b/transaction/urls.py new file mode 100644 index 0000000..4c17f3c --- /dev/null +++ b/transaction/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from transaction.views import CustomerOrderView + +urlpatterns = [ + path('order/', CustomerOrderView.as_view(), name='customer-order'), +] diff --git a/transaction/views.py b/transaction/views.py index 91ea44a..23e9d1f 100644 --- a/transaction/views.py +++ b/transaction/views.py @@ -1,3 +1,19 @@ -from django.shortcuts import render +from django_filters.views import FilterView +from django.contrib.auth.mixins import LoginRequiredMixin +from transaction.models import Order, Customer +from transaction.filters import OrderFilter -# Create your views here. +class CustomerOrderView(FilterView, LoginRequiredMixin): + template_name = 'transaction/order_filter.html' + model = Order + filterset_class = OrderFilter + context_object_name = 'orders' + + def get_queryset(self): + queryset = super().get_queryset() + return queryset.filter(customer__isnull=False) # Exclude orders without a customer + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['customers'] = Customer.objects.all() + return context \ No newline at end of file