Template
## Summary - Closes #7 - Portal Retail **Sales** page: 30-day orders/revenue/units/AOV, daily charts, top products - Home dashboard cards for 30-day shop sales and revenue when `FEATURE_SHOP` is on - Stacks on #6 (shop catalog). Merge that first, then retarget `master` if needed. ## Test plan - [ ] Sales page requires login; empty state with no paid orders - [ ] Paid/fulfilled in the last 30 days counted; draft/open/cancelled/old excluded - [ ] Top products ranked by units; home dashboard shows 30-day sales count - [ ] `manage.py test shop core.tests_features` Reviewed-on: #8
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from core.registry import (
|
|
register_dashboard_collector,
|
|
register_feature,
|
|
register_portal_nav,
|
|
register_public_nav,
|
|
)
|
|
|
|
|
|
def register() -> None:
|
|
register_feature("shop")
|
|
register_public_nav(section="shop", label="Shop", url_name="shop:list", order=30)
|
|
register_portal_nav(
|
|
section="shop_sales",
|
|
label="Sales",
|
|
url_name="shop_portal:sales",
|
|
group="Retail",
|
|
order=5,
|
|
)
|
|
register_portal_nav(
|
|
section="shop_products",
|
|
label="Products",
|
|
url_name="shop_portal:product_list",
|
|
group="Retail",
|
|
order=10,
|
|
)
|
|
register_portal_nav(
|
|
section="shop_orders",
|
|
label="Orders",
|
|
url_name="shop_portal:order_list",
|
|
group="Retail",
|
|
order=20,
|
|
)
|
|
register_dashboard_collector(_dashboard)
|
|
|
|
|
|
def _dashboard(request) -> dict:
|
|
from shop.models import Order, Product
|
|
from shop.stats import sales_summary
|
|
|
|
sales = sales_summary()
|
|
return {
|
|
"open_shop_orders": Order.objects.filter(
|
|
status__in=[Order.Status.OPEN, Order.Status.PAID]
|
|
).count(),
|
|
"low_stock_products": Product.objects.filter(
|
|
is_published=True,
|
|
track_inventory=True,
|
|
fulfillment=Product.Fulfillment.STOCKED,
|
|
stock_qty__lte=3,
|
|
).count(),
|
|
"shop_sales_30d": sales["order_count"],
|
|
"shop_revenue_30d": sales["revenue"],
|
|
}
|