HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/unlimited-leads/Unlimited-Leads-Be/user/helpers.py
import math
from payment.models import Transaction


class UserSearchLimit:

    def is_user_limit_exceed(self, usage_count, plan_limit):
        if plan_limit == math.inf:
            return False

        if plan_limit == None:
            return True

        return usage_count >= plan_limit

    def get_user_plan_limit(self, user):
        transaction = (
            Transaction.objects.filter(
                customer=user, subscription_status="active", is_subscription=True
            )
            .order_by("-created_at")
            .first()
        )

        if not transaction:
            return None

        # yearly subscription
        if transaction.product.limit.lower() == "unlimited":
            return math.inf

        # monthly subscription and free user
        try:
            return int(transaction.product.limit)
        except ValueError:
            return None