Files
chatballs/apps/backend/hub_platform/orders/selectors.py
T
AndreyandClaude Opus 4.8 5b831e6cae feat(orders): commerce orders domain + real sales metrics
New orders app (ADR-HUB-0018: catalog & sale recorded in Hub, execution
in product backends):
- Order + OrderItem models with payment/fulfillment status; items snapshot
  offer + price version so the record is stable. Migration included.
- Services (create_order, mark_paid, cancel_order, set_fulfillment),
  selectors, serializers, REST API (list/create/detail + status actions)
  under IsAuthenticated/IsOwner, org-scoped. Tests: 6 green.
- seed_orders management command for local demo (idempotent).

Wired real numbers into the spots that were "—":
- Sales overview: Продажи / Выручка / Конверсия + per-product sales/revenue.
- Clients list: orders count and purchases total per contact.
- Client detail: Заказы tab + summary (orders, purchases).

Full backend suite: 91/91.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 22:30:04 +03:00

17 lines
526 B
Python

from django.db.models import QuerySet
from hub_platform.orders.models import Order
def orders_for_organization(organization_id: int) -> QuerySet[Order]:
return (
Order.objects.filter(organization_id=organization_id)
.select_related("contact", "product", "channel", "conversation")
.prefetch_related("items")
.order_by("-created_at")
)
def order_for_organization(*, organization_id: int, order_id: int) -> Order:
return orders_for_organization(organization_id).get(id=order_id)