Subversion Repositories SmartDukaan

Rev

Rev 16999 | Rev 17002 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16999 Rev 17000
Line 53... Line 53...
53
            for key, value in userCashbacksMap.iteritems():
53
            for key, value in userCashbacksMap.iteritems():
54
                get_mongo_connection().Dtr.refund.insert({"userId": key, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S"), "type":utils.CREDIT_TYPE_APP})
54
                get_mongo_connection().Dtr.refund.insert({"userId": key, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S"), "type":utils.CREDIT_TYPE_APP})
55
                get_mongo_connection().Dtr.user.update({"userId":key}, {"$inc": { "credited": value, utils.CREDIT_TYPE_APP:value}}, upsert=True)
55
                get_mongo_connection().Dtr.user.update({"userId":key}, {"$inc": { "credited": value, utils.CREDIT_TYPE_APP:value}}, upsert=True)
56
        else:
56
        else:
57
            print 'Refund Process have been failed'
57
            print 'Refund Process have been failed'
-
 
58
    else:
-
 
59
        print 'Dry Run:- Only showing user map for which cashback have been updated'
-
 
60
        currentTimestamp = datetime.today()
-
 
61
        currentMonth = currentTimestamp.month
-
 
62
        currentDay = currentTimestamp.day
-
 
63
        currentYear = currentTimestamp.year
-
 
64
        fortNight = (currentMonth - 1)*2 + (currentDay/15)
-
 
65
        
-
 
66
        userCashbacksToBeCredited = user_app_cashbacks.query.filter(user_app_cashbacks.user_id>0).filter(user_app_cashbacks.status=='Approved').filter(user_app_cashbacks.fortnightOfYear<fortNight).filter(user_app_cashbacks.yearVal==currentYear).all()
-
 
67
        userCashbacksMap = {}
-
 
68
        for userCashback in userCashbacksToBeCredited:
-
 
69
            if userCashback.user_id >0:
-
 
70
                if userCashbacksMap.has_key(userCashback.user_id):
-
 
71
                    cashBackAmount = userCashbacksMap.get(userCashback.user_id) + userCashback.amount
-
 
72
                    userCashbacksMap[userCashback.user_id] = cashBackAmount
-
 
73
                else:
-
 
74
                    userCashbacksMap[userCashback.user_id] = userCashback.amount
-
 
75
        
-
 
76
        datetimeNow = datetime.now() 
-
 
77
        batchId = int(time.mktime(datetimeNow.timetuple()))
-
 
78
        print 'BatchId:- ', batchId
-
 
79
        
-
 
80
        for key, value in userCashbacksMap.iteritems():
-
 
81
            print 'User Id:- ', key, ' Cashback Value:- ', value
58
        
82
        
59
def main(argv):
83
def main(argv):
60
    runtype = 'dry'
84
    runtype = 'dry'
61
    try:
85
    try:
62
        opts, args = getopt.getopt(argv,"ht:",["runtype="])
86
        opts, args = getopt.getopt(argv,"ht:",["runtype="])