Subversion Repositories SmartDukaan

Rev

Rev 9485 | Rev 9488 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9334 kshitij.so 1
#!/usr/bin/python
2
# coding: ascii
3
from elixir import *
4
from shop2020.model.v1.catalog.impl import DataService
5
from shop2020.model.v1.catalog.impl.DataService import Item, Category,\
6
    SnapdealItem
9359 kshitij.so 7
from shop2020.thriftpy.model.v1.inventory import ttypes
8
from shop2020.thriftpy.model.v1.inventory.ttypes import WarehouseType, InventoryType
9334 kshitij.so 9
import optparse
10
import xlrd
11
from shop2020.clients.InventoryClient import InventoryClient
12
import xlwt
13
import urllib2
14
import time
15
import simplejson as json
9365 kshitij.so 16
from shop2020.utils import EmailAttachmentSender
17
from shop2020.utils.EmailAttachmentSender import get_attachment_part
9334 kshitij.so 18
 
19
 
9365 kshitij.so 20
 
9334 kshitij.so 21
if __name__ == '__main__' and __package__ is None:
22
    import sys
23
    import os
24
    sys.path.insert(0, os.getcwd())
25
 
26
 
27
class _SnapdealItemInfo:
28
 
9426 kshitij.so 29
    def __init__(self, item_id, product_group, category_name, our_nlc, brand, model_name, model_number, color, weight, parent_category, risky, issue):
9334 kshitij.so 30
        self.item_id = item_id
31
        self.product_group = product_group
32
        self.category_name = category_name
33
        self.our_nlc = our_nlc
34
        self.brand = brand
35
        self.model_name = model_name
36
        self.model_number = model_number
37
        self.color = color
38
        self.weight = weight
39
        self.parent_category = parent_category
9359 kshitij.so 40
        self.risky = risky
9426 kshitij.so 41
        self.issue = issue
9334 kshitij.so 42
 
43
 
44
class SnapdealDetails:
9359 kshitij.so 45
    def __init__(self, supc, ourSp, offerPrice, ourInventory, otherInventory, rank, lowestSellerName,lowestSp,secondLowestSellerName,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice):
9334 kshitij.so 46
        self.supc = supc
47
        self.ourSp = ourSp
48
        self.offerPrice = offerPrice
49
        self.ourInventory = ourInventory
50
        self.otherInventory = otherInventory
51
        self.rank = rank
52
        self.lowestSellerName = lowestSellerName
53
        self.lowestSp = lowestSp
54
        self.secondLowestSellerName = secondLowestSellerName
55
        self.secondLowestSellerSp = secondLowestSellerSp
56
        self.secondLowestSellerInventory = secondLowestSellerInventory
9359 kshitij.so 57
        self.lowestOfferPrice = lowestOfferPrice
58
        self.secondLowestSellerOfferPrice = secondLowestSellerOfferPrice
59
        self.ourOfferPrice = ourOfferPrice
9334 kshitij.so 60
 
61
 
62
def fetchDetails(supc_code):
63
    url="http://www.snapdeal.com/json/gvbps?supc=%s&catId=91"%(supc_code)
64
    print url
65
    time.sleep(2)
66
    req = urllib2.Request(url)
67
    response = urllib2.urlopen(req)
68
    json_input = response.read()
69
    vendorInfo = json.loads(json_input)
70
    rank ,otherInventory ,ourInventory, offerPrice, ourSp,iterator = 0, 0, 0, 0, 0, 0
9337 kshitij.so 71
    secondLowestSellerName=''
72
    secondLowestSellerSp=0
73
    secondLowestSellerInventory=0
9359 kshitij.so 74
    lowestOfferPrice = 0
75
    secondLowestSellerOfferPrice = 0
76
    ourOfferPrice = 0
9334 kshitij.so 77
    for vendor in vendorInfo:
78
        if iterator == 0:
79
            lowestSellerName = vendor['vendorDisplayName']
9362 kshitij.so 80
            try:
81
                lowestSp = vendor['sellingPriceBefIntCashBack']
82
            except:
83
                lowestSp = vendor['sellingPrice']
9359 kshitij.so 84
            lowestOfferPrice = vendor['sellingPrice']
9334 kshitij.so 85
 
86
        if iterator ==1:
87
            secondLowestSellerName = vendor['vendorDisplayName']
9362 kshitij.so 88
            try:
89
                secondLowestSellerSp = vendor['sellingPriceBefIntCashBack']
90
            except:
91
                secondLowestSellerSp = vendor['sellingPrice'] 
9359 kshitij.so 92
            secondLowestSellerOfferPrice = vendor['sellingPrice'] 
9334 kshitij.so 93
            secondLowestSellerInventory = vendor['buyableInventory']
94
 
95
        if vendor['vendorDisplayName'] == 'MobilesnMore':
96
            ourInventory = vendor['buyableInventory']
9362 kshitij.so 97
            try:
98
                ourSp = vendor['sellingPriceBefIntCashBack']
99
            except:
100
                ourSp = vendor['sellingPrice']
9359 kshitij.so 101
            ourOfferPrice = vendor['sellingPrice']
9334 kshitij.so 102
            rank = iterator +1
103
        else:
104
            if rank==0:
105
                otherInventory = otherInventory +vendor['buyableInventory']
106
 
107
        iterator+=1
9359 kshitij.so 108
    snapdealDetails = SnapdealDetails(supc_code,ourSp,offerPrice,ourInventory,otherInventory,rank,lowestSellerName,lowestSp,secondLowestSellerName,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice)
9334 kshitij.so 109
    return snapdealDetails
110
 
111
 
112
def read_data(filename):
113
    all_lines = []
114
    all_supc=[]
115
    iclient = InventoryClient().get_client()
9337 kshitij.so 116
    DataService.initialize('catalog','192.168.166.135')
9334 kshitij.so 117
    workbook = xlrd.open_workbook(filename)
118
    sheet = workbook.sheet_by_index(0)
119
    num_rows = sheet.nrows
120
    for rownum in range(1, num_rows):
121
        print sheet.row_values(rownum)
9453 kshitij.so 122
        try:
9454 kshitij.so 123
            item_id = int(sheet.row_values(rownum)[0])
9487 kshitij.so 124
            print "sku is",item_id
9454 kshitij.so 125
            supc = sheet.row_values(rownum)[1]
9487 kshitij.so 126
            print "supc is",supc
9453 kshitij.so 127
            item = Item.query.filter_by(id=item_id).one()
128
        except Exception as e:
9483 kshitij.so 129
            print "No item found.Maybe due to snapdeal item code in place of our sku id.Lets try again."
9453 kshitij.so 130
            print e
9483 kshitij.so 131
            try:
132
                item_id = sheet.row_values(rownum)[0]
9487 kshitij.so 133
                print "sku is",item_id
9483 kshitij.so 134
                snapdeal_item = SnapdealItem.query.filter_by(skuAtSnapdeal=item_id).one()
135
                item = Item.query.filter_by(id=snapdeal_item.item_id).one()
9487 kshitij.so 136
                print "item is",item.id
9483 kshitij.so 137
            except Exception as ex:
138
                print "Ahh...Still unable to find"
139
                print ex
140
                one_line = _SnapdealItemInfo(sheet.row_values(rownum)[0], '', '', 0, '', '','', '', 0, '', False,"item_related")
9487 kshitij.so 141
                print "appending supc",supc
9483 kshitij.so 142
                all_supc.append(supc)
143
                all_lines.append(one_line)
144
                continue
9453 kshitij.so 145
 
9485 vikram.rag 146
        category = Category.query.filter_by(id=item.category).one()
9426 kshitij.so 147
        parent_category = Category.query.filter_by(parent_category_id=category.parent_category_id).first()
148
        try:
9485 vikram.rag 149
            snapdeal_item = SnapdealItem.query.filter_by(item_id=item.id).one()
9426 kshitij.so 150
            warehouse = iclient.getWarehouse(snapdeal_item.warehouseId)
9484 kshitij.so 151
            item_pricing = iclient.getItemPricing(item.id, warehouse.vendor.id)
9426 kshitij.so 152
            one_line = _SnapdealItemInfo(item.id, item.product_group, parent_category.display_name, item_pricing.nlc, item.brand, item.model_name, item.model_number, item.color, item.weight, category.parent_category_id, item.risky,"")
153
        except Exception as e:
9484 kshitij.so 154
            print "Problem with item id ",item.id
9426 kshitij.so 155
            print e
156
            one_line = _SnapdealItemInfo(item.id, item.product_group, parent_category.display_name, item_pricing.nlc, item.brand, item.model_name, item.model_number, item.color, item.weight, category.parent_category_id, item.risky,"our_side")
157
 
9359 kshitij.so 158
        #TO BE USED LATER
159
        #inventory_snapshot = iclient.getInventorySnapshot(0)
160
        #warehouses_ours = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("OURS"), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
161
        #warehouses_third_party = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("THIRD_PARTY "), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
9487 kshitij.so 162
        print "supc is final append",supc
163
        print "item id",one_line.item_id
9334 kshitij.so 164
        all_supc.append(supc)
165
        all_lines.append(one_line)
166
    write_report("/tmp/snapdeal_running.xls", all_lines, all_supc)
167
 
9426 kshitij.so 168
 
169
def exception_sheet(items,wbk):
170
    sheet = wbk.add_sheet('Exception Item List')
171
 
172
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
9334 kshitij.so 173
 
9426 kshitij.so 174
    excel_integer_format = '0'
175
    integer_style = xlwt.XFStyle()
176
    integer_style.num_format_str = excel_integer_format
177
 
178
    sheet.write(0, 0, "Item ID", heading_xf)
179
    sheet.write(0, 1, "Problem Type", heading_xf)
180
 
181
    i=1
182
    for item in items:
183
        sheet.write(i, 0, item.item_id)
184
        if len(item.issue)!=0:
9457 kshitij.so 185
            sheet.write(i, 1, "Wrong item id or wrong warehouse Id")
9426 kshitij.so 186
        else:
187
            sheet.write(i, 1, "Unable to fetch info from snapdeal server")
188
        i+=1
189
 
190
 
191
 
9334 kshitij.so 192
 
9426 kshitij.so 193
 
9334 kshitij.so 194
def write_report(filename, all_lines, all_supc):
195
 
196
    buyBoxItems = []
9387 kshitij.so 197
    competitive = []
9396 kshitij.so 198
    competitiveNoInventory = []
9426 kshitij.so 199
    exceptionItems = []
9451 kshitij.so 200
    negativeMargin = []
9334 kshitij.so 201
 
202
    wbk = xlwt.Workbook()
9396 kshitij.so 203
    sheet = wbk.add_sheet('Can\'t Compete')
9334 kshitij.so 204
 
205
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
206
 
207
    excel_integer_format = '0'
208
    integer_style = xlwt.XFStyle()
209
    integer_style.num_format_str = excel_integer_format
210
 
211
    sheet.write(0, 0, "Item ID", heading_xf)
212
    sheet.write(0, 1, "Category", heading_xf)
213
    sheet.write(0, 2, "Product Group.", heading_xf)
214
    sheet.write(0, 3, "SUPC", heading_xf)
215
    sheet.write(0, 4, "Brand", heading_xf)
216
    sheet.write(0, 5, "Model Name", heading_xf)
217
    sheet.write(0, 6, "Model Number", heading_xf)
218
    sheet.write(0, 7, "Color", heading_xf)
9359 kshitij.so 219
    sheet.write(0, 8, "Weight", heading_xf)
9400 kshitij.so 220
    sheet.write(0, 9, "Courier Cost", heading_xf)
9399 kshitij.so 221
    sheet.write(0, 10, "Risky", heading_xf)
222
    sheet.write(0, 11, "Our SP", heading_xf)
9411 kshitij.so 223
    sheet.write(0, 13, "Our TP", heading_xf)
224
    sheet.write(0, 12, "Our Offer Price", heading_xf)
9399 kshitij.so 225
    sheet.write(0, 14, "Our Rank", heading_xf)
226
    sheet.write(0, 15, "Lowest Seller", heading_xf)
227
    sheet.write(0, 16, "Lowest SP", heading_xf)
228
    sheet.write(0, 17, "Lowest TP", heading_xf)
229
    sheet.write(0, 18, "Lowest Offer Price", heading_xf)
230
    sheet.write(0, 19, "Inventory of Top Vendors", heading_xf)
231
    sheet.write(0, 20, "Our Snapdeal Inventory", heading_xf)
232
    sheet.write(0, 21, "Our NLC", heading_xf)
233
    sheet.write(0, 22, "Lowest Possible TP", heading_xf)
234
    sheet.write(0, 23, "Lowest Possible SP", heading_xf)
235
    sheet.write(0, 24, "Competition Basis ", heading_xf)
236
    sheet.write(0, 25, "Can Compete", heading_xf)
237
    sheet.write(0, 26, "Target TP", heading_xf)
238
    sheet.write(0, 27, "Target SP", heading_xf)  
239
    sheet.write(0, 28, "Target NLC", heading_xf)
240
    sheet.write(0, 29, "Sales Potential", heading_xf)
9334 kshitij.so 241
 
9337 kshitij.so 242
    i, sheet_iterator=1,1
9334 kshitij.so 243
    for one_line in all_lines:
9426 kshitij.so 244
        if len(one_line.issue)!=0:
245
            exceptionItems.append(one_line)
246
            i+=1
247
            continue
9334 kshitij.so 248
        supc = all_supc[i-1]
9426 kshitij.so 249
        try:
250
            supc_data = fetchDetails(supc)
251
        except Exception as e:
252
            print "Unable to get information about SUPC Code: ",supc
253
            exceptionItems.append(one_line)
254
            i+=1
255
            continue
9334 kshitij.so 256
 
257
        courierCost = 45
258
 
259
        if one_line.weight:
9381 kshitij.so 260
            slab = int(((one_line.weight+0.05) - .001)/.5)
9334 kshitij.so 261
        for x in range (0,slab):
262
            courierCost = courierCost + 35
263
 
264
        courierCost = courierCost * 1.1236
265
 
9451 kshitij.so 266
        if one_line.parent_category ==10011:
267
            lowestTp = (supc_data.lowestSp*(1-.0803))-courierCost
268
        else:
269
            lowestTp = supc_data.lowestSp*0.9497-courierCost
270
 
271
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
272
 
273
        if (supc_data.ourSp*0.9597-courierCost < lowest_possible_tp):
274
            temp=[]
275
            temp.append(supc_data)
276
            temp.append(one_line)
277
            negativeMargin.append(temp)
278
            i+=1
279
            continue
280
 
9334 kshitij.so 281
        if supc_data.rank==1:
282
            temp = []
283
            temp.append(supc_data)
284
            temp.append(one_line)
285
            buyBoxItems.append(temp)
286
            i+=1
287
            continue
288
 
9387 kshitij.so 289
 
9396 kshitij.so 290
        if (lowestTp > lowest_possible_tp and supc_data.ourInventory!=0):
9387 kshitij.so 291
            temp=[]
292
            temp.append(supc_data)
293
            temp.append(one_line)
294
            competitive.append(temp)
295
            i+=1
296
            continue
297
 
9396 kshitij.so 298
        if (lowestTp > lowest_possible_tp and supc_data.ourInventory==0):
299
            temp=[]
300
            temp.append(supc_data)
301
            temp.append(one_line)
302
            competitiveNoInventory.append(temp)
303
            i+=1
304
            continue
9387 kshitij.so 305
 
9451 kshitij.so 306
 
9337 kshitij.so 307
        sheet.write(sheet_iterator, 0, one_line.item_id)
308
        sheet.write(sheet_iterator, 1, one_line.category_name)
309
        sheet.write(sheet_iterator, 2, one_line.product_group)
310
        sheet.write(sheet_iterator, 3, supc)
311
        sheet.write(sheet_iterator, 4, one_line.brand)
312
        sheet.write(sheet_iterator, 5, one_line.model_name)
313
        sheet.write(sheet_iterator, 6, one_line.model_number)
314
        sheet.write(sheet_iterator, 7, one_line.color)
9359 kshitij.so 315
        sheet.write(sheet_iterator, 8, one_line.weight)
9400 kshitij.so 316
        sheet.write(sheet_iterator, 9, round(courierCost))
9399 kshitij.so 317
        sheet.write(sheet_iterator, 10, one_line.risky)
318
        sheet.write(sheet_iterator, 11, supc_data.ourSp)
9411 kshitij.so 319
        sheet.write(sheet_iterator, 13, round(supc_data.ourSp*0.9597-courierCost))
320
        sheet.write(sheet_iterator, 12, supc_data.ourOfferPrice)
9399 kshitij.so 321
        sheet.write(sheet_iterator, 14, supc_data.rank)
322
        sheet.write(sheet_iterator, 15, supc_data.lowestSellerName)
323
        sheet.write(sheet_iterator, 16, supc_data.lowestSp)
9334 kshitij.so 324
        if one_line.parent_category ==10011:
325
            lowestTp = (supc_data.lowestSp*(1-.0803))-courierCost
326
        else:
327
            lowestTp = supc_data.lowestSp*0.9497-courierCost
9399 kshitij.so 328
        sheet.write(sheet_iterator, 17, round(lowestTp))
329
        sheet.write(sheet_iterator, 18, supc_data.lowestOfferPrice)
330
        sheet.write(sheet_iterator, 19, supc_data.otherInventory)
331
        sheet.write(sheet_iterator, 20, supc_data.ourInventory)
332
        sheet.write(sheet_iterator, 21, one_line.our_nlc)
9334 kshitij.so 333
        if supc_data.rank==1:
334
            i+=1
9337 kshitij.so 335
            sheet_iterator+=1
9334 kshitij.so 336
            continue
337
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
9366 kshitij.so 338
        lowest_possible_sp = (lowest_possible_tp+courierCost)/0.9597
9399 kshitij.so 339
        sheet.write(sheet_iterator, 22, round(lowest_possible_tp))
340
        sheet.write(sheet_iterator, 23, round(lowest_possible_sp))
9390 kshitij.so 341
        competitionBasis ='TP'
9411 kshitij.so 342
        if (supc_data.lowestOfferPrice == supc_data.lowestSp) and supc_data.ourOfferPrice == supc_data.ourSp:
9390 kshitij.so 343
            competitionBasis ='SP'
9399 kshitij.so 344
            sheet.write(sheet_iterator, 24, 'SP')
9366 kshitij.so 345
        else:
9399 kshitij.so 346
            sheet.write(sheet_iterator, 24, 'TP')
9334 kshitij.so 347
        proposed_tp = 0
348
        if lowestTp > lowest_possible_tp:
9399 kshitij.so 349
            sheet.write(sheet_iterator, 25, "Yes")
9334 kshitij.so 350
        else:
9399 kshitij.so 351
            sheet.write(sheet_iterator, 25, "No")
9396 kshitij.so 352
        if competitionBasis=='SP':
9411 kshitij.so 353
            proposed_sp = supc_data.lowestSp - max(10, supc_data.lowestSp*0.001)
9396 kshitij.so 354
            proposed_tp = proposed_sp*0.9597-courierCost
9399 kshitij.so 355
            sheet.write(sheet_iterator, 26, round(proposed_tp))
356
            sheet.write(sheet_iterator, 27, round(proposed_sp))
357
            sheet.write(sheet_iterator, 28, round(proposed_tp*0.988-21)) 
9396 kshitij.so 358
        else:    
9411 kshitij.so 359
            proposed_tp  = lowestTp - max(10, lowestTp*0.001)
9399 kshitij.so 360
            sheet.write(sheet_iterator, 26, round(proposed_tp))
361
            sheet.write(sheet_iterator, 27, round((proposed_tp+courierCost)/0.9597))
362
            sheet.write(sheet_iterator, 28, round(proposed_tp*0.988-21)) 
9381 kshitij.so 363
 
364
 
9366 kshitij.so 365
        if (supc_data.lowestOfferPrice - one_line.our_nlc) < 0:
9399 kshitij.so 366
            sheet.write(sheet_iterator, 29, "HIGH")
9366 kshitij.so 367
        elif (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice >=0 and (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice <= .02:
9399 kshitij.so 368
            sheet.write(sheet_iterator, 29, "MEDIUM")
9366 kshitij.so 369
        else:
9399 kshitij.so 370
            sheet.write(sheet_iterator, 29, "LOW")
9334 kshitij.so 371
        i= i+1
9337 kshitij.so 372
        sheet_iterator+=1
373
 
9334 kshitij.so 374
    createSheetForBuyBoxItems(buyBoxItems,wbk)
9387 kshitij.so 375
    createSheetForCometitiveItems(competitive,wbk)
9396 kshitij.so 376
    createSheetForCometitiveItemsNoInventory(competitiveNoInventory,wbk)
9426 kshitij.so 377
    exception_sheet(exceptionItems,wbk)
9451 kshitij.so 378
    createSheetForNegativeMargin(negativeMargin,wbk)
9334 kshitij.so 379
    wbk.save(filename)
9365 kshitij.so 380
 
9367 kshitij.so 381
    EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@shop2020.in"], " " , "", [get_attachment_part(filename)], ["kshitij.sood@shop2020.in"], [])
9334 kshitij.so 382
 
9365 kshitij.so 383
 
384
 
9334 kshitij.so 385
def createSheetForBuyBoxItems(buyBoxItems,wbk):
9396 kshitij.so 386
    sheet = wbk.add_sheet('Lowest')
9334 kshitij.so 387
 
388
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
389
 
390
    excel_integer_format = '0'
391
    integer_style = xlwt.XFStyle()
392
    integer_style.num_format_str = excel_integer_format
393
 
394
    sheet.write(0, 0, "Item ID", heading_xf)
395
    sheet.write(0, 1, "Category", heading_xf)
396
    sheet.write(0, 2, "Product Group.", heading_xf)
397
    sheet.write(0, 3, "SUPC", heading_xf)
398
    sheet.write(0, 4, "Brand", heading_xf)
399
    sheet.write(0, 5, "Model Name", heading_xf)
400
    sheet.write(0, 6, "Model Number", heading_xf)
401
    sheet.write(0, 7, "Color", heading_xf)
9359 kshitij.so 402
    sheet.write(0, 8, "Weight", heading_xf)
9399 kshitij.so 403
    sheet.write(0, 9, "Courier Cost", heading_xf)
404
    sheet.write(0, 10, "Risky", heading_xf)
405
    sheet.write(0, 11, "Our SP", heading_xf)
9411 kshitij.so 406
    sheet.write(0, 13, "Our TP", heading_xf)
407
    sheet.write(0, 12, "Our Offer Price", heading_xf)
9399 kshitij.so 408
    sheet.write(0, 14, "Our Rank", heading_xf)
409
    sheet.write(0, 15, "Lowest Seller", heading_xf)
410
    sheet.write(0, 16, "Second Lowest Seller", heading_xf)
411
    sheet.write(0, 17, "Second Lowest Price", heading_xf)
412
    sheet.write(0, 18, "Second Lowest Offer Price", heading_xf)
413
    sheet.write(0, 19, "Second Lowest Seller TP", heading_xf)
9396 kshitij.so 414
    sheet.write(0, 20, "Our Snapdeal Inventory", heading_xf)
415
    sheet.write(0, 21, "Second Lowest Seller Inventory", heading_xf)
416
    sheet.write(0, 22, "Our NLC", heading_xf)
417
    sheet.write(0, 23, "Competition Basis", heading_xf)
418
    sheet.write(0, 24, "Target TP", heading_xf)
419
    sheet.write(0, 25, "Target SP", heading_xf)
9411 kshitij.so 420
    sheet.write(0, 26, "MARGIN INCREASED POTENTIAL", heading_xf)
9334 kshitij.so 421
 
422
    i=1
423
 
424
    for data in buyBoxItems:
425
        supc_data =data[0]
426
        one_line = data[1]
427
 
428
        courierCost = 45
429
 
430
        if one_line.weight:
9381 kshitij.so 431
            slab = int(((one_line.weight+0.05) - .001)/.5)
9334 kshitij.so 432
        for x in range (0,slab):
433
            courierCost = courierCost + 35
434
 
435
        courierCost = courierCost * 1.1236
436
 
437
        sheet.write(i, 0, one_line.item_id)
438
        sheet.write(i, 1, one_line.category_name)
439
        sheet.write(i, 2, one_line.product_group)
440
        sheet.write(i, 3, supc_data.supc)
441
        sheet.write(i, 4, one_line.brand)
442
        sheet.write(i, 5, one_line.model_name)
443
        sheet.write(i, 6, one_line.model_number)
444
        sheet.write(i, 7, one_line.color)
9359 kshitij.so 445
        sheet.write(i, 8, one_line.weight)
9400 kshitij.so 446
        sheet.write(i, 9, round(courierCost))
9399 kshitij.so 447
        sheet.write(i, 10, one_line.risky)
448
        sheet.write(i, 11, supc_data.ourSp)
9411 kshitij.so 449
        sheet.write(i, 13, round(supc_data.ourSp*0.9597-courierCost))
450
        sheet.write(i, 12, supc_data.ourOfferPrice)
9399 kshitij.so 451
        sheet.write(i, 14, supc_data.rank)
452
        sheet.write(i, 15, supc_data.lowestSellerName)
453
        sheet.write(i, 16, supc_data.secondLowestSellerName)
454
        sheet.write(i, 17, supc_data.secondLowestSellerSp)
455
        sheet.write(i, 18, supc_data.secondLowestSellerOfferPrice)
9334 kshitij.so 456
        if one_line.parent_category ==10011:
9396 kshitij.so 457
            secondlowestTp = (supc_data.secondLowestSellerSp*(1-.0803))-courierCost
9334 kshitij.so 458
        else:
9396 kshitij.so 459
            secondlowestTp = supc_data.secondLowestSellerSp*0.9497-courierCost
9381 kshitij.so 460
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
9396 kshitij.so 461
        lowest_possible_sp = (lowest_possible_tp+courierCost)/0.9597
9401 kshitij.so 462
        sheet.write(i, 19, round(secondlowestTp))
9396 kshitij.so 463
        sheet.write(i, 20, supc_data.ourInventory)
464
        sheet.write(i, 21, supc_data.secondLowestSellerInventory)
465
        sheet.write(i, 22, one_line.our_nlc)
466
 
467
        competitionBasis ='TP'
9411 kshitij.so 468
        if (supc_data.secondLowestSellerOfferPrice == supc_data.secondLowestSellerSp) and supc_data.ourOfferPrice==supc_data.ourSp:
9396 kshitij.so 469
            competitionBasis ='SP'
470
            sheet.write(i, 23, 'SP')
471
        else:
472
            sheet.write(i, 23, 'TP')
473
 
474
        if competitionBasis=='SP':
475
            proposed_sp = max(supc_data.secondLowestSellerSp - max((20, supc_data.secondLowestSellerSp*0.002)), lowest_possible_sp)
476
            proposed_tp = proposed_sp*0.9597-courierCost
477
            sheet.write(i, 24, round(proposed_tp))
478
            sheet.write(i, 25, round(proposed_sp))
479
        else:    
480
            proposed_tp  = max(secondlowestTp - max((20, secondlowestTp*0.002)), lowest_possible_tp)
481
            sheet.write(i, 24, round(proposed_tp))
482
            sheet.write(i, 25, round((proposed_tp+courierCost)/0.9597))
483
 
9411 kshitij.so 484
        sheet.write(i, 26, round(proposed_tp-(supc_data.ourSp*0.9597-courierCost)))     
9334 kshitij.so 485
        i+=1
9387 kshitij.so 486
 
487
 
488
def createSheetForCometitiveItems(competitiveItems,wbk):
9396 kshitij.so 489
    sheet = wbk.add_sheet('Can Compete-With Inventory')
9387 kshitij.so 490
 
491
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
9334 kshitij.so 492
 
9387 kshitij.so 493
    excel_integer_format = '0'
494
    integer_style = xlwt.XFStyle()
495
    integer_style.num_format_str = excel_integer_format
496
 
497
    sheet.write(0, 0, "Item ID", heading_xf)
498
    sheet.write(0, 1, "Category", heading_xf)
499
    sheet.write(0, 2, "Product Group.", heading_xf)
500
    sheet.write(0, 3, "SUPC", heading_xf)
501
    sheet.write(0, 4, "Brand", heading_xf)
502
    sheet.write(0, 5, "Model Name", heading_xf)
503
    sheet.write(0, 6, "Model Number", heading_xf)
504
    sheet.write(0, 7, "Color", heading_xf)
505
    sheet.write(0, 8, "Weight", heading_xf)
9399 kshitij.so 506
    sheet.write(0, 9, "Courier Cost", heading_xf)
507
    sheet.write(0, 10, "Risky", heading_xf)
508
    sheet.write(0, 11, "Our SP", heading_xf)
9411 kshitij.so 509
    sheet.write(0, 13, "Our TP", heading_xf)
510
    sheet.write(0, 12, "Our Offer Price", heading_xf)
9399 kshitij.so 511
    sheet.write(0, 14, "Our Rank", heading_xf)
512
    sheet.write(0, 15, "Lowest Seller", heading_xf)
513
    sheet.write(0, 16, "Lowest SP", heading_xf)
514
    sheet.write(0, 17, "Lowest TP", heading_xf)
515
    sheet.write(0, 18, "Lowest Offer Price", heading_xf)
516
    sheet.write(0, 19, "Inventory of Top Vendors", heading_xf)
517
    sheet.write(0, 20, "Our Snapdeal Inventory", heading_xf)
518
    sheet.write(0, 21, "Our NLC", heading_xf)
519
    sheet.write(0, 22, "Lowest Possible TP", heading_xf)
520
    sheet.write(0, 23, "Lowest Possible SP", heading_xf)
521
    sheet.write(0, 24, "Competition Basis ", heading_xf)
522
    sheet.write(0, 25, "Can Compete", heading_xf)
523
    sheet.write(0, 26, "Target TP", heading_xf)
524
    sheet.write(0, 27, "Target SP", heading_xf)  
525
    sheet.write(0, 28, "Sales Potential", heading_xf)
9387 kshitij.so 526
 
527
    i, sheet_iterator=1,1
528
    for data in competitiveItems:
529
        supc_data =data[0]
530
        one_line = data[1]
531
 
532
        courierCost = 45
533
 
534
        if one_line.weight:
535
            slab = int(((one_line.weight+0.05) - .001)/.5)
536
        for x in range (0,slab):
537
            courierCost = courierCost + 35
538
 
539
        courierCost = courierCost * 1.1236
540
 
541
 
542
        sheet.write(sheet_iterator, 0, one_line.item_id)
543
        sheet.write(sheet_iterator, 1, one_line.category_name)
544
        sheet.write(sheet_iterator, 2, one_line.product_group)
545
        sheet.write(sheet_iterator, 3, supc_data.supc)
546
        sheet.write(sheet_iterator, 4, one_line.brand)
547
        sheet.write(sheet_iterator, 5, one_line.model_name)
548
        sheet.write(sheet_iterator, 6, one_line.model_number)
549
        sheet.write(sheet_iterator, 7, one_line.color)
550
        sheet.write(sheet_iterator, 8, one_line.weight)
9400 kshitij.so 551
        sheet.write(sheet_iterator, 9, round(courierCost))
9399 kshitij.so 552
        sheet.write(sheet_iterator, 10, one_line.risky)
553
        sheet.write(sheet_iterator, 11, supc_data.ourSp)
9411 kshitij.so 554
        sheet.write(sheet_iterator, 13, round(supc_data.ourSp*0.9597-courierCost))
555
        sheet.write(sheet_iterator, 12, supc_data.ourOfferPrice)
9399 kshitij.so 556
        sheet.write(sheet_iterator, 14, supc_data.rank)
557
        sheet.write(sheet_iterator, 15, supc_data.lowestSellerName)
558
        sheet.write(sheet_iterator, 16, supc_data.lowestSp)
9387 kshitij.so 559
        if one_line.parent_category ==10011:
560
            lowestTp = (supc_data.lowestSp*(1-.0803))-courierCost
561
        else:
562
            lowestTp = supc_data.lowestSp*0.9497-courierCost
9399 kshitij.so 563
        sheet.write(sheet_iterator, 17, round(lowestTp))
564
        sheet.write(sheet_iterator, 18, supc_data.lowestOfferPrice)
565
        sheet.write(sheet_iterator, 19, supc_data.otherInventory)
566
        sheet.write(sheet_iterator, 20, supc_data.ourInventory)
567
        sheet.write(sheet_iterator, 21, one_line.our_nlc)
9387 kshitij.so 568
        if supc_data.rank==1:
569
            i+=1
570
            sheet_iterator+=1
571
            continue
572
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
573
        lowest_possible_sp = (lowest_possible_tp+courierCost)/0.9597
9399 kshitij.so 574
        sheet.write(sheet_iterator, 22, round(lowest_possible_tp))
575
        sheet.write(sheet_iterator, 23, round(lowest_possible_sp))
9390 kshitij.so 576
        competitionBasis ='TP'
9411 kshitij.so 577
        if (supc_data.lowestOfferPrice == supc_data.lowestSp) and supc_data.ourOfferPrice==supc_data.ourSp:
9390 kshitij.so 578
            competitionBasis ='SP'
9399 kshitij.so 579
            sheet.write(sheet_iterator, 24, 'SP')
9387 kshitij.so 580
        else:
9399 kshitij.so 581
            sheet.write(sheet_iterator, 24, 'TP')
9387 kshitij.so 582
        proposed_tp = 0
583
        if lowestTp > lowest_possible_tp:
9399 kshitij.so 584
            sheet.write(sheet_iterator, 25, "Yes")
9390 kshitij.so 585
            if competitionBasis=='SP':
586
                proposed_sp = max(supc_data.lowestSp - max((10, supc_data.lowestSp*0.001)), lowest_possible_sp)
9396 kshitij.so 587
                proposed_tp = proposed_sp*.9597-courierCost
9399 kshitij.so 588
                sheet.write(sheet_iterator, 26, round(proposed_tp))
589
                sheet.write(sheet_iterator, 27, round(proposed_sp))
9390 kshitij.so 590
            else:
591
                proposed_tp  = max(lowestTp - max((10, lowestTp*0.001)), lowest_possible_tp)
9399 kshitij.so 592
                sheet.write(sheet_iterator, 26, round(proposed_tp))
593
                sheet.write(sheet_iterator, 27, round((proposed_tp+courierCost)/0.9597))
9387 kshitij.so 594
        else:
9399 kshitij.so 595
            sheet.write(sheet_iterator, 25, "No")
9387 kshitij.so 596
 
597
        if (supc_data.lowestOfferPrice - one_line.our_nlc) < 0:
9399 kshitij.so 598
            sheet.write(sheet_iterator, 28, "HIGH")
9387 kshitij.so 599
        elif (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice >=0 and (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice <= .02:
9399 kshitij.so 600
            sheet.write(sheet_iterator, 28, "MEDIUM")
9387 kshitij.so 601
        else:
9399 kshitij.so 602
            sheet.write(sheet_iterator, 28, "LOW")
9387 kshitij.so 603
        i= i+1
604
        sheet_iterator+=1
9334 kshitij.so 605
 
9396 kshitij.so 606
 
607
def createSheetForCometitiveItemsNoInventory(competitiveNoInventoryItems,wbk):
608
    sheet = wbk.add_sheet('Can Compete-No Inventory')
609
 
610
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
611
 
612
    excel_integer_format = '0'
613
    integer_style = xlwt.XFStyle()
614
    integer_style.num_format_str = excel_integer_format
615
 
616
    sheet.write(0, 0, "Item ID", heading_xf)
617
    sheet.write(0, 1, "Category", heading_xf)
618
    sheet.write(0, 2, "Product Group.", heading_xf)
619
    sheet.write(0, 3, "SUPC", heading_xf)
620
    sheet.write(0, 4, "Brand", heading_xf)
621
    sheet.write(0, 5, "Model Name", heading_xf)
622
    sheet.write(0, 6, "Model Number", heading_xf)
623
    sheet.write(0, 7, "Color", heading_xf)
624
    sheet.write(0, 8, "Weight", heading_xf)
9399 kshitij.so 625
    sheet.write(0, 9, "Courier Cost", heading_xf)
626
    sheet.write(0, 10, "Risky", heading_xf)
627
    sheet.write(0, 11, "Our SP", heading_xf)
9411 kshitij.so 628
    sheet.write(0, 13, "Our TP", heading_xf)
629
    sheet.write(0, 12, "Our Offer Price", heading_xf)
9399 kshitij.so 630
    sheet.write(0, 14, "Our Rank", heading_xf)
631
    sheet.write(0, 15, "Lowest Seller", heading_xf)
632
    sheet.write(0, 16, "Lowest SP", heading_xf)
633
    sheet.write(0, 17, "Lowest TP", heading_xf)
634
    sheet.write(0, 18, "Lowest Offer Price", heading_xf)
635
    sheet.write(0, 19, "Inventory of Top Vendors", heading_xf)
636
    sheet.write(0, 20, "Our Snapdeal Inventory", heading_xf)
637
    sheet.write(0, 21, "Our NLC", heading_xf)
638
    sheet.write(0, 22, "Lowest Possible TP", heading_xf)
639
    sheet.write(0, 23, "Lowest Possible SP", heading_xf)
640
    sheet.write(0, 24, "Competition Basis ", heading_xf)
641
    sheet.write(0, 25, "Can Compete", heading_xf)
642
    sheet.write(0, 26, "Target TP", heading_xf)
643
    sheet.write(0, 27, "Target SP", heading_xf)  
644
    sheet.write(0, 28, "Sales Potential", heading_xf)
9396 kshitij.so 645
 
646
    i, sheet_iterator=1,1
647
    for data in competitiveNoInventoryItems:
648
        supc_data =data[0]
649
        one_line = data[1]
650
 
651
        courierCost = 45
652
 
653
        if one_line.weight:
654
            slab = int(((one_line.weight+0.05) - .001)/.5)
655
        for x in range (0,slab):
656
            courierCost = courierCost + 35
657
 
658
        courierCost = courierCost * 1.1236
659
 
660
 
661
        sheet.write(sheet_iterator, 0, one_line.item_id)
662
        sheet.write(sheet_iterator, 1, one_line.category_name)
663
        sheet.write(sheet_iterator, 2, one_line.product_group)
664
        sheet.write(sheet_iterator, 3, supc_data.supc)
665
        sheet.write(sheet_iterator, 4, one_line.brand)
666
        sheet.write(sheet_iterator, 5, one_line.model_name)
667
        sheet.write(sheet_iterator, 6, one_line.model_number)
668
        sheet.write(sheet_iterator, 7, one_line.color)
669
        sheet.write(sheet_iterator, 8, one_line.weight)
9400 kshitij.so 670
        sheet.write(sheet_iterator, 9, round(courierCost))
9399 kshitij.so 671
        sheet.write(sheet_iterator, 10, one_line.risky)
672
        sheet.write(sheet_iterator, 11, supc_data.ourSp)
9411 kshitij.so 673
        sheet.write(sheet_iterator, 13, '-')
674
        sheet.write(sheet_iterator, 12, supc_data.ourOfferPrice)
9399 kshitij.so 675
        sheet.write(sheet_iterator, 14, supc_data.rank)
676
        sheet.write(sheet_iterator, 15, supc_data.lowestSellerName)
677
        sheet.write(sheet_iterator, 16, supc_data.lowestSp)
9396 kshitij.so 678
        if one_line.parent_category ==10011:
679
            lowestTp = (supc_data.lowestSp*(1-.0803))-courierCost
680
        else:
681
            lowestTp = supc_data.lowestSp*0.9497-courierCost
9399 kshitij.so 682
        sheet.write(sheet_iterator, 17, round(lowestTp))
683
        sheet.write(sheet_iterator, 18, supc_data.lowestOfferPrice)
684
        sheet.write(sheet_iterator, 19, supc_data.otherInventory)
685
        sheet.write(sheet_iterator, 20, supc_data.ourInventory)
686
        sheet.write(sheet_iterator, 21, one_line.our_nlc)
9396 kshitij.so 687
        if supc_data.rank==1:
688
            i+=1
689
            sheet_iterator+=1
690
            continue
691
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
692
        lowest_possible_sp = (lowest_possible_tp+courierCost)/0.9597
9399 kshitij.so 693
        sheet.write(sheet_iterator, 22, round(lowest_possible_tp))
694
        sheet.write(sheet_iterator, 23, round(lowest_possible_sp))
9396 kshitij.so 695
        competitionBasis ='TP'
696
        if (supc_data.lowestOfferPrice == supc_data.lowestSp):
697
            competitionBasis ='SP'
9399 kshitij.so 698
            sheet.write(sheet_iterator, 24, 'SP')
9396 kshitij.so 699
        else:
9399 kshitij.so 700
            sheet.write(sheet_iterator, 24, 'TP')
9396 kshitij.so 701
        proposed_tp = 0
702
        if lowestTp > lowest_possible_tp:
9399 kshitij.so 703
            sheet.write(sheet_iterator, 25, "Yes")
9396 kshitij.so 704
            if competitionBasis=='SP':
705
                proposed_sp = max(supc_data.lowestSp - max((10, supc_data.lowestSp*0.001)), lowest_possible_sp)
706
                proposed_tp = proposed_sp*.9597-courierCost
9399 kshitij.so 707
                sheet.write(sheet_iterator, 26, round(proposed_tp))
708
                sheet.write(sheet_iterator, 27, round(proposed_sp))
9396 kshitij.so 709
            else:
710
                proposed_tp  = max(lowestTp - max((10, lowestTp*0.001)), lowest_possible_tp)
9399 kshitij.so 711
                sheet.write(sheet_iterator, 26, round(proposed_tp))
712
                sheet.write(sheet_iterator, 27, round((proposed_tp+courierCost)/0.9597))
9396 kshitij.so 713
        else:
9399 kshitij.so 714
            sheet.write(sheet_iterator, 25, "No")
9396 kshitij.so 715
 
716
        if (supc_data.lowestOfferPrice - one_line.our_nlc) < 0:
9399 kshitij.so 717
            sheet.write(sheet_iterator, 28, "HIGH")
9396 kshitij.so 718
        elif (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice >=0 and (supc_data.lowestOfferPrice - one_line.our_nlc)/supc_data.lowestOfferPrice <= .02:
9399 kshitij.so 719
            sheet.write(sheet_iterator, 28, "MEDIUM")
9396 kshitij.so 720
        else:
9399 kshitij.so 721
            sheet.write(sheet_iterator, 28, "LOW")
9396 kshitij.so 722
        i= i+1
723
        sheet_iterator+=1
724
 
9451 kshitij.so 725
def createSheetForNegativeMargin(negativeMargin,wbk):
726
    sheet = wbk.add_sheet('Negative Margin')
727
 
728
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
9396 kshitij.so 729
 
9451 kshitij.so 730
    excel_integer_format = '0'
731
    integer_style = xlwt.XFStyle()
732
    integer_style.num_format_str = excel_integer_format
733
 
734
    sheet.write(0, 0, "Item ID", heading_xf)
735
    sheet.write(0, 1, "Category", heading_xf)
736
    sheet.write(0, 2, "Product Group.", heading_xf)
737
    sheet.write(0, 3, "SUPC", heading_xf)
738
    sheet.write(0, 4, "Brand", heading_xf)
739
    sheet.write(0, 5, "Model Name", heading_xf)
740
    sheet.write(0, 6, "Model Number", heading_xf)
741
    sheet.write(0, 7, "Color", heading_xf)
742
    sheet.write(0, 8, "Weight", heading_xf)
743
    sheet.write(0, 9, "Courier Cost", heading_xf)
744
    sheet.write(0, 10, "Risky", heading_xf)
745
    sheet.write(0, 11, "Our SP", heading_xf)
746
    sheet.write(0, 13, "Our TP", heading_xf)
747
    sheet.write(0, 12, "Our Offer Price", heading_xf)
748
    sheet.write(0, 14, "Our Rank", heading_xf)
9483 kshitij.so 749
    sheet.write(0, 15, "Our NLC", heading_xf)
750
    sheet.write(0, 16, "Margin", heading_xf)
9451 kshitij.so 751
 
752
    i, sheet_iterator=1,1
753
    for data in negativeMargin:
754
        supc_data =data[0]
755
        one_line = data[1]
756
 
757
        courierCost = 45
758
 
759
        if one_line.weight:
760
            slab = int(((one_line.weight+0.05) - .001)/.5)
761
        for x in range (0,slab):
762
            courierCost = courierCost + 35
763
 
764
        courierCost = courierCost * 1.1236
765
 
9483 kshitij.so 766
        '''if one_line.parent_category ==10011:
767
            lowestTp = (supc_data.lowestSp*(1-.0803))-courierCost
768
        else:
769
            lowestTp = supc_data.lowestSp*0.9497-courierCost
770
        '''
9451 kshitij.so 771
 
9483 kshitij.so 772
        lowest_possible_tp = one_line.our_nlc/0.988+15+6
773
 
9451 kshitij.so 774
        sheet.write(sheet_iterator, 0, one_line.item_id)
775
        sheet.write(sheet_iterator, 1, one_line.category_name)
776
        sheet.write(sheet_iterator, 2, one_line.product_group)
777
        sheet.write(sheet_iterator, 3, supc_data.supc)
778
        sheet.write(sheet_iterator, 4, one_line.brand)
779
        sheet.write(sheet_iterator, 5, one_line.model_name)
780
        sheet.write(sheet_iterator, 6, one_line.model_number)
781
        sheet.write(sheet_iterator, 7, one_line.color)
782
        sheet.write(sheet_iterator, 8, one_line.weight)
783
        sheet.write(sheet_iterator, 9, round(courierCost))
784
        sheet.write(sheet_iterator, 10, one_line.risky)
785
        sheet.write(sheet_iterator, 11, supc_data.ourSp)
9483 kshitij.so 786
        sheet.write(sheet_iterator, 13, round(supc_data.ourSp*0.9597-courierCost))
9451 kshitij.so 787
        sheet.write(sheet_iterator, 12, supc_data.ourOfferPrice)
788
        sheet.write(sheet_iterator, 14, supc_data.rank)
9483 kshitij.so 789
        sheet.write(sheet_iterator, 15, one_line.our_nlc)
790
        sheet.write(sheet_iterator, 16, round((supc_data.ourSp*0.9597-courierCost) - lowest_possible_tp))
9451 kshitij.so 791
        i= i+1
792
        sheet_iterator+=1
793
 
9396 kshitij.so 794
 
9334 kshitij.so 795
def main():
796
    parser = optparse.OptionParser()
797
    parser.add_option("-f", "--file", dest="filename",
798
                   default="ItemList.xls", type="string",
799
                   help="Read the item list from FILE",
800
                   metavar="FILE")
801
    (options, args) = parser.parse_args()
802
    if len(args) != 0:
803
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
804
    filename = options.filename
805
    read_data(filename)
806
 
807
if __name__ == '__main__':
808
    main()
9451 kshitij.so 809