Coverage for polar/customer_portal/repository/order.py: 90%
17 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from typing import TYPE_CHECKING
2from uuid import UUID
4from sqlalchemy import Select
5from sqlalchemy.orm import joinedload, selectinload
7from polar.auth.models import AuthSubject
8from polar.kit.repository import (
9 Options,
10 RepositoryBase,
11 RepositorySoftDeletionIDMixin,
12 RepositorySoftDeletionMixin,
13)
14from polar.models import (
15 Customer,
16 Order,
17 OrderItem,
18 Product,
19 ProductPrice,
20 Subscription,
21)
23if TYPE_CHECKING: 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true
24 from sqlalchemy.orm.strategy_options import _AbstractLoad
27class CustomerOrderRepository(
28 RepositorySoftDeletionIDMixin[Order, UUID],
29 RepositorySoftDeletionMixin[Order],
30 RepositoryBase[Order],
31):
32 model = Order
34 def get_readable_statement(
35 self, auth_subject: AuthSubject[Customer]
36 ) -> Select[tuple[Order]]:
37 return self.get_base_statement().where(
38 Order.customer_id == auth_subject.subject.id
39 )
41 def get_eager_options(
42 self, *, product_load: "_AbstractLoad | None" = None
43 ) -> Options:
44 if product_load is None:
45 product_load = joinedload(Order.product)
46 return (
47 joinedload(Order.customer).joinedload(Customer.organization),
48 joinedload(Order.discount),
49 joinedload(Order.subscription).joinedload(Subscription.customer),
50 product_load.options(
51 selectinload(Product.product_medias),
52 joinedload(Product.organization),
53 ),
54 selectinload(Order.items)
55 .joinedload(OrderItem.product_price)
56 .joinedload(ProductPrice.product),
57 )