parameters: (self)
return_statement: return 0, 0
docstring: Calculates the oldest non-expired topup that still has credits
docstring_summary: Calculates the oldest non-expired topup that still has credits
docstring_tokens: Calculates the oldest non - expired topup that still has credits
function: def _calculate_active_topup(self):
          """
          Calculates the oldest non-expired topup that still has credits
          """
          non_expired_topups = self.topups.filter(is_active=True, expires_on__gte=timezone.now()).order_by(
              "expires_on", "id"
          )
          active_topups = (
              non_expired_topups.annotate(used_credits=Sum("topupcredits__used"))
              .filter(credits__gt=0)
              .filter(Q(used_credits__lt=F("credits")) | Q(used_credits=None))
          )
  
          topup = active_topups.first()
          if topup:
              # initialize our active topup metrics
              r = get_redis_connection()
              ttl = self.get_topup_ttl(topup)
              r.set(ORG_ACTIVE_TOPUP_REMAINING % (self.id, topup.id), topup.get_remaining(), ttl)
              return topup.id, ttl
  
          return 0, 0
function_tokens: def _calculate_active_topup ( self ) : non_expired_topups = self . topups . filter ( is_active = True , expires_on__gte = timezone . now ( ) ) . order_by ( "expires_on" , "id" ) active_topups = ( non_expired_topups . annotate ( used_credits = Sum ( "topupcredits__used" ) ) . filter ( credits__gt = 0 ) . filter ( Q ( used_credits__lt = F ( "credits" ) ) | Q ( used_credits = None ) ) ) topup = active_topups . first ( ) if topup : # initialize our active topup metrics r = get_redis_connection ( ) ttl = self . get_topup_ttl ( topup ) r . set ( ORG_ACTIVE_TOPUP_REMAINING % ( self . id , topup . id ) , topup . get_remaining ( ) , ttl ) return topup . id , ttl return 0 , 0