FIX(promotions): default event status promotion_amount to 0 #2
1 changed files with 11 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ import uuid
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.postgres.indexes import GinIndex
|
from django.contrib.postgres.indexes import GinIndex
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import F
|
from django.db.models import F, Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django_minio_backend import MinioBackend, iso_date_prefix
|
from django_minio_backend import MinioBackend, iso_date_prefix
|
||||||
|
|
||||||
|
|
@ -136,10 +136,16 @@ class Plan(BaseModel):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def get_configured_promotion_amount(self, user_uuid=None):
|
def get_configured_promotion_amount(self, user_uuid=None):
|
||||||
|
access_filter = Q(access_type=RecipientTypeChoices.PUBLIC)
|
||||||
|
if user_uuid:
|
||||||
|
access_filter |= Q(access_type=RecipientTypeChoices.RESTRICTED, allowed_users__user__uuid=user_uuid)
|
||||||
|
|
||||||
|
recipients = self.recipients.filter(
|
||||||
|
recipient_uuid_field='->event:user' #TODO: instead of hard code use better soloution
|
||||||
|
).filter(access_filter).distinct()
|
||||||
|
|
||||||
amount = 0
|
amount = 0
|
||||||
for recipient in self.recipients.filter(recipient_uuid_field='->event:user'): #TODO: instead of hard code use better soloution
|
for recipient in recipients:
|
||||||
if not recipient.is_user_allowed(user_uuid):
|
|
||||||
continue
|
|
||||||
base_amount, promotion_amount = recipient.get_promotion_amount()
|
base_amount, promotion_amount = recipient.get_promotion_amount()
|
||||||
amount += promotion_amount
|
amount += promotion_amount
|
||||||
return amount
|
return amount
|
||||||
|
|
@ -393,7 +399,7 @@ class PromotionQuerySet(models.QuerySet):
|
||||||
|
|
||||||
def get_event_status_for_user(user_uuid, event_label):
|
def get_event_status_for_user(user_uuid, event_label):
|
||||||
processed = Promotion.objects.is_processed_for_user(user_uuid, event_label)
|
processed = Promotion.objects.is_processed_for_user(user_uuid, event_label)
|
||||||
promotion_amount = None
|
promotion_amount = 0
|
||||||
if not processed:
|
if not processed:
|
||||||
plan = Plan.objects.filter(event_list__icontains=event_label).first()
|
plan = Plan.objects.filter(event_list__icontains=event_label).first()
|
||||||
if plan:
|
if plan:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue