342 lines
12 KiB
Plaintext
342 lines
12 KiB
Plaintext
# import random
|
||
# import uuid
|
||
# from datetime import datetime, timedelta
|
||
# from decimal import Decimal
|
||
# from django.utils import timezone as django_timezone
|
||
# from django.contrib.auth import get_user_model
|
||
#
|
||
# from core.models import Tenant
|
||
# from inventory.models import InventoryItem, InventoryStock, InventoryLocation, PurchaseOrder, PurchaseOrderItem, \
|
||
# Supplier
|
||
#
|
||
# User = get_user_model()
|
||
#
|
||
# # Saudi Arabian Inventory Data
|
||
# SAUDI_MEDICAL_CATEGORIES = [
|
||
# 'Pharmaceuticals',
|
||
# 'Medical Devices',
|
||
# 'Surgical Instruments',
|
||
# 'Laboratory Supplies',
|
||
# 'PPE & Safety',
|
||
# 'IV Therapy',
|
||
# 'Emergency Supplies'
|
||
# ]
|
||
#
|
||
# SAUDI_SUPPLIERS = [
|
||
# 'Saudi Medical Supply Co.',
|
||
# 'Gulf Medical Equipment',
|
||
# 'Arabian Healthcare Supplies',
|
||
# 'Riyadh Medical Trading',
|
||
# 'Al-Dawaa Medical',
|
||
# 'Nahdi Medical Company',
|
||
# 'United Pharmaceuticals'
|
||
# ]
|
||
#
|
||
# SAUDI_CITIES = ['Riyadh', 'Jeddah', 'Dammam', 'Medina', 'Taif', 'Khobar']
|
||
#
|
||
# MEDICAL_ITEMS = [
|
||
# {'name': 'Paracetamol 500mg', 'category': 'Pharmaceuticals', 'unit': 'TAB'},
|
||
# {'name': 'Disposable Syringe 5ml', 'category': 'Medical Devices', 'unit': 'PCS'},
|
||
# {'name': 'Surgical Gloves Size M', 'category': 'PPE & Safety', 'unit': 'PAIR'},
|
||
# {'name': 'Blood Collection Tube', 'category': 'Laboratory Supplies', 'unit': 'PCS'},
|
||
# {'name': 'IV Bag Normal Saline', 'category': 'IV Therapy', 'unit': 'BAG'},
|
||
# {'name': 'Emergency Oxygen Mask', 'category': 'Emergency Supplies', 'unit': 'PCS'}
|
||
# ]
|
||
#
|
||
#
|
||
# def create_saudi_suppliers(tenants):
|
||
# """Create Saudi suppliers"""
|
||
# suppliers = []
|
||
#
|
||
# for tenant in tenants:
|
||
# print(f"Creating suppliers for {tenant.name}...")
|
||
#
|
||
# for i, supplier_name in enumerate(SAUDI_SUPPLIERS):
|
||
# supplier_code = f"SUP-{tenant.id}-{i + 1:03d}"
|
||
#
|
||
# try:
|
||
# supplier = Supplier.objects.create(
|
||
# tenant=tenant,
|
||
# supplier_code=supplier_code,
|
||
# name=supplier_name,
|
||
# supplier_type='DISTRIBUTOR',
|
||
# city=random.choice(SAUDI_CITIES),
|
||
# country='Saudi Arabia',
|
||
# is_active=True
|
||
# )
|
||
# suppliers.append(supplier)
|
||
# print(f" ✓ Created supplier: {supplier_name}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating supplier {supplier_name}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(suppliers)} suppliers")
|
||
# return suppliers
|
||
#
|
||
#
|
||
# def create_saudi_inventory_locations(tenants):
|
||
# """Create Saudi inventory locations"""
|
||
# locations = []
|
||
#
|
||
# storage_rooms = ['Pharmacy', 'Central Supply', 'OR Storage', 'ICU Supply', 'Ward Storage']
|
||
#
|
||
# for tenant in tenants:
|
||
# print(f"Creating locations for {tenant.name}...")
|
||
#
|
||
# for i, room in enumerate(storage_rooms):
|
||
# location_code = f"LOC-{tenant.id}-{i + 1:03d}"
|
||
#
|
||
# try:
|
||
# location = InventoryLocation.objects.create(
|
||
# tenant=tenant,
|
||
# location_code=location_code,
|
||
# name=f"{room} - {tenant.city}",
|
||
# description=f"Storage location in {room}",
|
||
# location_type='WAREHOUSE',
|
||
# building='Main Hospital',
|
||
# floor='Ground Floor',
|
||
# room=room,
|
||
# is_active=True
|
||
# )
|
||
# locations.append(location)
|
||
# print(f" ✓ Created location: {location.name}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating location {room}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(locations)} locations")
|
||
# return locations
|
||
#
|
||
#
|
||
# def create_saudi_inventory_items(tenants):
|
||
# """Create Saudi inventory items"""
|
||
# items = []
|
||
#
|
||
# for tenant in tenants:
|
||
# print(f"Creating items for {tenant.name}...")
|
||
#
|
||
# for i, item_data in enumerate(MEDICAL_ITEMS):
|
||
# item_code = f"ITM-{tenant.id}-{i + 1:03d}"
|
||
#
|
||
# try:
|
||
# item = InventoryItem.objects.create(
|
||
# tenant=tenant,
|
||
# item_code=item_code,
|
||
# item_name=item_data['name'],
|
||
# description=f"Medical item: {item_data['name']}",
|
||
# category=item_data['category'],
|
||
# subcategory=item_data['category'],
|
||
# item_type='STOCK',
|
||
# manufacturer='Saudi Medical Industries',
|
||
# unit_of_measure=item_data['unit'],
|
||
# package_size=1,
|
||
# unit_cost=Decimal(str(random.uniform(10, 100))),
|
||
# list_price=Decimal(str(random.uniform(15, 150))),
|
||
# has_expiration=item_data['category'] == 'Pharmaceuticals',
|
||
# is_active=True,
|
||
# is_tracked=True,
|
||
# reorder_point=random.randint(10, 50),
|
||
# reorder_quantity=random.randint(100, 500),
|
||
# max_stock_level=random.randint(500, 1000)
|
||
# )
|
||
# items.append(item)
|
||
# print(f" ✓ Created item: {item.item_name}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating item {item_data['name']}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(items)} items")
|
||
# return items
|
||
#
|
||
#
|
||
# def create_saudi_inventory_stock(items, locations):
|
||
# """Create Saudi inventory stock entries"""
|
||
# stocks = []
|
||
#
|
||
# for item in items:
|
||
# print(f"Creating stock for {item.item_name}...")
|
||
#
|
||
# # Get locations for this tenant
|
||
# tenant_locations = [loc for loc in locations if loc.tenant == item.tenant]
|
||
# if not tenant_locations:
|
||
# continue
|
||
#
|
||
# location = random.choice(tenant_locations)
|
||
#
|
||
# try:
|
||
# stock = InventoryStock.objects.create(
|
||
# inventory_item=item,
|
||
# location=location,
|
||
# quantity_on_hand=random.randint(50, 500),
|
||
# quantity_reserved=random.randint(0, 20),
|
||
# received_date=django_timezone.now().date() - timedelta(days=random.randint(1, 90)),
|
||
# expiration_date=django_timezone.now().date() + timedelta(days=365) if item.has_expiration else None,
|
||
# unit_cost=item.unit_cost,
|
||
# quality_status='AVAILABLE'
|
||
# )
|
||
# stocks.append(stock)
|
||
# print(f" ✓ Created stock for: {item.item_name}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating stock for {item.item_name}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(stocks)} stock entries")
|
||
# return stocks
|
||
#
|
||
#
|
||
# def create_saudi_purchase_orders(tenants, suppliers):
|
||
# """Create Saudi purchase orders"""
|
||
# orders = []
|
||
#
|
||
# for tenant in tenants:
|
||
# print(f"Creating purchase orders for {tenant.name}...")
|
||
#
|
||
# # Get suppliers for this tenant
|
||
# tenant_suppliers = [supplier for supplier in suppliers if supplier.tenant == tenant]
|
||
# if not tenant_suppliers:
|
||
# print(f" No suppliers found for {tenant.name}, skipping...")
|
||
# continue
|
||
#
|
||
# # Get delivery locations
|
||
# try:
|
||
# locations = InventoryLocation.objects.filter(tenant=tenant)
|
||
# delivery_location = locations.first() if locations.exists() else None
|
||
# except:
|
||
# delivery_location = None
|
||
#
|
||
# for i in range(3): # Create 3 orders per tenant
|
||
# po_number = f"PO-{tenant.id}-{django_timezone.now().year}-{i + 1:04d}"
|
||
# supplier = random.choice(tenant_suppliers)
|
||
#
|
||
# try:
|
||
# order = PurchaseOrder.objects.create(
|
||
# tenant=tenant,
|
||
# po_number=po_number,
|
||
# supplier=supplier,
|
||
# order_date=django_timezone.now().date() - timedelta(days=random.randint(1, 30)),
|
||
# requested_delivery_date=django_timezone.now().date() + timedelta(days=random.randint(7, 30)),
|
||
# order_type='STANDARD',
|
||
# priority='NORMAL',
|
||
# subtotal=Decimal(str(random.uniform(1000, 10000))),
|
||
# tax_amount=Decimal('0.00'),
|
||
# shipping_amount=Decimal('0.00'),
|
||
# total_amount=Decimal(str(random.uniform(1000, 10000))),
|
||
# status='DRAFT',
|
||
# delivery_location=delivery_location,
|
||
# payment_terms='NET_30'
|
||
# )
|
||
# orders.append(order)
|
||
# print(f" ✓ Created PO: {po_number}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating PO {po_number}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(orders)} purchase orders")
|
||
# return orders
|
||
#
|
||
#
|
||
# def create_saudi_purchase_order_items(orders, items):
|
||
# """Create Saudi purchase order items"""
|
||
# po_items = []
|
||
#
|
||
# for order in orders:
|
||
# print(f"Creating items for PO {order.po_number}...")
|
||
#
|
||
# # Get items for this tenant
|
||
# tenant_items = [item for item in items if item.tenant == order.tenant]
|
||
# if not tenant_items:
|
||
# continue
|
||
#
|
||
# # Create 2-3 items per order
|
||
# num_items = min(3, len(tenant_items))
|
||
# selected_items = random.sample(tenant_items, num_items)
|
||
#
|
||
# for line_num, item in enumerate(selected_items, 1):
|
||
# quantity_ordered = random.randint(10, 100)
|
||
# unit_price = item.unit_cost * Decimal(str(random.uniform(0.9, 1.1)))
|
||
# total_price = unit_price * quantity_ordered
|
||
#
|
||
# try:
|
||
# po_item = PurchaseOrderItem.objects.create(
|
||
# purchase_order=order,
|
||
# line_number=line_num,
|
||
# inventory_item=item,
|
||
# quantity_ordered=quantity_ordered,
|
||
# quantity_received=0,
|
||
# unit_price=unit_price,
|
||
# total_price=total_price,
|
||
# requested_delivery_date=order.requested_delivery_date,
|
||
# status='PENDING'
|
||
# )
|
||
# po_items.append(po_item)
|
||
# print(f" ✓ Created PO item: {item.item_name}")
|
||
#
|
||
# except Exception as e:
|
||
# print(f" ✗ Error creating PO item for {item.item_name}: {e}")
|
||
# continue
|
||
#
|
||
# print(f"Created {len(po_items)} purchase order items")
|
||
# return po_items
|
||
#
|
||
#
|
||
# def main():
|
||
# """Main function to create all Saudi inventory data"""
|
||
# print("🏥 Starting Saudi Inventory Data Generation...")
|
||
#
|
||
# # Get tenants
|
||
# try:
|
||
# tenants = list(Tenant.objects.filter(is_active=True)[:5]) # Limit to first 5 tenants
|
||
# if not tenants:
|
||
# print("❌ No active tenants found. Please run core_data.py first.")
|
||
# return
|
||
#
|
||
# print(f"📋 Found {len(tenants)} active tenants")
|
||
# except Exception as e:
|
||
# print(f"❌ Error getting tenants: {e}")
|
||
# return
|
||
#
|
||
# # Create data step by step
|
||
# print("\n1️⃣ Creating Suppliers...")
|
||
# suppliers = create_saudi_suppliers(tenants)
|
||
# if not suppliers:
|
||
# print("❌ No suppliers created. Stopping.")
|
||
# return
|
||
#
|
||
# print("\n2️⃣ Creating Locations...")
|
||
# locations = create_saudi_inventory_locations(tenants)
|
||
# if not locations:
|
||
# print("❌ No locations created. Stopping.")
|
||
# return
|
||
#
|
||
# print("\n3️⃣ Creating Items...")
|
||
# items = create_saudi_inventory_items(tenants)
|
||
# if not items:
|
||
# print("❌ No items created. Stopping.")
|
||
# return
|
||
#
|
||
# print("\n4️⃣ Creating Stock...")
|
||
# stocks = create_saudi_inventory_stock(items, locations)
|
||
#
|
||
# print("\n5️⃣ Creating Purchase Orders...")
|
||
# orders = create_saudi_purchase_orders(tenants, suppliers)
|
||
#
|
||
# print("\n6️⃣ Creating Purchase Order Items...")
|
||
# po_items = create_saudi_purchase_order_items(orders, items)
|
||
#
|
||
# print("\n🎉 Saudi Inventory Data Generation Complete!")
|
||
# print(f"📊 Summary:")
|
||
# print(f" - Suppliers: {len(suppliers)}")
|
||
# print(f" - Locations: {len(locations)}")
|
||
# print(f" - Items: {len(items)}")
|
||
# print(f" - Stock Entries: {len(stocks)}")
|
||
# print(f" - Purchase Orders: {len(orders)}")
|
||
# print(f" - PO Items: {len(po_items)}")
|
||
#
|
||
#
|
||
# if __name__ == "__main__":
|
||
# main() |