- 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
88 lines
3.4 KiB
Python
88 lines
3.4 KiB
Python
import ulid
|
|
from sqlalchemy import select
|
|
import app.models.db_base
|
|
from app.core.database.db_session import engine_commerce, SessionLocal, Base
|
|
from app.models.WalletModel import CustomerWallet, WalletTransaction
|
|
from app.models.SettingModel import Setting
|
|
|
|
def run_migration():
|
|
print("Creating wallet tables in Commerce DB...")
|
|
Base.metadata.create_all(bind=engine_commerce, tables=[CustomerWallet.__table__, WalletTransaction.__table__])
|
|
print("Wallet tables created/verified.")
|
|
|
|
print("Seeding/Verifying credit settings...")
|
|
db = SessionLocal()
|
|
try:
|
|
credit_settings = [
|
|
{
|
|
"setting_key": "credits_enabled",
|
|
"setting_value": {"value": True},
|
|
"description": "Master switch to enable/disable store credit rewards",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_sales_percentage",
|
|
"setting_value": {"value": 5.0},
|
|
"description": "Store credit percentage earned on e-commerce sales orders",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_sales_return_window_days",
|
|
"setting_value": {"value": 7},
|
|
"description": "Return window period in days before sales credit matures",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_service_percentage",
|
|
"setting_value": {"value": 5.0},
|
|
"description": "Store credit percentage earned on completed repair service jobs",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_service_claim_window_days",
|
|
"setting_value": {"value": 3},
|
|
"description": "Return/dispute window period in days before service credit matures",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_minimum_order_value",
|
|
"setting_value": {"value": 0.0},
|
|
"description": "Minimum order/invoice amount required to earn credit",
|
|
"is_public": True,
|
|
},
|
|
{
|
|
"setting_key": "credits_expiry_days",
|
|
"setting_value": {"value": 365},
|
|
"description": "Days before matured credits expire (0 for no expiration)",
|
|
"is_public": True,
|
|
},
|
|
]
|
|
|
|
for s in credit_settings:
|
|
existing = db.execute(
|
|
select(Setting).where(Setting.setting_key == s["setting_key"])
|
|
).scalar_one_or_none()
|
|
if not existing:
|
|
db.add(Setting(
|
|
setting_id=str(ulid.ULID()),
|
|
setting_key=s["setting_key"],
|
|
group="credits",
|
|
type="json",
|
|
setting_value=s["setting_value"],
|
|
description=s["description"],
|
|
is_public=s["is_public"],
|
|
))
|
|
print(f" + Added Setting: {s['setting_key']}")
|
|
else:
|
|
print(f" = Setting exists: {s['setting_key']}")
|
|
db.commit()
|
|
print("Credit settings successfully synchronized.")
|
|
except Exception as e:
|
|
db.rollback()
|
|
print(f"Error during credit settings synchronization: {e}")
|
|
raise
|
|
finally:
|
|
db.close()
|
|
|
|
if __name__ == "__main__":
|
|
run_migration()
|