Subversion Repositories SmartDukaan

Rev

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

Rev 14449 Rev 14618
Line 1... Line 1...
1
'''
1
'''
2
Created on Jan 15, 2015
2
Created on Jan 15, 2015
3
 
3
 
4
@author: amit
4
@author: amit
5
'''
5
'''
6
from datetime import datetime
6
from datetime import datetime, timedelta
7
from dtr.config import PythonPropertyReader, PythonPropertyReader
7
from dtr.config import PythonPropertyReader, PythonPropertyReader
-
 
8
from dtr.storage.Mysql import getOrdersAfterDate1, getOrdersAfterDate
8
from pprint import pprint
9
from pprint import pprint
9
from pymongo.mongo_client import MongoClient
10
from pymongo.mongo_client import MongoClient
10
import base64
11
import base64
11
import importlib
12
import importlib
12
import json
13
import json
Line 75... Line 76...
75
    CB_PENDING = 'Pending'
76
    CB_PENDING = 'Pending'
76
    CB_CREDIT_IN_PROCESS = 'Credit in process'
77
    CB_CREDIT_IN_PROCESS = 'Credit in process'
77
    CB_CREDITED = 'Credited to wallet'
78
    CB_CREDITED = 'Credited to wallet'
78
    CB_NA = 'Not Applicable'
79
    CB_NA = 'Not Applicable'
79
    CB_APPROVED = 'Approved'
80
    CB_APPROVED = 'Approved'
-
 
81
    CB_REJECTED = 'Rejected'
-
 
82
    CB_ONHOLD = 'On hold'
80
    CB_CANCELLED = 'Cancelled'
83
    CB_CANCELLED = 'Cancelled'
81
    
84
    
82
    CONF_CB_SELLING_PRICE = 0
85
    CONF_CB_SELLING_PRICE = 0
83
    CONF_CB_DISCOUNTED_PRICE = 1
86
    CONF_CB_DISCOUNTED_PRICE = 1
84
    
87
    
Line 99... Line 102...
99
        raise NotImplementedError
102
        raise NotImplementedError
100
    
103
    
101
    def saveToAffiliate(self, offers):
104
    def saveToAffiliate(self, offers):
102
        raise NotImplementedError
105
        raise NotImplementedError
103
    
106
    
-
 
107
    def saveOrder(self, merchantOrder):
-
 
108
        #merchantOrder = Order()
-
 
109
        #merchantOrder.status
-
 
110
        #mercha
-
 
111
        pass
-
 
112
    
-
 
113
    
104
    def scrapeStoreOrders(self,):
114
    def scrapeStoreOrders(self,):
105
        raise NotImplementedError
115
        raise NotImplementedError
106
    
116
    
-
 
117
    def updateSubOrder(self, subOrder):
-
 
118
        pass
-
 
119
        #if subOrder.get
-
 
120
    
107
    def _saveToOrder(self, order):
121
    def _saveToOrder(self, order):
108
        collection = self.db.merchantOrder
122
        collection = self.db.merchantOrder
109
        try:
123
        try:
110
            order = collection.insert(order)
124
            order = collection.insert(order)
111
            return True 
125
            return True 
Line 178... Line 192...
178
        for subOrder in subOrders:
192
        for subOrder in subOrders:
179
            if merchantSubOrderId == subOrder.get("merchantSubOrderId"):
193
            if merchantSubOrderId == subOrder.get("merchantSubOrderId"):
180
                return subOrder
194
                return subOrder
181
        return None
195
        return None
182
 
196
 
183
def settlePayBack():
197
def settlePayBack(runtype='dry'):
184
        client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_APPROVED},{'$set':{'subOrders.$.cashBackStatus':Store.CB_CREDIT_IN_PROCESS}}, multi=True)    
198
        client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_APPROVED},{'$set':{'subOrders.$.cashBackStatus':Store.CB_CREDIT_IN_PROCESS}}, multi=True)    
185
        result = client.Dtr.merchantOrder\
199
        result = client.Dtr.merchantOrder\
186
            .aggregate([
200
            .aggregate([
187
                        {'$match':{'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS}},
201
                        {'$match':{'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS}},
188
                        {'$unwind':"$subOrders"},
202
                        {'$unwind':"$subOrders"},
Line 191... Line 205...
191
                                   '_id':'$userId',
205
                                   '_id':'$userId',
192
                                   'amount': { '$sum':'$subOrders.cashBackAmount'},
206
                                   'amount': { '$sum':'$subOrders.cashBackAmount'},
193
                                   }
207
                                   }
194
                         }
208
                         }
195
                    ])['result']
209
                    ])['result']
-
 
210
        if runtype!='live':
-
 
211
            print result
-
 
212
            return
196
                    
213
                    
197
        userAmountMap = {}
214
        userAmountMap = {}
198
        print result
215
        print result
199
        for res in result:
216
        for res in result:
200
            userAmountMap[res['_id']] = res['amount']
217
            userAmountMap[res['_id']] = res['amount']
Line 240... Line 257...
240
        traceback.print_exc()
257
        traceback.print_exc()
241
        tprint("Could not batch refund")
258
        tprint("Could not batch refund")
242
        return False
259
        return False
243
    
260
    
244
def main():
261
def main():
-
 
262
#    client = MongoClient('mongodb://root:ecip$dtrMay2014@dtr:27017/')
245
    store = getStore(4)
263
#    s = Store(1)
246
    #print store.getCashbackAmount('1010989', 500)
-
 
247
    #data = urllib.urlencode({'orderId':6000, 'amount':200})
-
 
248
    #request = urllib2.Request(WALLET_CREDIT_URL % (483649), headers=headers)
264
#    orders = s.db.Dtr.find({"subOrders.imgUrl":{"$exists":1}}, {"merchantOrderId":1, "subOrders.productCode":1,"subOrders.imgUrl":1,"_id": 0})
249
    #response = urllib2.urlopen(request, data)
-
 
250
    #print response.read()
265
#    db = client.Dtr
251
    #settlePayBack()
266
#    for order in orders:
252
    for store in client.Dtr.merchantOrder.find({"storeId":3}):
267
#        for subOrder in order.get("subOrders"):
253
        client.Dtr.merchantOrder.update({"orderId":store["orderId"]},{'$set':{'placedOn':store['subOrders'][0]['placedOn']}})
268
#            #db.merchantOrder.update({"merchantOrderId":order.getMerchantOrderId,"subOrders.imgUrl":{"$exists":0}, "subOrders.productCode":subOrder.get("productCode")}, {"$set":{"subOrders.$.imgUrl":subOrder.get("imgUrl")}})
254
    
269
#            db.merchantOrder.findOne()
255
        
270
    settlePayBack()        
256
 
271
 
257
 
272
 
258
###
273
###
259
#Settlement process is suposed to be a batch and run weekly
274
#Settlement process is suposed to be a batch and run weekly
260
#It is should be running on first hour of mondays. As cron should
275
#It is should be running on first hour of mondays. As cron should