Subversion Repositories SmartDukaan

Rev

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

Rev 9411 Rev 9426
Line 24... Line 24...
24
    sys.path.insert(0, os.getcwd())
24
    sys.path.insert(0, os.getcwd())
25
 
25
 
26
 
26
 
27
class _SnapdealItemInfo:
27
class _SnapdealItemInfo:
28
    
28
    
29
    def __init__(self, item_id, product_group, category_name, our_nlc, brand, model_name, model_number, color, weight, parent_category, risky):
29
    def __init__(self, item_id, product_group, category_name, our_nlc, brand, model_name, model_number, color, weight, parent_category, risky, issue):
30
        self.item_id = item_id
30
        self.item_id = item_id
31
        self.product_group = product_group
31
        self.product_group = product_group
32
        self.category_name = category_name
32
        self.category_name = category_name
33
        self.our_nlc = our_nlc
33
        self.our_nlc = our_nlc
34
        self.brand = brand
34
        self.brand = brand
Line 36... Line 36...
36
        self.model_number = model_number
36
        self.model_number = model_number
37
        self.color = color
37
        self.color = color
38
        self.weight = weight
38
        self.weight = weight
39
        self.parent_category = parent_category
39
        self.parent_category = parent_category
40
        self.risky = risky
40
        self.risky = risky
-
 
41
        self.issue = issue
41
        
42
        
42
 
43
 
43
class SnapdealDetails:
44
class SnapdealDetails:
44
    def __init__(self, supc, ourSp, offerPrice, ourInventory, otherInventory, rank, lowestSellerName,lowestSp,secondLowestSellerName,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice):
45
    def __init__(self, supc, ourSp, offerPrice, ourInventory, otherInventory, rank, lowestSellerName,lowestSp,secondLowestSellerName,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice):
45
        self.supc = supc
46
        self.supc = supc
Line 121... Line 122...
121
        print sheet.row_values(rownum)
122
        print sheet.row_values(rownum)
122
        item_id = int(sheet.row_values(rownum)[0])
123
        item_id = int(sheet.row_values(rownum)[0])
123
        supc = sheet.row_values(rownum)[1]
124
        supc = sheet.row_values(rownum)[1]
124
        item = Item.query.filter_by(id=item_id).one()
125
        item = Item.query.filter_by(id=item_id).one()
125
        category = Category.query.filter_by(id=item.category).one()
126
        category = Category.query.filter_by(id=item.category).one()
126
        parent_category = Category.query.filter_by(parent_category_id=category.parent_category_id).one()
127
        parent_category = Category.query.filter_by(parent_category_id=category.parent_category_id).first()
-
 
128
        try:
127
        snapdeal_item = SnapdealItem.query.filter_by(item_id=item_id).one()
129
            snapdeal_item = SnapdealItem.query.filter_by(item_id=item_id).one()
128
        warehouse = iclient.getWarehouse(snapdeal_item.warehouseId)
130
            warehouse = iclient.getWarehouse(snapdeal_item.warehouseId)
129
        item_pricing = iclient.getItemPricing(item_id, warehouse.vendor.id)
131
            item_pricing = iclient.getItemPricing(item_id, warehouse.vendor.id)
-
 
132
            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,"")
-
 
133
        except Exception as e:
-
 
134
            print "Problem with item id ",item_id
-
 
135
            print e
-
 
136
            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")
-
 
137
            
130
        #TO BE USED LATER
138
        #TO BE USED LATER
131
        #inventory_snapshot = iclient.getInventorySnapshot(0)
139
        #inventory_snapshot = iclient.getInventorySnapshot(0)
132
        #warehouses_ours = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("OURS"), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
140
        #warehouses_ours = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("OURS"), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
133
        #warehouses_third_party = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("THIRD_PARTY "), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
141
        #warehouses_third_party = iclient.getWarehouses(WarehouseType._NAMES_TO_VALUES.get("THIRD_PARTY "), InventoryType._NAMES_TO_VALUES.get("GOOD"), 0,0,0)
134
        one_line = _SnapdealItemInfo(item.id, item.product_group, parent_category.displayName, item_pricing.nlc, item.brand, item.model_name, item.model_number, item.color, item.weight, category.parent_category_id, item.risky)
-
 
135
        all_supc.append(supc)
142
        all_supc.append(supc)
136
        all_lines.append(one_line)
143
        all_lines.append(one_line)
137
    write_report("/tmp/snapdeal_running.xls", all_lines, all_supc)
144
    write_report("/tmp/snapdeal_running.xls", all_lines, all_supc)
138
    
145
    
-
 
146
 
-
 
147
def exception_sheet(items,wbk):
-
 
148
    sheet = wbk.add_sheet('Exception Item List')
-
 
149
 
-
 
150
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
-
 
151
    
-
 
152
    excel_integer_format = '0'
-
 
153
    integer_style = xlwt.XFStyle()
-
 
154
    integer_style.num_format_str = excel_integer_format
-
 
155
    
-
 
156
    sheet.write(0, 0, "Item ID", heading_xf)
-
 
157
    sheet.write(0, 1, "Problem Type", heading_xf)
139
    
158
    
-
 
159
    i=1
-
 
160
    for item in items:
-
 
161
        sheet.write(i, 0, item.item_id)
-
 
162
        if len(item.issue)!=0:
-
 
163
            sheet.write(i, 0, "Either Snapdeal item is not present on our end or wrong warehouse Id")
-
 
164
        else:
-
 
165
            sheet.write(i, 1, "Unable to fetch info from snapdeal server")
-
 
166
        i+=1
-
 
167
    
-
 
168
    
-
 
169
    
-
 
170
 
140
 
171
 
141
def write_report(filename, all_lines, all_supc):
172
def write_report(filename, all_lines, all_supc):
142
    
173
    
143
    buyBoxItems = []
174
    buyBoxItems = []
144
    competitive = []
175
    competitive = []
145
    competitiveNoInventory = []
176
    competitiveNoInventory = []
-
 
177
    exceptionItems = []
146
    
178
    
147
    wbk = xlwt.Workbook()
179
    wbk = xlwt.Workbook()
148
    sheet = wbk.add_sheet('Can\'t Compete')
180
    sheet = wbk.add_sheet('Can\'t Compete')
149
 
181
 
150
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
182
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 184... Line 216...
184
    sheet.write(0, 28, "Target NLC", heading_xf)
216
    sheet.write(0, 28, "Target NLC", heading_xf)
185
    sheet.write(0, 29, "Sales Potential", heading_xf)
217
    sheet.write(0, 29, "Sales Potential", heading_xf)
186
    
218
    
187
    i, sheet_iterator=1,1
219
    i, sheet_iterator=1,1
188
    for one_line in all_lines:
220
    for one_line in all_lines:
-
 
221
        if len(one_line.issue)!=0:
-
 
222
            exceptionItems.append(one_line)
-
 
223
            i+=1
-
 
224
            continue
189
        supc = all_supc[i-1]
225
        supc = all_supc[i-1]
-
 
226
        try:
190
        supc_data = fetchDetails(supc)
227
            supc_data = fetchDetails(supc)
-
 
228
        except Exception as e:
-
 
229
            print "Unable to get information about SUPC Code: ",supc
-
 
230
            exceptionItems.append(one_line)
-
 
231
            i+=1
-
 
232
            continue
191
        
233
        
192
        courierCost = 45
234
        courierCost = 45
193
        
235
        
194
        if one_line.weight:
236
        if one_line.weight:
195
            slab = int(((one_line.weight+0.05) - .001)/.5)
237
            slab = int(((one_line.weight+0.05) - .001)/.5)
Line 297... Line 339...
297
        sheet_iterator+=1
339
        sheet_iterator+=1
298
        
340
        
299
    createSheetForBuyBoxItems(buyBoxItems,wbk)
341
    createSheetForBuyBoxItems(buyBoxItems,wbk)
300
    createSheetForCometitiveItems(competitive,wbk)
342
    createSheetForCometitiveItems(competitive,wbk)
301
    createSheetForCometitiveItemsNoInventory(competitiveNoInventory,wbk)
343
    createSheetForCometitiveItemsNoInventory(competitiveNoInventory,wbk)
-
 
344
    exception_sheet(exceptionItems,wbk)
302
    wbk.save(filename)
345
    wbk.save(filename)
303
    
346
    
304
    EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@shop2020.in"], " " , "", [get_attachment_part(filename)], ["kshitij.sood@shop2020.in"], [])
347
    EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@shop2020.in"], " " , "", [get_attachment_part(filename)], ["kshitij.sood@shop2020.in"], [])
305
 
348
 
306
    
349