Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
chore: Update query payment orm by source

See merge request locker/api-core!395
  • Loading branch information
phuongntt-cystack committed Mar 14, 2024
2 parents 177c5b5 + 186e7b6 commit 51a5d2d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions locker_server/api_orm/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
platform_param = filters.get("platform", "") # CHPlay,Stripe,ChPlay, Markets
status_param = filters.get("status") # success,failed,pending
plan_param = filters.get("plan") # premium, lifetime,family,enterprise
utm_source_param = filters.get("utm_source") # organic,ads, affiliate
channel_param = filters.get("channel") # organic,ads, affiliate
source_param = filters.get("source") # stacksocial, dealmirror, saasmantra
payment_method_param = filters.get("payment_method")
user_id_param = filters.get("user_id")
enterprise_id_param = filters.get("enterprise_id")
Expand All @@ -118,21 +119,20 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
payments_orm = payments_orm.filter(plan=plan_param)
if status_param:
payments_orm = payments_orm.filter(status=status_param)
if utm_source_param:
user_ids = UserORMRepository.search_from_cystack_id(**{"utm_source": utm_source_param}).get("ids", [])
if channel_param:
user_ids = UserORMRepository.search_from_cystack_id(**{"utm_source": channel_param}).get("ids", [])
payments_orm = payments_orm.filter(user_id__in=user_ids)
if platform_param:
platform_param = platform_param.lower()
if platform_param == "stripe":
payments_orm = payments_orm.filter(stripe_invoice_id__isnull=False)
elif platform_param == "ios":
payments_orm = payments_orm.filter(
Q(stripe_invoice_id__isnull=True) & Q(metadata__contains="ios") & Q(mobile_invoice_id__isnull=False)

Q(metadata__contains="ios") & Q(mobile_invoice_id__isnull=False)
)
elif platform_param == "android":
payments_orm = payments_orm.filter(
Q(stripe_invoice_id__isnull=True) & Q(metadata__contains="android") &
Q(metadata__contains="android") &
Q(mobile_invoice_id__isnull=False)

)
Expand All @@ -142,7 +142,9 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
payments_orm = payments_orm.filter(user_id=user_id_param)
if enterprise_id_param:
payments_orm = payments_orm.filter(enterprise_id=enterprise_id_param)

if source_param:
source_param = source_param.lower()
payments_orm = payments_orm.filter(saas_market__icontains=source_param)
payments_orm = payments_orm.select_related('user')
payments_orm = payments_orm.order_by("-created_time")
return payments_orm
Expand Down Expand Up @@ -373,12 +375,12 @@ def statistic_by_type(self, **filters) -> List:
).order_by("currency")

total_price_ios = payments_orm.filter(
Q(stripe_invoice_id__isnull=True) & Q(metadata__contains="ios") & Q(mobile_invoice_id__isnull=False)
Q(metadata__contains="ios") & Q(mobile_invoice_id__isnull=False)
).values("currency").annotate(
total_price=Sum('total_price')
).order_by("currency")
total_price_android = payments_orm.filter(
Q(stripe_invoice_id__isnull=True) & Q(metadata__contains="android") &
Q(metadata__contains="android") &
Q(mobile_invoice_id__isnull=False)
).values("currency").annotate(
total_price=Sum('total_price')
Expand Down

0 comments on commit 51a5d2d

Please sign in to comment.