Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand
from product.models import ProductCategory, Product, SupplierProduct
from warehouse.models import Warehouse, WarehouseInventory, InventoryTransaction
from warehouse.models import Warehouse, WarehouseInventory, InventoryTransaction, WarehouseSupplier
from decimal import Decimal
from django.utils import timezone
import random
Expand All @@ -13,12 +13,13 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs):
self.stdout.write("🧹 Deleting existing data...")

InventoryTransaction.objects.all().delete()
WarehouseInventory.objects.all().delete()
SupplierProduct.objects.all().delete()
Product.objects.all().delete()
ProductCategory.objects.all().delete()
Warehouse.objects.all().delete()
# InventoryTransaction.objects.all().delete()
# WarehouseInventory.objects.all().delete()
# SupplierProduct.objects.all().delete()
# Product.objects.all().delete()
# ProductCategory.objects.all().delete()
# WarehouseSupplier.objects.all().delete()
# Warehouse.objects.all().delete()

self.stdout.write("🧪 Populating new data...")

Expand All @@ -34,7 +35,7 @@ def handle(self, *args, **kwargs):

# Products
products = []
for i in range(10): # more products
for i in range(10):
category = random.choice(categories)
product = Product.objects.create(
product_SKU=f"SKU{i + 1:03}",
Expand All @@ -44,7 +45,7 @@ def handle(self, *args, **kwargs):
)
products.append(product)

# Warehouses
# Warehouses (Randomly assigning warehouses to suppliers)
warehouse_data = [
("Colombo Central", "6.9271° N", "79.8612° E"),
("Kandy Depot", "7.2906° N", "80.6337° E"),
Expand All @@ -56,39 +57,52 @@ def handle(self, *args, **kwargs):
warehouse_name=name,
location_x=x,
location_y=y,
capacity=Decimal("1000000.00")
capacity=Decimal("100000000.00")
)
warehouses.append(warehouse)

# SupplierProduct, WarehouseInventory, and InventoryTransaction
# SupplierProduct, WarehouseInventory, InventoryTransaction, WarehouseSupplier
created_pairs = set()

for product in products:
for supplier_id in [101, 102, 103]:
# SupplierProduct
max_capacity = random.randint(300000, 600000)
lead_time = random.randint(3, 10)
SupplierProduct.objects.create(
supplier_id=supplier_id,
product=product,
maximum_capacity=max_capacity,
supplier_price=round(random.uniform(80, 1500), 2),
lead_time_days=lead_time
)
# Randomly assign suppliers (not for all suppliers)
suppliers = random.sample([101, 102, 103], k=random.randint(1, 3)) # Randomly pick 1 to 3 suppliers
for supplier_id in suppliers:
# SupplierProduct (Randomly create it for some suppliers)
if random.choice([True, False]):
max_capacity = random.randint(300000, 600000)
lead_time = random.randint(3, 10)
SupplierProduct.objects.create(
supplier_id=supplier_id,
product=product,
maximum_capacity=max_capacity,
supplier_price=round(random.uniform(80, 1500), 2),
lead_time_days=lead_time
)

# WarehouseSupplier (Randomly assign warehouses for this supplier)
warehouse = random.choice(warehouses) # Randomly pick one warehouse for this supplier
if (warehouse.id, supplier_id) not in created_pairs:
WarehouseSupplier.objects.create(
warehouse=warehouse,
supplier_id=supplier_id
)
created_pairs.add((warehouse.id, supplier_id))

# For each warehouse, create inventory & transactions
for warehouse in warehouses:
# Inventory - ensure unique product_id and warehouse_id combination
if not WarehouseInventory.objects.filter(warehouse=warehouse, product=product).exists():
quantity = Decimal(random.uniform(100000, 400000))
last_restocked = timezone.now() - timedelta(days=random.randint(1, 60))

inventory = WarehouseInventory.objects.create(
warehouse=warehouse,
product=product,
supplier_id=supplier_id,
quantity=quantity,
last_restocked=last_restocked,
minimum_stock_level=Decimal("100000.00")
)

# Create 1-2 incoming and 1 outgoing transactions per inventory
# Transactions
for _ in range(random.randint(1, 2)):
qty_in = Decimal(random.uniform(10000, 50000))
InventoryTransaction.objects.create(
Expand All @@ -111,4 +125,4 @@ def handle(self, *args, **kwargs):
created_by="System"
)

self.stdout.write(self.style.SUCCESS("✅ Successfully seeded all data including inventory and transactions!"))
self.stdout.write(self.style.SUCCESS("✅ Successfully seeded all data!!!"))
9 changes: 7 additions & 2 deletions warehouse_managment/warehouse/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from django.contrib import admin
from .models import Warehouse, WarehouseInventory, InventoryTransaction
from .models import Warehouse, WarehouseInventory, InventoryTransaction, WarehouseSupplier

@admin.register(Warehouse)
class WarehouseAdmin(admin.ModelAdmin):
list_display = ('id', 'warehouse_name', 'location_x', 'location_y', 'created_at')

@admin.register(WarehouseInventory)
class WarehouseInventoryAdmin(admin.ModelAdmin):
list_display = ('id', 'warehouse', 'product', 'supplier_id', 'quantity', 'last_restocked', 'minimum_stock_level')
list_display = ('id', 'warehouse', 'product', 'quantity', 'last_restocked', 'minimum_stock_level')
list_filter = ('warehouse', 'product')

@admin.register(InventoryTransaction)
class InventoryTransactionAdmin(admin.ModelAdmin):
list_display = ('id', 'inventory', 'transaction_type', 'quantity_change', 'created_at', 'created_by')
list_filter = ('transaction_type', 'created_by')

@admin.register(WarehouseSupplier)
class WarehouseSupplierAdmin(admin.ModelAdmin):
list_display = ('id', 'warehouse', 'supplier_id')
list_filter = ('warehouse',)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 5.2 on 2025-05-08 19:48

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('warehouse', '0002_warehouse_capacity'),
]

operations = [
migrations.RemoveField(
model_name='warehouseinventory',
name='supplier_id',
),
migrations.CreateModel(
name='WarehouseSupplier',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('supplier_id', models.IntegerField()),
('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='warehouse.warehouse')),
],
options={
'db_table': 'warehouse_supplier',
'unique_together': {('warehouse', 'supplier_id')},
},
),
]
11 changes: 8 additions & 3 deletions warehouse_managment/warehouse/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.db import models

from django.db import models
from product.models import Product

Expand All @@ -16,7 +14,6 @@ class Meta:
class WarehouseInventory(models.Model):
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
supplier_id = models.IntegerField()
quantity = models.DecimalField(max_digits=10, decimal_places=2)
last_restocked = models.DateTimeField(blank=True, null=True)
minimum_stock_level = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
Expand Down Expand Up @@ -49,3 +46,11 @@ class InventoryTransaction(models.Model):
class Meta:
db_table = 'inventory_transactions'

class WarehouseSupplier(models.Model):
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
supplier_id = models.IntegerField()

class Meta:
db_table = 'warehouse_supplier'
unique_together = (('warehouse', 'supplier_id'),)

7 changes: 6 additions & 1 deletion warehouse_managment/warehouse/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from .models import Warehouse, WarehouseInventory, InventoryTransaction
from .models import Warehouse, WarehouseInventory, InventoryTransaction, WarehouseSupplier

class WarehouseSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -15,3 +15,8 @@ class InventoryTransactionSerializer(serializers.ModelSerializer):
class Meta:
model = InventoryTransaction
fields = '__all__'

class WarehouseSupplierSerializer(serializers.ModelSerializer):
class Meta:
model = WarehouseSupplier
fields = ['id', 'name', 'location']
10 changes: 10 additions & 0 deletions warehouse_managment/warehouse/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
supplier_dashboard,
get_suppliers_by_category,
warehouse_inventory_list,
order_inventory_summary,
handle_order_status,
)

urlpatterns = [
Expand Down Expand Up @@ -34,4 +36,12 @@

# GET suppliers by category
path('suppliers-by-category', get_suppliers_by_category, name='suppliers-by-category'),

# GET Product counts and names by orders
path('order-inventory-summary/', order_inventory_summary),

# POST endpoint to accept or reject an order request and update inventory
path('order/handle/', handle_order_status, name='handle_order_status'),
]


22 changes: 22 additions & 0 deletions warehouse_managment/warehouse/utils/flower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from turtle import *

Copilot AI May 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Wildcard imports can reduce code clarity and potentially lead to name collisions. Consider importing only the specific functions needed.

Suggested change
from turtle import *
from turtle import speed, bgcolor, color, rt, circle, lt, down

Copilot uses AI. Check for mistakes.
import colorsys

speed(10000)
bgcolor("black")
h = 0

for i in range(16):
for j in range(18):
c = colorsys.hsv_to_rgb(h, 1, 1)
color(c)
h += 0.005
rt(90)
circle(150 - j * 6, 90)
lt(90)
circle(150 - j * 6, 90)
rt(180)
circle(40, 24)
down()


# Run separately - DDRMin
23 changes: 23 additions & 0 deletions warehouse_managment/warehouse/utils/mock_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ORDERS = [
{
"order_id": "ORD001",
"products": [
{"product_id": 1, "product_count": 100},
{"product_id": 3, "product_count": 50}
]
},
{
"order_id": "ORD002",
"products": [
{"product_id": 5, "product_count": 200}
]
},
{
"order_id": "ORD003",
"products": [
{"product_id": 2, "product_count": 150},
{"product_id": 1, "product_count": 60},
{"product_id": 6, "product_count": 30}
]
}
]
10 changes: 10 additions & 0 deletions warehouse_managment/warehouse/utils/order_accept_Req.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ORDER_REQUEST = {
"warehouse_id": 1,
"order_id": "ORD109",
"status": "accepted", # or "rejected"
"products": [
{"product_name": "Chili Product 1", "product_count": 4460},
{"product_name": "Cinnamon Product 2", "product_count": 68},
{"product_name": "Chili Product 5", "product_count": 81},
]
}
Loading
Loading