ifixkart-backend/app/api/v1/routers/BillingFinanceRouter.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

86 lines
3.3 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Query, status, Request
from sqlalchemy.orm import Session
from typing import List, Optional, Any
from app.core.database.db_session import get_db
from app.core.permissions.RoleChecker import get_current_user
from app.models.UserModel import User
from app.services.BillingFinanceService import BillingFinanceService
from app.schemas.BillingFinance import (
CrmBulkQuotationCreate, CrmBulkQuotationResponse,
CrmGstInvoiceCreate, CrmGstInvoiceResponse, CrmRecordPayment
)
router = APIRouter(prefix="/api/v1/billing-finance", tags=["Billing & GST Finance Management"])
def get_billing_service(request: Request, db: Session = Depends(get_db)) -> BillingFinanceService:
tenant_id = getattr(request.state, "tenant_id", "tenant_default")
return BillingFinanceService(db=db, tenant_id=tenant_id)
# --- BULK QUOTATION ENDPOINTS ---
@router.post("/quotations", response_model=CrmBulkQuotationResponse, status_code=status.HTTP_201_CREATED)
def create_bulk_quotation(
payload: CrmBulkQuotationCreate,
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Creates a formal B2B bulk quotation estimate."""
return svc.create_quotation(payload)
@router.get("/quotations", response_model=List[CrmBulkQuotationResponse])
def list_bulk_quotations(
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Lists all B2B bulk quotations."""
return svc.list_quotations()
@router.post("/quotations/{quote_id}/convert", response_model=CrmGstInvoiceResponse)
def convert_quotation_to_invoice(
quote_id: str,
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Converts an approved B2B bulk quotation into a formal GST Tax Invoice."""
res = svc.convert_quote_to_invoice(quote_id)
if not res or (isinstance(res, dict) and "error" in res):
raise HTTPException(status_code=404, detail="Quotation not found or already converted")
return res
# --- GST TAX INVOICE ENDPOINTS ---
@router.post("/invoices", response_model=CrmGstInvoiceResponse, status_code=status.HTTP_201_CREATED)
def create_gst_invoice(
payload: CrmGstInvoiceCreate,
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Creates a new GST Tax Invoice with itemized IMEI warranty stamping and CGST/SGST/IGST calculation."""
return svc.create_invoice(payload)
@router.get("/invoices", response_model=List[CrmGstInvoiceResponse])
def list_gst_invoices(
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Lists all GST Tax Invoices."""
return svc.list_invoices()
@router.post("/invoices/{invoice_id}/payment", response_model=CrmGstInvoiceResponse)
def record_invoice_payment(
invoice_id: str,
payload: CrmRecordPayment,
svc: BillingFinanceService = Depends(get_billing_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Records payment for a GST Tax Invoice."""
invoice = svc.record_payment(invoice_id, payload)
if not invoice:
raise HTTPException(status_code=404, detail="GST Invoice not found")
return invoice