0% found this document useful (0 votes)
2 views10 pages

Directory Structure

The document outlines the directory structure and code for an Inventory Management System, which includes a backend built with Django and a frontend with HTML, CSS, and JavaScript. It details models for users, categories, suppliers, products, transactions, and inventory logs, along with their serializers and viewsets for API interactions. The frontend includes various pages for managing inventory-related tasks and a dashboard for user navigation.

Uploaded by

someonesa10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Directory Structure

The document outlines the directory structure and code for an Inventory Management System, which includes a backend built with Django and a frontend with HTML, CSS, and JavaScript. It details models for users, categories, suppliers, products, transactions, and inventory logs, along with their serializers and viewsets for API interactions. The frontend includes various pages for managing inventory-related tasks and a dashboard for user navigation.

Uploaded by

someonesa10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

// Directory Structure

//
// ProjectName/
// ├── backend/
// │ ├── ProjectName/
// │ ├── inventory/
// │ │ ├── __init__.py
// │ │ ├── admin.py
// │ │ ├── models.py
// │ │ ├── views.py
// │ │ ├── urls.py
// │ │ ├── serializers.py
// │ │ ├── tests.py
// │ │ └── migrations/
// │ ├── manage.py
// │ ├── requirements.txt
// │ └── db.sqlite3
// ├── frontend/
// │ ├── index.html
// │ ├── css/
// │ │ ├── styles.css
// │ │ └── bootstrap.min.css
// │ ├── js/
// │ │ ├── script.js
// │ │ └── bootstrap.bundle.min.js
// │ ├── images/
// │ └── pages/
// │ ├── dashboard.html
// │ ├── products.html
// │ ├── categories.html
// │ ├── suppliers.html
// │ ├── transactions.html
// │ ├── inventory_logs.html
// │ ├── users.html
// │ ├── reports.html
// │ ├── orders.html
// │ ├── customers.html
// │ ├── sales.html
// │ ├── purchases.html
// │ ├── returns.html
// │ ├── adjustments.html
// │ ├── stock_transfer.html
// │ ├── stock_count.html
// │ ├── damaged_goods.html
// │ ├── settings.html
// │ ├── profile.html
// │ ├── login.html
// │ ├── register.html
// │ ├── password_reset.html
// │ ├── error.html
// │ ├── access_denied.html
// │ ├── not_found.html
// │ ├── print.html
// │ ├── help.html
// │ ├── contact.html
// │ ├── about.html
// │ ├── terms.html
// │ ├── privacy.html
// │ ├── sitemap.html
// │ ├── faq.html
// │ ├── updates.html
// │ ├── backups.html
// │ ├── security.html
// │ └── performance.html
// └── README.md
//
// backend/inventory/models.py
from django.db import models
from django.utils import timezone

class User(models.Model):
ROLE_CHOICES = (
('Admin', 'Admin'),
('Staff', 'Staff'),
)

user_id = models.AutoField(primary_key=True)
username = models.CharField(max_length=50, unique=True, null=False,
blank=False)
password = models.CharField(max_length=255, null=False,
blank=False)
role = models.CharField(max_length=5, choices=ROLE_CHOICES,
default='Staff', null=False, blank=False)
email = models.EmailField(max_length=100, null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.username

class Category(models.Model):
category_id = models.AutoField(primary_key=True)
category_name = models.CharField(max_length=50, unique=True,
null=False, blank=False)
description = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.category_name

class Supplier(models.Model):
supplier_id = models.AutoField(primary_key=True)
supplier_name = models.CharField(max_length=100, null=False,
blank=False)
contact_number = models.CharField(max_length=15, null=True,
blank=True)
email = models.EmailField(max_length=100, null=True, blank=True)
address = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.supplier_name
class Product(models.Model):
product_id = models.AutoField(primary_key=True)
product_name = models.CharField(max_length=100, null=False,
blank=False)
category = models.ForeignKey(Category, on_delete=models.CASCADE,
related_name='products', null=False, blank=False)
unit_price = models.DecimalField(max_digits=10, decimal_places=2,
null=False, blank=False)
quantity_in_stock = models.IntegerField(default=0, null=False,
blank=False)
record_level = models.IntegerField(null=False, blank=False)
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE,
related_name='products', null=False, blank=False)
description = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.product_name

class Transaction(models.Model):
TRANSACTION_TYPE_CHOICES = (
('Purchase', 'Purchase'),
('Sale', 'Sale'),
('Return', 'Return'),
)

transaction_id = models.AutoField(primary_key=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE,
related_name='transactions', null=False, blank=False)
user = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='transactions', null=False, blank=False)
transaction_type = models.CharField(max_length=10,
choices=TRANSACTION_TYPE_CHOICES, null=False, blank=False)
quantity = models.IntegerField(null=False, blank=False)
transaction_date = models.DateTimeField(default=timezone.now)

def __str__(self):
return f"{self.transaction_type} - {self.product.product_name}
- {self.quantity}"

class InventoryLog(models.Model):
ACTION_CHOICES = (
('Add', 'Add'),
('Remove', 'Remove'),
('Adjust', 'Adjust'),
)

log_id = models.AutoField(primary_key=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE,
related_name='inventory_logs', null=False, blank=False)
quantity_changed = models.IntegerField(null=False, blank=False)
action = models.CharField(max_length=10, choices=ACTION_CHOICES,
null=False, blank=False)
user = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='inventory_logs', null=False, blank=False)
log_date = models.DateTimeField(default=timezone.now)

def __str__(self):
return f"{self.action} - {self.product.product_name} -
{self.quantity_changed}"

// backend/inventory/serializers.py
from rest_framework import serializers
from .models import User, Product, Category, Supplier, Transaction,
InventoryLog

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['user_id', 'username', 'role', 'email', 'created_at']
read_only_fields = ['user_id', 'created_at']

class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ['category_id', 'category_name', 'description',
'created_at']
read_only_fields = ['category_id', 'created_at']

class SupplierSerializer(serializers.ModelSerializer):
class Meta:
model = Supplier
fields = ['supplier_id', 'supplier_name', 'contact_number',
'email', 'address', 'created_at']
read_only_fields = ['supplier_id', 'created_at']

class ProductSerializer(serializers.ModelSerializer):
category = CategorySerializer(read_only=True)
supplier = SupplierSerializer(read_only=True)

class Meta:
model = Product
fields = ['product_id', 'product_name', 'category',
'unit_price', 'quantity_in_stock', 'record_level', 'supplier',
'description', 'created_at']
read_only_fields = ['product_id', 'created_at']

class TransactionSerializer(serializers.ModelSerializer):
product = ProductSerializer(read_only=True)
user = UserSerializer(read_only=True)

class Meta:
model = Transaction
fields = ['transaction_id', 'product', 'user',
'transaction_type', 'quantity', 'transaction_date']
read_only_fields = ['transaction_id', 'transaction_date']

class InventoryLogSerializer(serializers.ModelSerializer):
product = ProductSerializer(read_only=True)
user = UserSerializer(read_only=True)

class Meta:
model = InventoryLog
fields = ['log_id', 'product', 'quantity_changed', 'action',
'user', 'log_date']
read_only_fields = ['log_id', 'log_date']

// backend/inventory/views.py
from rest_framework import viewsets, permissions, status
from rest_framework.response import Response
from rest_framework.decorators import action
from .models import User, Product, Category, Supplier, Transaction,
InventoryLog
from .serializers import UserSerializer, ProductSerializer,
CategorySerializer, SupplierSerializer, TransactionSerializer,
InventoryLogSerializer
from django.contrib.auth.hashers import make_password
from rest_framework.pagination import PageNumberPagination
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters

class StandardResultsSetPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
max_page_size = 100

class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['username', 'role', 'email']
search_fields = ['username', 'email']
ordering_fields = ['username', 'created_at']

def create(self, request, *args, **kwargs):


data = request.data.copy()
password = data.get('password')
if password:
data['password'] = make_password(password)
serializer = self.get_serializer(data=data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data,
status=status.HTTP_201_CREATED, headers=headers)

def update(self, request, *args, **kwargs):


partial = kwargs.pop('partial', False)
instance = self.get_object()
data = request.data.copy()
password = data.get('password')
if password:
data['password'] = make_password(password)
serializer = self.get_serializer(instance, data=data,
partial=partial)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Response(serializer.data)

class CategoryViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['category_name']
search_fields = ['category_name', 'description']
ordering_fields = ['category_name', 'created_at']

class SupplierViewSet(viewsets.ModelViewSet):
queryset = Supplier.objects.all()
serializer_class = SupplierSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['supplier_name']
search_fields = ['supplier_name', 'email', 'contact_number']
ordering_fields = ['supplier_name', 'created_at']

class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['category', 'supplier', 'product_name']
search_fields = ['product_name', 'description']
ordering_fields = ['product_name', 'unit_price',
'quantity_in_stock', 'created_at']

class TransactionViewSet(viewsets.ModelViewSet):
queryset = Transaction.objects.all()
serializer_class = TransactionSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['product', 'user', 'transaction_type',
'transaction_date']
search_fields = ['transaction_type']
ordering_fields = ['transaction_date']

class InventoryLogViewSet(viewsets.ModelViewSet):
queryset = InventoryLog.objects.all()
serializer_class = InventoryLogSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
pagination_class = StandardResultsSetPagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter,
filters.OrderingFilter]
filterset_fields = ['product', 'user', 'action', 'log_date']
search_fields = ['action']
ordering_fields = ['log_date']

// backend/inventory/urls.py
from django.urls import include, path
from rest_framework import routers
from . import views

router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'categories', views.CategoryViewSet)
router.register(r'suppliers', views.SupplierViewSet)
router.register(r'products', views.ProductViewSet)
router.register(r'transactions', views.TransactionViewSet)
router.register(r'inventorylogs', views.InventoryLogViewSet)

urlpatterns = [
path('', include(router.urls)),
]

// ProjectName/ProjectName/urls.py
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('inventory.urls')),
]

// frontend/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Inventory Management System</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-
light sidebar collapse">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active"
href="index.html">
<span data-feather="home"></span>
Dashboard
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/products.html">
<span data-feather="file"></span>
Products
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/categories.html">
<span
data-feather="shopping-cart"></span>
Categories
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/suppliers.html">
<span data-feather="users"></span>
Suppliers
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/transactions.html">
<span data-feather="truck"></span>
Transactions
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/inventory_logs.html">
<span data-feather="list"></span>
Inventory Logs
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/users.html">
<span data-feather="users"></span>
Users
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="pages/reports.html">
<span
data-feather="bar-chart-2"></span>
Reports
</a>
</li>
</ul>
</div>
</nav>

<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-


md-4">
<div class="d-flex justify-content-between flex-wrap
flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Dashboard</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<button type="button" class="btn btn-sm
btn-outline-secondary">Share</button>
<button type="button" class="btn btn-sm
btn-outline-secondary">Export</button>
</div>
<button type="button" class="btn btn-sm btn-
outline-secondary dropdown-toggle">
<span data-feather="calendar"></span>
This week
</button>
</div>
</div>

<div class="dashboard-content">
<p>Welcome to the Inventory Management System
Dashboard.</p>
</div>
</main>
</div>
</div>
<script src="https://unpkg.com/feather-icons"></script>
<script>
feather.replace()
</script>
</body>
</html>

You might also like