ifixkart-backend/add_location.py
adithiyan 10bfba7d58 feat: add warranties, refunds, notifications, CRM calendar, system config & delivery modules
- New models: WarrantyModel, WalletModel, SystemConfigModel
- New schemas: WarrantySchema, RefundSchema, SystemConfig, CrmTaskCalendar, NotificationTemplate, NotificationGateway, RepairErp, ReviewModeration, InventoryPos, MultiDashboard, BillingFinance
- New services: WarrantyService, RefundService, CrmService, CrmTaskCalendarService, DeliveryService, EmailTemplateService, InventoryPosService, MultiDashboardService, NotificationGatewayService, RepairErpService, ReviewModerationService, SystemConfigService, TemplateService, CreditService
- Updated routers: AdminOrder, BillingFinance, Cart, Catalog, Checkout, Crm, InventoryPos, NotificationGateway, RolePermission, ServiceJob, Settings, Storefront, UserCreation
- Updated models: Inventory, Notification, Order, Product, Service, Setting, SystemConfig, User
- Updated core: database init, invoice generator, main app
- Added WarrantyRouter with full CRUD and claim flow
2026-10-13 22:05:16 +05:30

61 lines
1.8 KiB
Python

import os
import sys
# Set path and environment variables to allow imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ['PYTHONPATH'] = os.path.dirname(os.path.abspath(__file__))
from app.core.database.db_session import engine_crm, SessionLocal
from app.models.SystemConfigModel import CrmLocation, Base
from sqlalchemy import text
# Create tables in CRM database just in case
# Base.metadata.create_all(bind=engine_crm)
db = SessionLocal()
try:
# Check if table exists (raw SQL)
try:
db.execute(text("SELECT 1 FROM crm_locations LIMIT 1"))
except Exception as e:
print("Table crm_locations does not exist or error:", e)
# Create it manually if SQLAlchemy missed it
db.execute(text("""
CREATE TABLE IF NOT EXISTS crm_locations (
location_id VARCHAR(50) PRIMARY KEY,
tenant_id VARCHAR(50),
code VARCHAR(20),
name VARCHAR(100),
address VARCHAR(255),
city VARCHAR(100),
state VARCHAR(100),
pincode VARCHAR(20),
phone VARCHAR(20),
is_active BOOLEAN,
is_primary BOOLEAN,
created_at DATETIME
)
"""))
db.commit()
locations = db.query(CrmLocation).all()
if not locations:
loc1 = CrmLocation(
location_id="loc_1",
tenant_id="tenant_1",
code="HQ01",
name="Headquarters",
city="Bangalore",
is_active=True,
is_primary=True
)
db.add(loc1)
db.commit()
print("Added default location.")
else:
print("Locations already exist:", [l.name for l in locations])
except Exception as e:
print("Error:", e)
finally:
db.close()