Exemplo n.º 1
0
    def deletePref(self, consumerId, cardId, categoryKey, periodKey):
        pref = None
        millis = SSUtil.getMillis()
        cacheService = CacheService()
        txnService = TxnService()
        try:
            pref = ConsumerPrefs.objects.get(consumerId=consumerId,
                                             cardId=cardId,
                                             periodKey=periodKey,
                                             categoryKey=categoryKey)
            pref.delete()
        except ConsumerPrefs.DoesNotExist:
            pass

        try:
            agg = ConsumerAgg.objects.get(consumerId=consumerId,
                                          cardId=cardId,
                                          periodKey=periodKey,
                                          categoryKey=categoryKey)
            agg.delete()
        except ConsumerAgg.DoesNotExist:
            pass
        cacheService.setConsumerPrefs(consumerId)
        txnService.recalculateAgg(consumerId, None, None)
        cacheService.setConsumerAggs(consumerId)
        return True
Exemplo n.º 2
0
 def savePref(self, consumerId, cardId, categoryKey, periodKey, action,
              userLimit):
     pref = None
     millis = SSUtil.getMillis()
     cacheService = CacheService()
     txnService = TxnService()
     try:
         if categoryKey is None:
             pref = ConsumerPrefs.objects.get(consumerId=consumerId,
                                              cardId=cardId,
                                              periodKey=periodKey,
                                              categoryKey='Any')
         else:
             pref = ConsumerPrefs.objects.get(consumerId=consumerId,
                                              cardId=cardId,
                                              periodKey=periodKey,
                                              categoryKey=categoryKey)
     except ConsumerPrefs.DoesNotExist:
         pref = ConsumerPrefs()
         pref.consumerId = consumerId
         pref.cardId = cardId
         pref.periodKey = periodKey
         pref.categoryKey = categoryKey
         pref.created = millis
         pref.txType = "Any"
         pref.merchantId = -1
     pref.ssApproval = action
     pref.limit = userLimit
     pref.updated = millis
     pref.save()
     cacheService.setConsumerPrefs(consumerId)
     txnService.recalculateAgg(consumerId, None, None)
     cacheService.setConsumerAggs(consumerId)
     return pref
Exemplo n.º 3
0
    def createDefaultPrefsAndAggs(self, card):
        agg = None
        pref = None
        defPeriodKeys = {"Daily","Monthly"}
        defAction = "Approve"
        millis = SSUtil.getMillis()
        cacheService = CacheService()
        for periodKey in defPeriodKeys:
            try:
                pref = ConsumerPrefs.objects.get(consumerId=card.consumerId,
                                    cardId = card.id, periodKey=periodKey,
                                    categoryKey='Any')
            except:
                pref = ConsumerPrefs()
                pref.consumerId = card.consumerId
                pref.cardId = card.id
                pref.periodKey = periodKey
                pref.categoryKey = 'Any'
                pref.created = millis
                pref.txType = "Any"
                pref.merchantId = -1
                pref.ssApproval = defAction
            pref.limit = card.limit
            pref.updated = millis
            pref.save()

            try:
                agg = ConsumerAgg.objects.get(consumerId=card.consumerId,
                                    cardId = card.id, periodKey=periodKey,
                                    categoryKey='Any')
            except:
                agg = ConsumerAgg()
                agg.consumerId = card.consumerId
                agg.cardId = card.id
                agg.periodKey = periodKey
                agg.categoryKey = 'Any'
                agg.created = millis
                agg.txType = "Any"
                agg.merchantId = -1
                agg.ssApproval = defAction
            agg.amtSpentSS = 0.00
            agg.updated = millis
            agg.save()
        cacheService.setConsumerPrefs(card.consumerId)
        cacheService.setConsumerAggs(card.consumerId)