feat: multi-module improvements across merchant, store, i18n, and customer systems
All checks were successful
All checks were successful
- Fix platform-grouped merchant sidebar menu with core items at root level - Add merchant store management (detail page, create store, team page) - Fix store settings 500 error by removing dead stripe/API tab - Move onboarding translations to module-owned locale files - Fix onboarding banner i18n with server-side rendering + context inheritance - Refactor login language selectors to use languageSelector() function (LANG-002) - Move HTTPException handling to global exception handler in merchant routes (API-003) - Add language selector to all login pages and portal headers - Fix customer module: drop order stats from customer model, add to orders module - Fix admin menu config visibility for super admin platform context - Fix storefront auth and layout issues - Add missing i18n translations for onboarding steps (en/fr/de/lb) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,10 +13,11 @@ Similar to how:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.orders.models import Order
|
||||
from app.modules.orders.models import CustomerOrderStats, Order
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -89,6 +90,51 @@ class CustomerOrderService:
|
||||
.all()
|
||||
)
|
||||
|
||||
def record_order(
|
||||
self,
|
||||
db: Session,
|
||||
store_id: int,
|
||||
customer_id: int,
|
||||
total_amount_cents: int,
|
||||
) -> CustomerOrderStats:
|
||||
"""
|
||||
Record an order in customer order stats (upsert).
|
||||
|
||||
Args:
|
||||
db: Database session
|
||||
store_id: Store ID
|
||||
customer_id: Customer ID
|
||||
total_amount_cents: Order total in cents
|
||||
|
||||
Returns:
|
||||
Updated CustomerOrderStats
|
||||
"""
|
||||
stats = (
|
||||
db.query(CustomerOrderStats)
|
||||
.filter(
|
||||
CustomerOrderStats.store_id == store_id,
|
||||
CustomerOrderStats.customer_id == customer_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
now = datetime.now(UTC)
|
||||
if stats:
|
||||
stats.total_orders = (stats.total_orders or 0) + 1
|
||||
stats.total_spent_cents = (stats.total_spent_cents or 0) + total_amount_cents
|
||||
stats.last_order_date = now
|
||||
else:
|
||||
stats = CustomerOrderStats(
|
||||
store_id=store_id,
|
||||
customer_id=customer_id,
|
||||
total_orders=1,
|
||||
total_spent_cents=total_amount_cents,
|
||||
first_order_date=now,
|
||||
last_order_date=now,
|
||||
)
|
||||
db.add(stats)
|
||||
db.flush()
|
||||
return stats
|
||||
|
||||
def get_order_count(
|
||||
self,
|
||||
db: Session,
|
||||
|
||||
Reference in New Issue
Block a user