mirror of
https://github.com/Sosokker/Inventory-Management-System.git
synced 2025-12-18 23:24:05 +01:00
Add context to overview and finish overview
This commit is contained in:
parent
39c259b2f0
commit
5610637301
@ -13,6 +13,16 @@ class Warehouse(models.Model):
|
||||
address = models.TextField()
|
||||
have_freeze = models.BooleanField()
|
||||
|
||||
@property
|
||||
def stock_percentage(self) -> float:
|
||||
inventories = Inventory.objects.filter(warehouse=self)
|
||||
total_stock = 0
|
||||
total_max_stock = 0
|
||||
for inventory in inventories:
|
||||
total_stock += inventory.current_stock
|
||||
total_max_stock += inventory.max_stock
|
||||
return total_stock / total_max_stock * 100
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
||||
@ -31,7 +41,7 @@ class Inventory(models.Model):
|
||||
current_stock = models.IntegerField()
|
||||
|
||||
@property
|
||||
def stock_percentage(self):
|
||||
def stock_percentage(self) -> float:
|
||||
return self.current_stock / self.max_stock * 100
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from django.urls import path, include
|
||||
from inventory.views import test
|
||||
from inventory.views import OverviewView
|
||||
|
||||
urlpatterns = [
|
||||
path('overview/', test, name='overview'),
|
||||
path('overview/', OverviewView.as_view(), name='overview'),
|
||||
]
|
||||
|
||||
21
inventory/utils.py
Normal file
21
inventory/utils.py
Normal file
@ -0,0 +1,21 @@
|
||||
from inventory.models import Inventory
|
||||
from transaction.models import Supply
|
||||
|
||||
def stock_percentage_all() -> float:
|
||||
inventories = Inventory.objects.all()
|
||||
total_stock = 0
|
||||
total_max_stock = 0
|
||||
for inventory in inventories:
|
||||
total_stock += inventory.current_stock
|
||||
total_max_stock += inventory.max_stock
|
||||
if total_max_stock == 0:
|
||||
return 0
|
||||
return total_stock / total_max_stock * 100
|
||||
|
||||
|
||||
def count_pending_supply() -> int:
|
||||
pending_count = 0
|
||||
for supply in Supply.objects.all():
|
||||
if supply.pending_status():
|
||||
pending_count += 1
|
||||
return pending_count
|
||||
@ -1,6 +1,24 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import TemplateView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from inventory.models import Warehouse
|
||||
from inventory.utils import stock_percentage_all, count_pending_supply
|
||||
from transaction.models import Customer
|
||||
|
||||
@login_required
|
||||
def test(request):
|
||||
return render(request, 'inventory/index.html')
|
||||
def Over(request):
|
||||
return render(request, 'inventory/index.html')
|
||||
|
||||
class OverviewView(TemplateView, LoginRequiredMixin):
|
||||
template_name = "inventory/overview.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['warehouse_list'] = Warehouse.objects.all()
|
||||
context['warehouse_count'] = Warehouse.objects.count()
|
||||
context['customer_count'] = Customer.objects.count()
|
||||
context['stock_percentage'] = stock_percentage_all()
|
||||
context['pending_supply'] = count_pending_supply()
|
||||
return context
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
<!-- Heading -->
|
||||
<div class="sidebar-heading">
|
||||
Interface
|
||||
Storage
|
||||
</div>
|
||||
|
||||
<!-- Nav Item - Pages Collapse Menu -->
|
||||
@ -116,18 +116,6 @@
|
||||
<!-- Divider -->
|
||||
<hr class="sidebar-divider d-none d-md-block">
|
||||
|
||||
<!-- Sidebar Toggler (Sidebar) -->
|
||||
<div class="text-center d-none d-md-inline">
|
||||
<button class="rounded-circle border-0" id="sidebarToggle"></button>
|
||||
</div>
|
||||
|
||||
<!-- Sidebar Message -->
|
||||
<div class="sidebar-card d-none d-lg-flex">
|
||||
<img class="sidebar-card-illustration mb-2" src="img/undraw_rocket.svg" alt="...">
|
||||
<p class="text-center mb-2"><strong>SB Admin Pro</strong> is packed with premium features, components, and more!</p>
|
||||
<a class="btn btn-success btn-sm" href="https://startbootstrap.com/theme/sb-admin-pro">Upgrade to Pro!</a>
|
||||
</div>
|
||||
|
||||
</ul>
|
||||
<!-- End of Sidebar -->
|
||||
|
||||
@ -220,15 +208,15 @@
|
||||
<!-- Content Row -->
|
||||
<div class="row">
|
||||
|
||||
<!-- Earnings (Monthly) Card Example -->
|
||||
<!-- Warehouse Count Card Example -->
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card border-left-primary shadow h-100 py-2">
|
||||
<div class="card-body">
|
||||
<div class="row no-gutters align-items-center">
|
||||
<div class="col mr-2">
|
||||
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
||||
Earnings (Monthly)</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">$40,000</div>
|
||||
Warehouse Count</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ warehouse_count }}</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<i class="fas fa-calendar fa-2x text-gray-300"></i>
|
||||
@ -238,15 +226,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Earnings (Monthly) Card Example -->
|
||||
<!-- Customer Count Card Example -->
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card border-left-success shadow h-100 py-2">
|
||||
<div class="card-body">
|
||||
<div class="row no-gutters align-items-center">
|
||||
<div class="col mr-2">
|
||||
<div class="text-xs font-weight-bold text-success text-uppercase mb-1">
|
||||
Earnings (Annual)</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">$215,000</div>
|
||||
Customer Count</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ customer_count }}</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<i class="fas fa-dollar-sign fa-2x text-gray-300"></i>
|
||||
@ -256,22 +244,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Earnings (Monthly) Card Example -->
|
||||
<!-- Stock Level Card Example -->
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card border-left-info shadow h-100 py-2">
|
||||
<div class="card-body">
|
||||
<div class="row no-gutters align-items-center">
|
||||
<div class="col mr-2">
|
||||
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">Tasks
|
||||
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">Stock Level
|
||||
</div>
|
||||
<div class="row no-gutters align-items-center">
|
||||
<div class="col-auto">
|
||||
<div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">50%</div>
|
||||
<div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">{{ stock_percentage }}%</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="progress progress-sm mr-2">
|
||||
<div class="progress-bar bg-info" role="progressbar"
|
||||
style="width: 50%" aria-valuenow="50" aria-valuemin="0"
|
||||
style="width: {{ stock_percentage }}%" aria-valuenow="50" aria-valuemin="0"
|
||||
aria-valuemax="100"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -285,15 +273,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pending Requests Card Example -->
|
||||
<!-- Pending Supply Card Example -->
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card border-left-warning shadow h-100 py-2">
|
||||
<div class="card-body">
|
||||
<div class="row no-gutters align-items-center">
|
||||
<div class="col mr-2">
|
||||
<div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
|
||||
Pending Requests</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">18</div>
|
||||
Pending Supply</div>
|
||||
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ pending_supply }}</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<i class="fas fa-comments fa-2x text-gray-300"></i>
|
||||
@ -315,26 +303,18 @@
|
||||
<h6 class="m-0 font-weight-bold text-primary">Warehouse Stock Level</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h4 class="small font-weight-bold">Server Migration <span class="float-right">20%</span></h4>
|
||||
<div class="progress mb-4">
|
||||
<div class="progress-bar bg-danger" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<h4 class="small font-weight-bold">Sales Tracking <span class="float-right">40%</span></h4>
|
||||
<div class="progress mb-4">
|
||||
<div class="progress-bar bg-warning" role="progressbar" style="width: 40%" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<h4 class="small font-weight-bold">Customer Database <span class="float-right">60%</span></h4>
|
||||
<div class="progress mb-4">
|
||||
<div class="progress-bar" role="progressbar" style="width: 60%" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<h4 class="small font-weight-bold">Payout Details <span class="float-right">80%</span></h4>
|
||||
<div class="progress mb-4">
|
||||
<div class="progress-bar bg-info" role="progressbar" style="width: 80%" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<h4 class="small font-weight-bold">Account Setup <span class="float-right">Complete!</span></h4>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
{% if warehouse_list|length != 0 %}
|
||||
{% for warehouse in warehouse_list %}
|
||||
<h4 class="small font-weight-bold">Account Setup <span class="float-right">
|
||||
{% if warehouse.stock_percentage == 100 %}Complete!{% else %}{{ warehouse.stock_percentage }}%{% endif %}
|
||||
</span></h4>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<h2>No Warehouse Available!</h2>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -348,7 +328,7 @@
|
||||
<footer class="sticky-footer bg-white">
|
||||
<div class="container my-auto">
|
||||
<div class="copyright text-center my-auto">
|
||||
<span>Copyright © Your Website 2021</span>
|
||||
<a href="https://github.com/Sosokker/Inventory-Management-System"><i class="fas fa-laugh-wink"></i> Inventory Management System 2023</a>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.2.7 on 2023-11-18 17:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transaction', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='supply',
|
||||
options={'verbose_name_plural': 'Supplies'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='order',
|
||||
name='order_date',
|
||||
field=models.DateTimeField(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supply',
|
||||
name='arrive_date',
|
||||
field=models.DateTimeField(),
|
||||
),
|
||||
]
|
||||
@ -1,3 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from django.db import models
|
||||
|
||||
from inventory.models import Warehouse, Item
|
||||
@ -27,7 +29,11 @@ class Supply(models.Model):
|
||||
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)
|
||||
item = models.ForeignKey(Item, on_delete=models.CASCADE)
|
||||
quantity = models.IntegerField()
|
||||
arrive_date = models.DateField()
|
||||
arrive_date = models.DateTimeField()
|
||||
|
||||
def pending_status(self) -> bool:
|
||||
now = datetime.datetime.now()
|
||||
return self.arrive_date > now.date()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.supplier.name} - {self.item.name} - {self.quantity}"
|
||||
@ -60,7 +66,7 @@ class Order(models.Model):
|
||||
"""
|
||||
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
|
||||
item = models.ForeignKey(Item, on_delete=models.CASCADE)
|
||||
order_date = models.DateField()
|
||||
order_date = models.DateTimeField()
|
||||
quantity = models.IntegerField()
|
||||
|
||||
def __str__(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user