- 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
115 lines
3 KiB
Python
115 lines
3 KiB
Python
import sys
|
|
import os
|
|
import ulid
|
|
import requests
|
|
import json
|
|
|
|
sys.path.insert(0, os.path.abspath('/mnt/fam/SERVER/IfixKartEcommerce/Backend'))
|
|
from app.models.db_base import *
|
|
from app.core.database.db_session import SessionLocal
|
|
from app.models.ProductModel import Product, ProductVariant
|
|
from app.models.UserModel import User
|
|
from app.core.Token import create_access_token
|
|
|
|
db = SessionLocal()
|
|
|
|
admin = db.query(User).filter(User.role_id == "ROLE_ADMIN").first()
|
|
if not admin:
|
|
admin = db.query(User).first() # Just grab any user to test
|
|
|
|
if not admin:
|
|
print("NO USER FOUND IN DB")
|
|
sys.exit(1)
|
|
|
|
token = create_access_token(user_id=admin.user_id, email=admin.email, role="ROLE_ADMIN")
|
|
|
|
# 1. Get Product Variant
|
|
variant = db.query(ProductVariant).first()
|
|
if not variant:
|
|
product = Product(
|
|
product_id=str(ulid.ULID()),
|
|
tenant_id="tenant_default",
|
|
name="Test API Product",
|
|
slug="test-api-product",
|
|
description="Test",
|
|
category_id=None,
|
|
status="ACTIVE"
|
|
)
|
|
db.add(product)
|
|
|
|
variant = ProductVariant(
|
|
variant_id=str(ulid.ULID()),
|
|
product_id=product.product_id,
|
|
sku="TEST-SKU-API",
|
|
price=100.0,
|
|
stock_quantity=10,
|
|
attributes_json="{}"
|
|
)
|
|
db.add(variant)
|
|
db.commit()
|
|
|
|
variant_id = variant.variant_id
|
|
db.close()
|
|
|
|
print(f"VARIANT_ID: {variant_id}")
|
|
|
|
# 2. Create Order via API
|
|
API_BASE = "http://localhost:8000/api/v1"
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
payload = {
|
|
"customer_name": "API Test User",
|
|
"customer_email": "apitest@ifixkart.com",
|
|
"customer_phone": "9080323589",
|
|
"items": [
|
|
{
|
|
"variant_id": variant_id,
|
|
"quantity": 1,
|
|
"unit_price": 100.0
|
|
}
|
|
],
|
|
"payment_status": "PAID",
|
|
"payment_method": "CASH",
|
|
"notification_channel": "NONE"
|
|
}
|
|
|
|
print("Creating Order...")
|
|
res = requests.post(f"{API_BASE}/admin/orders/create", json=payload, headers=headers)
|
|
print("Create Order Status:", res.status_code)
|
|
if res.status_code != 200:
|
|
print(res.text)
|
|
sys.exit(1)
|
|
|
|
order_data = res.json()
|
|
order_id = order_data["order_id"]
|
|
print(f"Order created: {order_id}")
|
|
|
|
# 3. Change Status to DELIVERED
|
|
print("Updating Order Status to DELIVERED...")
|
|
status_payload = {
|
|
"status": "DELIVERED"
|
|
}
|
|
res2 = requests.put(f"{API_BASE}/admin/orders/{order_id}/status", json=status_payload, headers=headers)
|
|
print("Update Status:", res2.status_code)
|
|
if res2.status_code != 200:
|
|
print(res2.text)
|
|
sys.exit(1)
|
|
|
|
# 4. Fetch Warranties
|
|
print("Fetching Warranties...")
|
|
res3 = requests.get(f"{API_BASE}/warranties/", headers=headers)
|
|
print("Warranties Status:", res3.status_code)
|
|
if res3.status_code != 200:
|
|
print(res3.text)
|
|
sys.exit(1)
|
|
warranties = res3.json()
|
|
print(f"Found {len(warranties)} warranties")
|
|
|
|
for w in warranties:
|
|
if w["reference_id"] == order_id:
|
|
print("SUCCESS! Warranty found for the order.")
|
|
print("Warranty Details:", json.dumps(w, indent=2))
|
|
sys.exit(0)
|
|
|
|
print("FAILURE: No warranty found for the order.")
|
|
sys.exit(1)
|