From 186e7b63644b0d87ce3fa0c7185698e805b77765 Mon Sep 17 00:00:00 2001 From: phuongntt Date: Thu, 14 Mar 2024 14:57:06 +0700 Subject: [PATCH] chore: Update query payment orm by source --- .../repositories/payment_repository.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/locker_server/api_orm/repositories/payment_repository.py b/locker_server/api_orm/repositories/payment_repository.py index 6f47fce..e211812 100644 --- a/locker_server/api_orm/repositories/payment_repository.py +++ b/locker_server/api_orm/repositories/payment_repository.py @@ -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") @@ -118,8 +119,8 @@ 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() @@ -127,12 +128,11 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]: 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) ) @@ -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 @@ -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')