Subversion Repositories SmartDukaan

Rev

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