
- Set up project structure and FastAPI application - Create database models with SQLAlchemy - Implement authentication with JWT - Add CRUD operations for products, inventory, categories - Implement purchase order and sales functionality - Create reporting endpoints - Set up Alembic for database migrations - Add comprehensive documentation in README.md
166 lines
4.6 KiB
Python
166 lines
4.6 KiB
Python
"""Add sample data
|
|
|
|
Revision ID: 003
|
|
Revises: 002
|
|
Create Date: 2023-08-12 00:02:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.sql import table, column
|
|
import datetime
|
|
from decimal import Decimal
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '003'
|
|
down_revision = '002'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Define tables for inserting data
|
|
category_table = table('category',
|
|
column('id', sa.Integer),
|
|
column('name', sa.String),
|
|
column('description', sa.Text)
|
|
)
|
|
|
|
product_table = table('product',
|
|
column('id', sa.Integer),
|
|
column('name', sa.String),
|
|
column('description', sa.Text),
|
|
column('sku', sa.String),
|
|
column('barcode', sa.String),
|
|
column('unit_price', sa.Numeric),
|
|
column('cost_price', sa.Numeric),
|
|
column('category_id', sa.Integer)
|
|
)
|
|
|
|
# Insert sample categories
|
|
op.bulk_insert(category_table,
|
|
[
|
|
{
|
|
'id': 1,
|
|
'name': 'Electronics',
|
|
'description': 'Electronic devices and accessories'
|
|
},
|
|
{
|
|
'id': 2,
|
|
'name': 'Office Supplies',
|
|
'description': 'Stationery and office equipment'
|
|
},
|
|
{
|
|
'id': 3,
|
|
'name': 'Furniture',
|
|
'description': 'Home and office furniture'
|
|
}
|
|
]
|
|
)
|
|
|
|
# Insert sample products
|
|
op.bulk_insert(product_table,
|
|
[
|
|
{
|
|
'id': 1,
|
|
'name': 'Laptop',
|
|
'description': 'High-performance laptop for work and gaming',
|
|
'sku': 'EL-LAP-001',
|
|
'barcode': '1234567890123',
|
|
'unit_price': 1299.99,
|
|
'cost_price': 899.99,
|
|
'category_id': 1
|
|
},
|
|
{
|
|
'id': 2,
|
|
'name': 'Wireless Mouse',
|
|
'description': 'Ergonomic wireless mouse',
|
|
'sku': 'EL-MOU-001',
|
|
'barcode': '1234567890124',
|
|
'unit_price': 29.99,
|
|
'cost_price': 12.50,
|
|
'category_id': 1
|
|
},
|
|
{
|
|
'id': 3,
|
|
'name': 'Notebook',
|
|
'description': 'Premium quality hardcover notebook',
|
|
'sku': 'OS-NOT-001',
|
|
'barcode': '2234567890123',
|
|
'unit_price': 12.99,
|
|
'cost_price': 4.75,
|
|
'category_id': 2
|
|
},
|
|
{
|
|
'id': 4,
|
|
'name': 'Desk Chair',
|
|
'description': 'Comfortable office chair with lumbar support',
|
|
'sku': 'FN-CHR-001',
|
|
'barcode': '3234567890123',
|
|
'unit_price': 199.99,
|
|
'cost_price': 89.50,
|
|
'category_id': 3
|
|
},
|
|
{
|
|
'id': 5,
|
|
'name': 'Standing Desk',
|
|
'description': 'Adjustable height standing desk',
|
|
'sku': 'FN-DSK-001',
|
|
'barcode': '3234567890124',
|
|
'unit_price': 349.99,
|
|
'cost_price': 175.00,
|
|
'category_id': 3
|
|
}
|
|
]
|
|
)
|
|
|
|
# Define inventory table
|
|
inventory_table = table('inventory',
|
|
column('id', sa.Integer),
|
|
column('product_id', sa.Integer),
|
|
column('quantity', sa.Integer),
|
|
column('location', sa.String)
|
|
)
|
|
|
|
# Insert sample inventory
|
|
op.bulk_insert(inventory_table,
|
|
[
|
|
{
|
|
'id': 1,
|
|
'product_id': 1,
|
|
'quantity': 10,
|
|
'location': 'Warehouse A'
|
|
},
|
|
{
|
|
'id': 2,
|
|
'product_id': 2,
|
|
'quantity': 50,
|
|
'location': 'Warehouse A'
|
|
},
|
|
{
|
|
'id': 3,
|
|
'product_id': 3,
|
|
'quantity': 100,
|
|
'location': 'Warehouse B'
|
|
},
|
|
{
|
|
'id': 4,
|
|
'product_id': 4,
|
|
'quantity': 20,
|
|
'location': 'Warehouse C'
|
|
},
|
|
{
|
|
'id': 5,
|
|
'product_id': 5,
|
|
'quantity': 15,
|
|
'location': 'Warehouse C'
|
|
}
|
|
]
|
|
)
|
|
|
|
|
|
def downgrade():
|
|
# Delete sample data in reverse order
|
|
op.execute("DELETE FROM inventory WHERE id IN (1, 2, 3, 4, 5)")
|
|
op.execute("DELETE FROM product WHERE id IN (1, 2, 3, 4, 5)")
|
|
op.execute("DELETE FROM category WHERE id IN (1, 2, 3)") |