Coverage for polar/customer_portal/repository/order.py: 62%
17 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
1from typing import TYPE_CHECKING 1a
2from uuid import UUID 1a
4from sqlalchemy import Select 1a
5from sqlalchemy.orm import joinedload, selectinload 1a
7from polar.auth.models import AuthSubject 1a
8from polar.kit.repository import ( 1a
9 Options,
10 RepositoryBase,
11 RepositorySoftDeletionIDMixin,
12 RepositorySoftDeletionMixin,
13)
14from polar.models import ( 1a
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 true1a
24 from sqlalchemy.orm.strategy_options import _AbstractLoad
27class CustomerOrderRepository( 1a
28 RepositorySoftDeletionIDMixin[Order, UUID],
29 RepositorySoftDeletionMixin[Order],
30 RepositoryBase[Order],
31):
32 model = Order 1a
34 def get_readable_statement( 1a
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( 1a
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 )