From 3d9102d15d03ebe65183bbfd2c78aa0cf8fc34b2 Mon Sep 17 00:00:00 2001 From: sosokker Date: Sun, 19 Nov 2023 02:30:48 +0700 Subject: [PATCH] Add warehouse table view and extract nav/footer --- inventory/models.py | 4 + inventory/urls.py | 3 +- inventory/views.py | 10 ++ templates/base.html | 3 +- templates/footer.html | 9 ++ templates/inventory/overview.html | 213 +---------------------------- templates/inventory/warehouse.html | 86 ++++++++++++ templates/nav.html | 165 ++++++++++++++++++++++ 8 files changed, 280 insertions(+), 213 deletions(-) create mode 100644 templates/footer.html create mode 100644 templates/inventory/warehouse.html create mode 100644 templates/nav.html diff --git a/inventory/models.py b/inventory/models.py index 798f639..efe2a3b 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -23,6 +23,10 @@ class Warehouse(models.Model): total_max_stock += inventory.max_stock return total_stock / total_max_stock * 100 + @property + def inventory_count(self) -> int: + return Inventory.objects.filter(warehouse=self).count() + def __str__(self): return f"{self.name}" diff --git a/inventory/urls.py b/inventory/urls.py index 6317246..9aa3dcc 100644 --- a/inventory/urls.py +++ b/inventory/urls.py @@ -1,6 +1,7 @@ from django.urls import path, include -from inventory.views import OverviewView +from inventory.views import OverviewView, WarehouseView urlpatterns = [ path('overview/', OverviewView.as_view(), name='overview'), + path('warehouse/', WarehouseView.as_view(), name='warehouse'), ] diff --git a/inventory/views.py b/inventory/views.py index 68135e4..3a72863 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1,3 +1,4 @@ +from typing import Any from django.shortcuts import render from django.views.generic import TemplateView from django.contrib.auth.mixins import LoginRequiredMixin @@ -21,4 +22,13 @@ class OverviewView(TemplateView, LoginRequiredMixin): context['customer_count'] = Customer.objects.count() context['stock_percentage'] = stock_percentage_all() context['pending_supply'] = count_pending_supply() + return context + + +class WarehouseView(TemplateView, LoginRequiredMixin): + template_name = "inventory/warehouse.html" + + def get_context_data(self, **kwargs: Any) -> dict[str, Any]: + context = super().get_context_data(**kwargs) + context['warehouse_list'] = Warehouse.objects.all() return context \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 687b1f3..e6afd71 100644 --- a/templates/base.html +++ b/templates/base.html @@ -20,5 +20,6 @@ - {% block content %}{% endblock %} + {% block content %} + {% endblock %} diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 0000000..69c0253 --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/templates/inventory/overview.html b/templates/inventory/overview.html index dda6e10..c640717 100644 --- a/templates/inventory/overview.html +++ b/templates/inventory/overview.html @@ -6,171 +6,7 @@
- - - - - -
- - -
- - - - + {% include "nav.html" %}
@@ -299,16 +135,6 @@
- - - -
@@ -320,42 +146,7 @@ - - - - - - - - - - - - - - - - - - - + {% include "footer.html" %} {% endblock content %} \ No newline at end of file diff --git a/templates/inventory/warehouse.html b/templates/inventory/warehouse.html new file mode 100644 index 0000000..bcfc2b1 --- /dev/null +++ b/templates/inventory/warehouse.html @@ -0,0 +1,86 @@ +{% extends "base.html" %} + +{% block content %} + + + +
+ + {% include "nav.html" %} + + +
+ + + +
+ + + +
+ + +

Warehouse Tables

+

Warehouse Table

+ + +
+
+
Warehouse
+
+
+
+ + + + + + + + + + + + + + + + + + + {% for warehouse in warehouse_list %} + + + + + + + {% endfor %} + +
NameAddressNumber of InventoryHave Freezer
NameAddressNumber of InventoryHave Freezer
{{ warehouse.name }}{{ warehouse.address }}{{ warehouse.inventory_count }}{{ warehouse.have_freeze }}
+
+
+
+ +
+ + +
+ + + +
+ + +
+ + + + + + + + {% include "footer.html" %} + + +{% endblock content %} \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html new file mode 100644 index 0000000..f7c80cb --- /dev/null +++ b/templates/nav.html @@ -0,0 +1,165 @@ + + + + + +
+ + +
+ + + + \ No newline at end of file