Subversion Repositories SmartDukaan

Rev

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

Rev 11118 Rev 11486
Line 37... Line 37...
37
from shop2020.model.v1.order.impl.DataService import RechargeTransaction, HotspotStore,\
37
from shop2020.model.v1.order.impl.DataService import RechargeTransaction, HotspotStore,\
38
    WalletForCompany, WalletHistoryForCompany, RechargeCollection, Company, HotspotServiceMatrix,\
38
    WalletForCompany, WalletHistoryForCompany, RechargeCollection, Company, HotspotServiceMatrix,\
39
    RechargeVoucherTracker, SpiceTransactionHistory
39
    RechargeVoucherTracker, SpiceTransactionHistory
40
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
40
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
41
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds, getBalance,\
41
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds, getBalance,\
42
    getRechargeClient, checkTransactionStatus, getAllTransactions
42
    getRechargeClient, checkTransactionStatus, getAllTransactions, getRechargeStatus
43
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, between
43
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, between
44
 
44
 
45
def main():
45
def main():
46
    parser = optparse.OptionParser()
46
    parser = optparse.OptionParser()
47
    parser.add_option("-H", "--host", dest="hostname",
47
    parser.add_option("-H", "--host", dest="hostname",
Line 105... Line 105...
105
        reconcileWithMobisoc()
105
        reconcileWithMobisoc()
106
        
106
        
107
def reconcileWithMobisoc():
107
def reconcileWithMobisoc():
108
    startTime = datetime.datetime.now() + timedelta(days = -1)
108
    startTime = datetime.datetime.now() + timedelta(days = -1)
109
    endTime = datetime.datetime.now()
109
    endTime = datetime.datetime.now()
-
 
110
    startTime.replace(hour=00,minute=00,second=00)
-
 
111
    endTime.replace(hour=00,minute=00,second=00)
110
    websiteOrders = {}
112
    websiteOrders = {}
111
    storeOrders = {}
113
    storeOrders = {}
112
    spiceOrders = {}
114
    spiceOrders = {}
113
    rechargeOrders = RechargeOrder.query.filter(not_(RechargeOrder.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeOrder.creationTimestamp.between(startTime, endTime)).all()
115
    rechargeOrders = RechargeOrder.query.filter(not_(RechargeOrder.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeOrder.creationTimestamp.between(startTime, endTime)).all()
114
    rechargeTransactions = RechargeTransaction.query.filter(not_(RechargeTransaction.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeTransaction.transactionTime.between(startTime, endTime)).all()
116
    rechargeTransactions = RechargeTransaction.query.filter(not_(RechargeTransaction.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeTransaction.transactionTime.between(startTime, endTime)).all()
115
    print "Creating MAps"
-
 
116
    for rechargeOrder in rechargeOrders:
117
    for rechargeOrder in rechargeOrders:
117
        websiteOrders[int(rechargeOrder.id)] = rechargeOrder
118
        websiteOrders[int(rechargeOrder.id)] = rechargeOrder
118
        
119
        
119
    for rechargeTxn in rechargeTransactions:
120
    for rechargeTxn in rechargeTransactions:
120
        storeOrders[int(rechargeTxn.id)] = rechargeTxn
121
        storeOrders[int(rechargeTxn.id)] = rechargeTxn
121
    
122
    
122
    print "***** Getting transactions from mobisoc..."
-
 
123
    transactions = getAllTransactions(startTime, endTime)
123
    transactions = getAllTransactions(startTime, endTime)
124
    print "***** Got all transactions"
-
 
125
 
124
 
126
    for txn in transactions:
125
    for txn in transactions:
127
        try:
126
        try:
128
            print "in for loop"
127
            print "in for loop"
129
            respCode = txn.getElementsByTagName('transactionResponseCode')[0].childNodes[0].data
128
            respCode = txn.getElementsByTagName('transactionResponseCode')[0].childNodes[0].data
Line 180... Line 179...
180
    if len(websiteOrders.keys()) > 0:
179
    if len(websiteOrders.keys()) > 0:
181
        for woid in websiteOrders.keys():
180
        for woid in websiteOrders.keys():
182
            try:
181
            try:
183
                result = checkTransactionStatus("", str(woid))
182
                result = checkTransactionStatus("", str(woid))
184
            except Exception:
183
            except Exception:
185
                pass
184
                continue
186
            if result:
185
            if result[0]:
187
                removed = websiteOrders.pop(woid, -1)
186
                removed = websiteOrders.pop(woid, -1)
188
                
187
                
189
    if len(storeOrders.keys()) > 0:
188
    if len(storeOrders.keys()) > 0:
190
        for soid in storeOrders.keys():
189
        for soid in storeOrders.keys():
191
            try:
190
            try:
192
                result = checkTransactionStatus("", str(soid))
191
                result = checkTransactionStatus("", str(soid))
193
            except Exception:
192
            except Exception:
194
                pass
193
                continue
195
            if result[0] == False:
194
            if result[0]:
196
                removed = storeOrders.pop(soid, -1)
195
                removed = storeOrders.pop(soid, -1)
197
                
196
                
198
    if len(spiceOrders.keys()) > 0:
197
    if len(spiceOrders.keys()) > 0:
199
        for id in spiceOrders.keys():
198
        for id in spiceOrders.keys():
200
            order = RechargeOrder.query.filter(RechargeOrder.id == id).first()
199
            order = RechargeOrder.query.filter(RechargeOrder.id == id).first()
Line 212... Line 211...
212
                    removed = spiceOrders.pop(id, -1)
211
                    removed = spiceOrders.pop(id, -1)
213
        
212
        
214
    maildata = "<html><body><b>Website Recharges</b><br><br>"
213
    maildata = "<html><body><b>Website Recharges</b><br><br>"
215
    for woid in websiteOrders.keys():
214
    for woid in websiteOrders.keys():
216
        wo = websiteOrders.get(woid)
215
        wo = websiteOrders.get(woid)
-
 
216
        try:
-
 
217
            recharge_status = getRechargeStatus('',wo.id)
-
 
218
        except:
-
 
219
            recharge_status= ""
217
        maildata = maildata + str(wo.id) + " : " +  str(wo.status) + "<br>"
220
        maildata = maildata + str(wo.id) + " : " +  str(RechargeOrderStatus._VALUES_TO_NAMES.get(wo.status)) + " : "+recharge_status+"<br>"
218
 
221
 
219
    maildata = maildata + "<br><br><b>Store recharges</b><br><br>"
222
    maildata = maildata + "<br><br><b>Store recharges</b><br><br>"
220
    for soid in storeOrders.keys():
223
    for soid in storeOrders.keys():
221
        so = storeOrders.get(soid)
224
        so = storeOrders.get(soid)
-
 
225
        try:
-
 
226
            recharge_status = getRechargeStatus('',so.id)
-
 
227
        except:
-
 
228
            recharge_status= ""
222
        maildata = maildata +  str(so.id) + " : " + str(so.status) + "<br>"
229
        maildata = maildata +  str(so.id) + " : " + str(RechargeOrderStatus._VALUES_TO_NAMES.get(wo.status)) + " : "+recharge_status+ "<br>"
223
 
230
 
224
    maildata = maildata + "<br><br><b>Spice Orders</b><br><br>"
231
    maildata = maildata + "<br><br><b>Spice Orders</b><br><br>"
225
    for id in spiceOrders.keys():
232
    for id in spiceOrders.keys():
226
        maildata = maildata + str(id) + " : " + str(spiceOrders.get(id)) + "<br>"
233
        maildata = maildata + str(id) + " : " + str(spiceOrders.get(id)) + "<br>"
227
        
234