Subversion Repositories SmartDukaan

Rev

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

Rev 10420 Rev 10428
Line 23... Line 23...
23
DataService.initialize(db_hostname=host)
23
DataService.initialize(db_hostname=host)
24
 
24
 
25
class __SnapdealInfo:
25
class __SnapdealInfo:
26
    def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, \
26
    def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, \
27
                 fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId, parentCategory, productGroup ,brand, modelName, modelNumber, \
27
                 fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId, parentCategory, productGroup ,brand, modelName, modelNumber, \
28
                 color):
28
                 color,reason):
29
        
29
        
30
        self.sellingPrice = sellingPrice
30
        self.sellingPrice = sellingPrice
31
        self.weight = weight
31
        self.weight = weight
32
        self.transferPrice = transferPrice
32
        self.transferPrice = transferPrice
33
        self.commission = commission
33
        self.commission = commission
Line 45... Line 45...
45
        self.parentCategory = parentCategory
45
        self.parentCategory = parentCategory
46
        self.productGroup = productGroup
46
        self.productGroup = productGroup
47
        self.brand = brand
47
        self.brand = brand
48
        self.modelName = modelName
48
        self.modelName = modelName
49
        self.modelNumber = modelNumber
49
        self.modelNumber = modelNumber
50
        self.color = color 
50
        self.color = color
-
 
51
        self.reason = reason 
51
        
52
        
52
 
53
 
53
def getBrowserObject():
54
def getBrowserObject():
54
    br = mechanize.Browser(factory=mechanize.RobustFactory())
55
    br = mechanize.Browser(factory=mechanize.RobustFactory())
55
    cj = cookielib.LWPCookieJar()
56
    cj = cookielib.LWPCookieJar()
Line 121... Line 122...
121
    dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
122
    dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
122
    struct = json.loads(dataform)
123
    struct = json.loads(dataform)
123
    sdObj = struct['rows'][0]
124
    sdObj = struct['rows'][0]
124
    print sdObj
125
    print sdObj
125
    snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None, \
126
    snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None, \
126
                    None, None, None, None, None, None)
127
                    None, None, None, None, None, None, None)
127
    return snapdealInfo
128
    return snapdealInfo
128
 
129
 
129
def filterData(fetchedItems):
130
def filterData(fetchedItems):
130
    filterList = []
131
    filterList = []
131
    for data in fetchedItems:
132
    for data in fetchedItems:
Line 153... Line 154...
153
            <th>Snapdeal Commission %</th>
154
            <th>Snapdeal Commission %</th>
154
            <th>Our System Weight</th>
155
            <th>Our System Weight</th>
155
            <th>Snapdeal Weight</th>
156
            <th>Snapdeal Weight</th>
156
            <th>Our Courier Cost</th>
157
            <th>Our Courier Cost</th>
157
            <th>Snapdeal Courier Charges</th>
158
            <th>Snapdeal Courier Charges</th>
-
 
159
            <th>Reason</th>
158
            </tr></thead>
160
            </tr></thead>
159
            <tbody>"""
161
            <tbody>"""
160
    for data in filteredData:
162
    for data in filteredData:
161
        if data.transferPriceSnapdeal < data.transferPrice:
163
        if data.transferPriceSnapdeal < data.transferPrice:
162
            message+="""<tr>
164
            message+="""<tr>
Line 172... Line 174...
172
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
174
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
173
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
175
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
174
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
176
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
175
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
177
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
176
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
178
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
-
 
179
            <td style="text-align:center">"""+getReason(data)+"""</td>
177
            </tr>"""
180
            </tr>"""
178
    message+="""</tbody></table>"""
181
    message+="""</tbody></table>"""
179
    message+="""
182
    message+="""
180
            <h3>High TP On Snapdeal</h3>
183
            <h3>High TP On Snapdeal</h3>
181
            <table border="1" style="width:100%;">
184
            <table border="1" style="width:100%;">
Line 192... Line 195...
192
            <th>Snapdeal Commission %</th>
195
            <th>Snapdeal Commission %</th>
193
            <th>Our System Weight</th>
196
            <th>Our System Weight</th>
194
            <th>Snapdeal Weight</th>
197
            <th>Snapdeal Weight</th>
195
            <th>Our Courier Cost</th>
198
            <th>Our Courier Cost</th>
196
            <th>Snapdeal Courier Charges</th>
199
            <th>Snapdeal Courier Charges</th>
-
 
200
            <th>Reason</th>
197
            </tr></thead>
201
            </tr></thead>
198
            <tbody>"""
202
            <tbody>"""
199
    for data in filteredData:
203
    for data in filteredData:
200
        if data.transferPriceSnapdeal >= data.transferPrice:
204
        if data.transferPriceSnapdeal >= data.transferPrice:
201
            message+="""<tr>
205
            message+="""<tr>
Line 211... Line 215...
211
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
215
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
212
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
216
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
213
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
217
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
214
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
218
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
215
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
219
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
-
 
220
            <td style="text-align:center">"""+getReason(data)+"""</td>
216
            </tr>"""
221
            </tr>"""
217
    message+="""</tbody></table>"""
222
    message+="""</tbody></table>"""
218
    message+="""
223
    message+="""
219
            <h3>Unable To Fetch Items</h3>
224
            <h3>Unable To Fetch Items</h3>
220
            <table border="1" style="width:100%;">
225
            <table border="1" style="width:100%;">
Line 301... Line 306...
301
    sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
306
    sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
302
    sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
307
    sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
303
    sheet.write(0, 15, "Snapdeal Weight", heading_xf)
308
    sheet.write(0, 15, "Snapdeal Weight", heading_xf)
304
    sheet.write(0, 16, "Our Courier Cost", heading_xf)
309
    sheet.write(0, 16, "Our Courier Cost", heading_xf)
305
    sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
310
    sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
-
 
311
    sheet.write(0, 18, "Reason", heading_xf)
306
    
312
    
307
    sheet_iterator=1
313
    sheet_iterator=1
308
    for data in filteredData:
314
    for data in filteredData:
309
        if data.transferPriceSnapdeal < data.transferPrice:
315
        if data.transferPriceSnapdeal < data.transferPrice:
310
            sheet.write(sheet_iterator, 0, data.itemId)
316
            sheet.write(sheet_iterator, 0, data.itemId)
Line 323... Line 329...
323
            sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
329
            sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
324
            sheet.write(sheet_iterator, 14, data.weight*1000)
330
            sheet.write(sheet_iterator, 14, data.weight*1000)
325
            sheet.write(sheet_iterator, 15, data.weightSnapdeal)
331
            sheet.write(sheet_iterator, 15, data.weightSnapdeal)
326
            sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
332
            sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
327
            sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
333
            sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
-
 
334
            sheet.write(sheet_iterator, 18, getReason(data))
328
            sheet_iterator+=1
335
            sheet_iterator+=1
329
    
336
    
330
    sheet = wbk.add_sheet('High TP SD')
337
    sheet = wbk.add_sheet('High TP SD')
331
 
338
 
332
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
339
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 352... Line 359...
352
    sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
359
    sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
353
    sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
360
    sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
354
    sheet.write(0, 15, "Snapdeal Weight", heading_xf)
361
    sheet.write(0, 15, "Snapdeal Weight", heading_xf)
355
    sheet.write(0, 16, "Our Courier Cost", heading_xf)
362
    sheet.write(0, 16, "Our Courier Cost", heading_xf)
356
    sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
363
    sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
-
 
364
    sheet.write(0, 18, "Reason", heading_xf)
357
    
365
    
358
    sheet_iterator=1
366
    sheet_iterator=1
359
    for data in filteredData:
367
    for data in filteredData:
360
        if data.transferPriceSnapdeal > data.transferPrice:
368
        if data.transferPriceSnapdeal > data.transferPrice:
361
            sheet.write(sheet_iterator, 0, data.itemId)
369
            sheet.write(sheet_iterator, 0, data.itemId)
Line 374... Line 382...
374
            sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
382
            sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
375
            sheet.write(sheet_iterator, 14, data.weight*1000)
383
            sheet.write(sheet_iterator, 14, data.weight*1000)
376
            sheet.write(sheet_iterator, 15, data.weightSnapdeal)
384
            sheet.write(sheet_iterator, 15, data.weightSnapdeal)
377
            sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
385
            sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
378
            sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
386
            sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
-
 
387
            sheet.write(sheet_iterator, 18, getReason(data))
379
            sheet_iterator+=1
388
            sheet_iterator+=1
380
    
389
    
381
    sheet = wbk.add_sheet('Exceptions')
390
    sheet = wbk.add_sheet('Exceptions')
382
 
391
 
383
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
392
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 441... Line 450...
441
        try:
450
        try:
442
            smtpServer.sendmail(sender, recipients, msg.as_string())
451
            smtpServer.sendmail(sender, recipients, msg.as_string())
443
            print "Successfully sent email"
452
            print "Successfully sent email"
444
        except:
453
        except:
445
            print "Error: unable to send email."
454
            print "Error: unable to send email."
446
        
-
 
447
        
-
 
448
    
-
 
449
    
-
 
450
    
-
 
451
    
-
 
452
    
-
 
453
    
-
 
454
    
-
 
455
    
-
 
456
            
-
 
457
            
-
 
458
        
-
 
459
 
455
 
-
 
456
def getReason(data):
-
 
457
    reason=""
-
 
458
    if data.sellingPrice!=data.sellingPriceSnapdeal:
-
 
459
        reason+="Selling Price is different."
-
 
460
    if data.commission!= round(data.fixedMargin*1.1236,2):
-
 
461
        reason+="Commission is different"
-
 
462
    if round(data.courierCost)!=round(data.logisticCostSnapdeal):
-
 
463
        reason+="Courier Cost is different-Check Weight."
-
 
464
    return reason
-
 
465
        
460
 
466
 
461
def main():
467
def main():
462
    print "Opening snapdeal seller login page"
468
    print "Opening snapdeal seller login page"
463
    br = login("http://selleraccounts.snapdeal.com/")
469
    br = login("http://selleraccounts.snapdeal.com/")
464
    exceptionList, fetchedItems = populateStuff(br)
470
    exceptionList, fetchedItems = populateStuff(br)