def get_balance_pending(self): ''' pending currents from offer redemption requests ''' active_redemption_reqs = self.get_redemptions(status='pending') total_redemptions = common._get_redemption_total( active_redemption_reqs) return total_redemptions
def get_balance_pending_usd(self): ''' pending usd balance is composed of: - requested redemptions - redemptions in status redeemed and accepted do not count ''' # user's transations transactions = self._get_transactions_annotated() actions = self._get_actions_for_annotated_transactions( transactions, 'req') total_redemptions = common._get_redemption_total(actions, 'usd') return round(total_redemptions, 2)
def get_master_offer_remaining(self): ''' return cumulative user's redemption amount towards the master offer ''' dt_week_ago_from_now = datetime.now(tz=pytz.utc) - timedelta(days=7) actions = self._get_transactions_master_timeframe(dt_week_ago_from_now) remaining = common._MASTER_OFFER_LIMIT - float( common._get_redemption_total(actions)) if remaining < 0: logger.warning('user %s has redeemed above master offer limit', self.user.username) remaining = 0 return remaining
def get_giftcard_offer_redeemed(self): ''' return cumulative user's redemption amount towards the gift offers ''' dt_week_ago_from_now = datetime.now(tz=pytz.utc) - timedelta(days=7) actions = self._get_transactions_giftcard_timeframe( dt_week_ago_from_now) redeemed = float(common._get_redemption_total(actions)) # if remaining < 0: # logger.warning( # 'user %s has redeemed above giftcard offer limit', # self.user.username # ) # remaining = 0 return redeemed
def get_balance_available(self): ''' report total available currents - balance based on ledger - minus redeemed offers ''' if not self.userid: raise InvalidUserException() current_balance = OcLedger().get_balance( entity_id=self.user.userentity.id, entity_type='user') # offer redemption requests transactions = self._get_transactions_annotated() actions = self._get_actions_for_annotated_transactions( transactions, 'req') total_req_redemptions = common._get_redemption_total(actions) return round(current_balance - total_req_redemptions, 3)