Coverage for products/managers.py: 69%
19 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-04-03 14:02 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-04-03 14:02 -0600
1from django.db.models import Q, Manager, Sum
2from django.utils import timezone
3from polymorphic.managers import PolymorphicManager
6class ProductManager(PolymorphicManager):
7 """
8 Manager for product
9 """
11 def available_for(self, membership):
12 """
13 Get Available products for selected membership
14 """
15 if membership.segment:
16 segment_ancestors = membership.segment.get_ancestors(include_self=True)
17 available_products = self.filter(
18 membership_type=membership.type_of,
19 segments__in=segment_ancestors,
20 is_active=True,
21 )
22 return available_products
23 else:
24 available_products = self.filter(
25 membership_type=membership.type_of,
26 is_active=True,
27 )
28 return available_products
31class EventProductManager(ProductManager):
32 """
33 Manager for event product
34 """
36 # def get_product(self, event, membership):
37 # """
38 # Retrieve event product instance for given membership
39 # """
40 # objects = self.available_for(membership)
41 # objects = objects.get(event=event)
42 # return objects.first()
45class PriceVariationManager(Manager):
46 """
47 Manager for Product Price Variations
48 """
50 def appliable_for(self, membership, product):
51 available_variations = self.filter(
52 product=product,
53 membership_type=membership.type_of,
54 is_active=True,
55 )
56 if membership.segment: 56 ↛ 61line 56 didn't jump to line 61, because the condition on line 56 was never false
57 segment_ancestors = membership.segment.get_ancestors(include_self=True)
58 available_variations = available_variations.filter(
59 segments__in=segment_ancestors,
60 )
61 return available_variations