Subversion Repositories SmartDukaan

Rev

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

Rev 11774 Rev 11775
Line 600... Line 600...
600
        mpHistory.prefferedSellerTp = flipkartPricing.prefSellerTp
600
        mpHistory.prefferedSellerTp = flipkartPricing.prefSellerTp
601
        mpHistory.prefferedSellerShippingTime = ''
601
        mpHistory.prefferedSellerShippingTime = ''
602
        mpHistory.prefferedSellerShippingTime= str(flipkartDetails.shippingTimeLowerLimitPrefSeller) if flipkartDetails.shippingTimeUpperLimitPrefSeller==0\
602
        mpHistory.prefferedSellerShippingTime= str(flipkartDetails.shippingTimeLowerLimitPrefSeller) if flipkartDetails.shippingTimeUpperLimitPrefSeller==0\
603
        else str(flipkartDetails.shippingTimeLowerLimitPrefSeller)+'-'+str(flipkartDetails.shippingTimeUpperLimitPrefSeller)
603
        else str(flipkartDetails.shippingTimeLowerLimitPrefSeller)+'-'+str(flipkartDetails.shippingTimeUpperLimitPrefSeller)
604
        mpHistory.margin = mpHistory.ourTp - mpHistory.lowestPossibleTp
604
        mpHistory.margin = mpHistory.ourTp - mpHistory.lowestPossibleTp
605
        proposed_sp = max(mpHistory.lowestSellingPrice - max((20, mpHistory.lowestSellingPrice*0.002)), mpHistory.lowestPossibleSp)
605
        proposed_sp = max(flipkartDetails.lowestSellerSp - max((10, flipkartDetails.lowestSellerSp*0.001)), flipkartPricing.lowestPossibleSp)
606
        proposed_tp = getTargetTp(proposed_sp,mpItem)
606
        proposed_tp = getTargetTp(proposed_sp,mpItem)
607
        mpHistory.proposedSellingPrice = proposed_sp
607
        mpHistory.proposedSellingPrice = proposed_sp
608
        mpHistory.proposedTp = proposed_tp  
608
        mpHistory.proposedTp = proposed_tp  
609
        mpHistory.totalSeller = flipkartDetails.totalAvailableSeller
609
        mpHistory.totalSeller = flipkartDetails.totalAvailableSeller
610
        mpHistory.avgSales = (itemSaleMap.get(flipkartItemInfo.item_id))[3]
610
        mpHistory.avgSales = (itemSaleMap.get(flipkartItemInfo.item_id))[3]
Line 739... Line 739...
739
    flipkartDetails = __FlipkartDetails(rank ,ourSp , secondLowestSellerSp, prefSellerSp, lowestSellerSp, lowestSellerScore, prefSellerScore, secondLowestSellerScore, ourScore, int(shippingTimeLowerLimitLowestSeller),int(shippingTimeUpperLimitLowestSeller), \
739
    flipkartDetails = __FlipkartDetails(rank ,ourSp , secondLowestSellerSp, prefSellerSp, lowestSellerSp, lowestSellerScore, prefSellerScore, secondLowestSellerScore, ourScore, int(shippingTimeLowerLimitLowestSeller),int(shippingTimeUpperLimitLowestSeller), \
740
    int(shippingTimeLowerLimitPrefSeller), int(shippingTimeUpperLimitPrefSeller), int(shippingTimeLowerLimitOur), int(shippingTimeUpperLimitOur), int(shippingTimeLowerLimitSecondLowestSeller), int(shippingTimeUpperLimitSecondLowestSeller), len(sortedVendorsData), lowestSellerName, lowestSellerCode, secondLowestSellerName, secondLowestSellerCode, prefSellerName, prefSellerCode, lowestSellerBuyTrend, \
740
    int(shippingTimeLowerLimitPrefSeller), int(shippingTimeUpperLimitPrefSeller), int(shippingTimeLowerLimitOur), int(shippingTimeUpperLimitOur), int(shippingTimeLowerLimitSecondLowestSeller), int(shippingTimeUpperLimitSecondLowestSeller), len(sortedVendorsData), lowestSellerName, lowestSellerCode, secondLowestSellerName, secondLowestSellerCode, prefSellerName, prefSellerCode, lowestSellerBuyTrend, \
741
    ourBuyTrend, prefSellerBuyTrend, secondLowestSellerBuyTrend, ourCode)
741
    ourBuyTrend, prefSellerBuyTrend, secondLowestSellerBuyTrend, ourCode)
742
    
742
    
743
    if flipkartDetails.ourBuyTrend == 'PrefCheap'and flipkartDetails.rank!=1 and flipkartDetails.ourSp==flipkartDetails.secondLowestSellerSp:
743
    if flipkartDetails.ourBuyTrend == 'PrefCheap'and flipkartDetails.rank!=1 and flipkartDetails.ourSp==flipkartDetails.secondLowestSellerSp:
744
        print "Under PrefCheap category.Swiching data for ",flipkartSerialNumber
744
        print "Under PrefCheap category.Switching data for ",flipkartSerialNumber
745
        flipkartDetails.lowestSellerSp, flipkartDetails.secondLowestSellerSp = flipkartDetails.secondLowestSellerSp,flipkartDetails.lowestSellerSp
745
        flipkartDetails.lowestSellerSp, flipkartDetails.secondLowestSellerSp = flipkartDetails.secondLowestSellerSp,flipkartDetails.lowestSellerSp
746
        flipkartDetails.lowestSellerScore, flipkartDetails.secondLowestSellerScore = flipkartDetails.secondLowestSellerScore,flipkartDetails.lowestSellerScore
746
        flipkartDetails.lowestSellerScore, flipkartDetails.secondLowestSellerScore = flipkartDetails.secondLowestSellerScore,flipkartDetails.lowestSellerScore
747
        flipkartDetails.shippingTimeLowerLimitLowestSeller, flipkartDetails.shippingTimeLowerLimitSecondLowestSeller = flipkartDetails.shippingTimeLowerLimitSecondLowestSeller,flipkartDetails.shippingTimeLowerLimitLowestSeller
747
        flipkartDetails.shippingTimeLowerLimitLowestSeller, flipkartDetails.shippingTimeLowerLimitSecondLowestSeller = flipkartDetails.shippingTimeLowerLimitSecondLowestSeller,flipkartDetails.shippingTimeLowerLimitLowestSeller
748
        flipkartDetails.shippingTimeUpperLimitLowestSeller, flipkartDetails.shippingTimeUpperLimitSecondLowestSeller = flipkartDetails.shippingTimeUpperLimitSecondLowestSeller,flipkartDetails.shippingTimeUpperLimitLowestSeller
748
        flipkartDetails.shippingTimeUpperLimitLowestSeller, flipkartDetails.shippingTimeUpperLimitSecondLowestSeller = flipkartDetails.shippingTimeUpperLimitSecondLowestSeller,flipkartDetails.shippingTimeUpperLimitLowestSeller
749
        flipkartDetails.lowestSellerName, flipkartDetails.secondLowestSellerName = flipkartDetails.secondLowestSellerName,flipkartDetails.lowestSellerName
749
        flipkartDetails.lowestSellerName, flipkartDetails.secondLowestSellerName = flipkartDetails.secondLowestSellerName,flipkartDetails.lowestSellerName
750
        flipkartDetails.lowestSellerCode, flipkartDetails.secondLowestSellerCode = flipkartDetails.secondLowestSellerCode,flipkartDetails.lowestSellerCode
750
        flipkartDetails.lowestSellerCode, flipkartDetails.secondLowestSellerCode = flipkartDetails.secondLowestSellerCode,flipkartDetails.lowestSellerCode
751
        flipkartDetails.lowestSellerBuyTrend, flipkartDetails.secondLowestSellerBuyTrend = flipkartDetails.secondLowestSellerBuyTrend,flipkartDetails.lowestSellerBuyTrend
751
        flipkartDetails.lowestSellerBuyTrend, flipkartDetails.secondLowestSellerBuyTrend = flipkartDetails.secondLowestSellerBuyTrend,flipkartDetails.lowestSellerBuyTrend
752
        flipkartDetails.rank=1
752
        flipkartDetails.rank=1
753
    
753
    
754
    if flipkartDetails.ourBuyTrend == 'NPrefCheap'and flipkartDetails.rank!=1 and flipkartDetails.ourSp==flipkartDetails.lowestSellerSp:
754
    if flipkartDetails.ourBuyTrend == 'NPrefCheap'and flipkartDetails.rank!=1 and flipkartDetails.ourSp==flipkartDetails.lowestSellerSp:
755
        print "Under NPrefCheap category.Swiching data for ",flipkartSerialNumber
755
        print "Under NPrefCheap category.Switching data for ",flipkartSerialNumber
756
        flipkartDetails.lowestSellerSp = flipkartDetails.ourSp
756
        flipkartDetails.lowestSellerSp = flipkartDetails.ourSp
757
        flipkartDetails.lowestSellerScore = flipkartDetails.ourScore
757
        flipkartDetails.lowestSellerScore = flipkartDetails.ourScore
758
        flipkartDetails.shippingTimeLowerLimitLowestSeller = flipkartDetails.shippingTimeLowerLimitOur
758
        flipkartDetails.shippingTimeLowerLimitLowestSeller = flipkartDetails.shippingTimeLowerLimitOur
759
        flipkartDetails.shippingTimeUpperLimitLowestSeller = flipkartDetails.shippingTimeUpperLimitOur
759
        flipkartDetails.shippingTimeUpperLimitLowestSeller = flipkartDetails.shippingTimeUpperLimitOur
760
        flipkartDetails.lowestSellerName = 'Saholic'
760
        flipkartDetails.lowestSellerName = 'Saholic'
Line 1175... Line 1175...
1175
    sheet.write(0, 30, "Lowest Possible TP", heading_xf)
1175
    sheet.write(0, 30, "Lowest Possible TP", heading_xf)
1176
    sheet.write(0, 31, "Target SP", heading_xf)
1176
    sheet.write(0, 31, "Target SP", heading_xf)
1177
    sheet.write(0, 32, "Target TP", heading_xf)  
1177
    sheet.write(0, 32, "Target TP", heading_xf)  
1178
    sheet.write(0, 33, "Margin Increased Potential", heading_xf)
1178
    sheet.write(0, 33, "Margin Increased Potential", heading_xf)
1179
    sheet.write(0, 34, "Total Seller", heading_xf)
1179
    sheet.write(0, 34, "Total Seller", heading_xf)
-
 
1180
    sheet.write(0, 35, "Auto Pricing Decision", heading_xf)
-
 
1181
    sheet.write(0, 36, "Reason", heading_xf)
-
 
1182
    sheet.write(0, 37, "Updated Price", heading_xf)
1180
    sheet_iterator = 1
1183
    sheet_iterator = 1
1181
    
1184
    
1182
    buyBoxItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1185
    buyBoxItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1183
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1186
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1184
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
1187
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
Line 1237... Line 1240...
1237
        target_nlc = proposed_tp -  mpHistory.lowestPossibleTp + mpHistory.ourNlc
1240
        target_nlc = proposed_tp -  mpHistory.lowestPossibleTp + mpHistory.ourNlc
1238
        sheet.write(sheet_iterator, 31, proposed_sp)
1241
        sheet.write(sheet_iterator, 31, proposed_sp)
1239
        sheet.write(sheet_iterator, 32, proposed_tp)
1242
        sheet.write(sheet_iterator, 32, proposed_tp)
1240
        sheet.write(sheet_iterator, 33, proposed_tp -mpHistory.ourTp )
1243
        sheet.write(sheet_iterator, 33, proposed_tp -mpHistory.ourTp )
1241
        sheet.write(sheet_iterator, 34, mpHistory.totalSeller)
1244
        sheet.write(sheet_iterator, 34, mpHistory.totalSeller)
-
 
1245
        if mpHistory.decision is None:
-
 
1246
            sheet.write(sheet_iterator, 35, 'Auto Pricing Inactive')
-
 
1247
            sheet_iterator+=1
-
 
1248
            continue
-
 
1249
        sheet.write(sheet_iterator, 35, Decision._VALUES_TO_NAMES.get(mpHistory.decision))
-
 
1250
        sheet.write(sheet_iterator, 36, mpHistory.reason)
-
 
1251
        sheet.write(sheet_iterator, 37, math.ceil(mpHistory.ourSellingPrice+max(10,.01*mpHistory.ourSellingPrice)))
1242
        sheet_iterator+=1
1252
        sheet_iterator+=1
1243
    
1253
    
1244
    buyBoxItems[:] = []
1254
    buyBoxItems[:] = []
1245
    
1255
    
1246
    sheet = wbk.add_sheet('Pref Not Cheap')
1256
    sheet = wbk.add_sheet('Pref Not Cheap')
Line 1290... Line 1300...
1290
    sheet.write(0, 29, "Lowest Possible SP", heading_xf)
1300
    sheet.write(0, 29, "Lowest Possible SP", heading_xf)
1291
    sheet.write(0, 30, "Lowest Possible TP", heading_xf)
1301
    sheet.write(0, 30, "Lowest Possible TP", heading_xf)
1292
    sheet.write(0, 31, "Target SP", heading_xf)
1302
    sheet.write(0, 31, "Target SP", heading_xf)
1293
    sheet.write(0, 32, "Target TP", heading_xf)  
1303
    sheet.write(0, 32, "Target TP", heading_xf)  
1294
    sheet.write(0, 33, "Total Seller", heading_xf)
1304
    sheet.write(0, 33, "Total Seller", heading_xf)
-
 
1305
    sheet.write(0, 34, "Auto Pricing Decision", heading_xf)
-
 
1306
    sheet.write(0, 35, "Reason", heading_xf)
-
 
1307
    sheet.write(0, 36, "Updated Price", heading_xf)
-
 
1308
 
1295
    sheet_iterator = 1
1309
    sheet_iterator = 1
1296
    
1310
    
1297
    prefNotCheapItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1311
    prefNotCheapItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1298
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1312
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1299
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
1313
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
Line 1345... Line 1359...
1345
        sheet.write(sheet_iterator, 26, getOosString((itemSaleMap.get(mpHistory.item_id))[1]))
1359
        sheet.write(sheet_iterator, 26, getOosString((itemSaleMap.get(mpHistory.item_id))[1]))
1346
        sheet.write(sheet_iterator, 27, (itemSaleMap.get(mpHistory.item_id))[3])
1360
        sheet.write(sheet_iterator, 27, (itemSaleMap.get(mpHistory.item_id))[3])
1347
        sheet.write(sheet_iterator, 28, mpHistory.ourNlc)
1361
        sheet.write(sheet_iterator, 28, mpHistory.ourNlc)
1348
        sheet.write(sheet_iterator, 29, mpHistory.lowestPossibleSp)
1362
        sheet.write(sheet_iterator, 29, mpHistory.lowestPossibleSp)
1349
        sheet.write(sheet_iterator, 30, mpHistory.lowestPossibleTp)
1363
        sheet.write(sheet_iterator, 30, mpHistory.lowestPossibleTp)
1350
        proposed_sp = max(mpHistory.lowestSellingPrice - max((20, mpHistory.lowestSellingPrice*0.002)), mpHistory.lowestPossibleSp)
1364
        proposed_sp = max(mpHistory.lowestSellingPrice - max((10, mpHistory.lowestSellingPrice*0.001)), mpHistory.lowestPossibleSp)
1351
        proposed_tp = getTargetTp(proposed_sp,mpItem)
1365
        proposed_tp = getTargetTp(proposed_sp,mpItem)
1352
        target_nlc = proposed_tp -  mpHistory.lowestPossibleTp + mpHistory.ourNlc
1366
        target_nlc = proposed_tp -  mpHistory.lowestPossibleTp + mpHistory.ourNlc
1353
        sheet.write(sheet_iterator, 31, proposed_sp)
1367
        sheet.write(sheet_iterator, 31, proposed_sp)
1354
        sheet.write(sheet_iterator, 32, proposed_tp)
1368
        sheet.write(sheet_iterator, 32, proposed_tp)
1355
        sheet.write(sheet_iterator, 33, mpHistory.totalSeller)
1369
        sheet.write(sheet_iterator, 33, mpHistory.totalSeller)
-
 
1370
        if mpHistory.decision is None:
-
 
1371
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
-
 
1372
            sheet_iterator+=1
-
 
1373
            continue
-
 
1374
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(mpHistory.decision))
-
 
1375
        sheet.write(sheet_iterator, 35, mpHistory.reason)
-
 
1376
        sheet.write(sheet_iterator, 36, math.ceil(mpHistory.proposedSellingPrice))
-
 
1377
        
1356
        sheet_iterator+=1
1378
        sheet_iterator+=1
1357
        
1379
        
1358
    prefNotCheapItems[:] = []
1380
    prefNotCheapItems[:] = []
1359
    
1381
    
1360
    sheet = wbk.add_sheet('Cheap But Not Pref')
1382
    sheet = wbk.add_sheet('Cheap But Not Pref')
Line 1498... Line 1520...
1498
    sheet.write(0, 31, "Target SP", heading_xf)
1520
    sheet.write(0, 31, "Target SP", heading_xf)
1499
    sheet.write(0, 32, "Target TP", heading_xf)  
1521
    sheet.write(0, 32, "Target TP", heading_xf)  
1500
    sheet.write(0, 33, "Target NLC", heading_xf)
1522
    sheet.write(0, 33, "Target NLC", heading_xf)
1501
    sheet.write(0, 34, "Sales Potential", heading_xf)
1523
    sheet.write(0, 34, "Sales Potential", heading_xf)
1502
    sheet.write(0, 35, "Total Seller", heading_xf)
1524
    sheet.write(0, 35, "Total Seller", heading_xf)
-
 
1525
    sheet.write(0, 36, "Auto Pricing Decision", heading_xf)
-
 
1526
    sheet.write(0, 37, "Reason", heading_xf)
-
 
1527
    sheet.write(0, 38, "Updated Price", heading_xf)
1503
    sheet_iterator = 1
1528
    sheet_iterator = 1
1504
    
1529
    
1505
    competitiveItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1530
    competitiveItems = session.query(MarketPlaceHistory,FlipkartItem,MarketplaceItems,Item)\
1506
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1531
    .join((FlipkartItem,MarketPlaceHistory.item_id==FlipkartItem.item_id))\
1507
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
1532
    .join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
Line 1552... Line 1577...
1552
        sheet.write(sheet_iterator, 26, getOosString((itemSaleMap.get(mpHistory.item_id))[1]))
1577
        sheet.write(sheet_iterator, 26, getOosString((itemSaleMap.get(mpHistory.item_id))[1]))
1553
        sheet.write(sheet_iterator, 27, (itemSaleMap.get(mpHistory.item_id))[3])
1578
        sheet.write(sheet_iterator, 27, (itemSaleMap.get(mpHistory.item_id))[3])
1554
        sheet.write(sheet_iterator, 28, mpHistory.ourNlc)
1579
        sheet.write(sheet_iterator, 28, mpHistory.ourNlc)
1555
        sheet.write(sheet_iterator, 29, mpHistory.lowestPossibleSp)
1580
        sheet.write(sheet_iterator, 29, mpHistory.lowestPossibleSp)
1556
        sheet.write(sheet_iterator, 30, mpHistory.lowestPossibleTp)
1581
        sheet.write(sheet_iterator, 30, mpHistory.lowestPossibleTp)
1557
        proposed_sp = max(mpHistory.lowestSellingPrice - max((10, mpHistory.lowestSellingPrice*0.001)), mpHistory.lowestSellingPrice)
1582
        proposed_sp = max(mpHistory.lowestSellingPrice - max((10, mpHistory.lowestSellingPrice*0.001)), mpHistory.lowestPossibleSp)
1558
        proposed_tp = getTargetTp(proposed_sp,mpItem)
1583
        proposed_tp = getTargetTp(proposed_sp,mpItem)
1559
        target_nlc = proposed_tp - mpHistory.lowestPossibleTp + mpHistory.ourNlc
1584
        target_nlc = proposed_tp - mpHistory.lowestPossibleTp + mpHistory.ourNlc
1560
        sheet.write(sheet_iterator, 31, proposed_sp)
1585
        sheet.write(sheet_iterator, 31, proposed_sp)
1561
        sheet.write(sheet_iterator, 32, proposed_tp)
1586
        sheet.write(sheet_iterator, 32, proposed_tp)
1562
        sheet.write(sheet_iterator, 33, target_nlc)
1587
        sheet.write(sheet_iterator, 33, target_nlc)
1563
        sheet.write(sheet_iterator, 34, getSalesPotential(mpHistory.lowestSellingPrice,mpHistory.ourNlc))
1588
        sheet.write(sheet_iterator, 34, getSalesPotential(mpHistory.lowestSellingPrice,mpHistory.ourNlc))
1564
        sheet.write(sheet_iterator, 35, mpHistory.totalSeller)
1589
        sheet.write(sheet_iterator, 35, mpHistory.totalSeller)
-
 
1590
        if mpHistory.decision is None:
-
 
1591
            sheet.write(sheet_iterator, 36, 'Auto Pricing Inactive')
-
 
1592
            sheet_iterator+=1
-
 
1593
            continue
-
 
1594
        sheet.write(sheet_iterator, 36, Decision._VALUES_TO_NAMES.get(mpHistory.decision))
-
 
1595
        sheet.write(sheet_iterator, 37, mpHistory.reason)
-
 
1596
        sheet.write(sheet_iterator, 38, math.ceil(mpHistory.proposedSellingPrice))
-
 
1597
        
1565
        sheet_iterator+=1
1598
        sheet_iterator+=1
1566
    
1599
    
1567
    competitiveItems[:]=[]
1600
    competitiveItems[:]=[]
1568
    
1601
    
1569
    sheet = wbk.add_sheet('Negative Margin')
1602
    sheet = wbk.add_sheet('Negative Margin')
Line 1950... Line 1983...
1950
            sheet.write(sheet_iterator, 33, getSalesPotential(mpHistory.lowestPossibleSp,mpHistory.ourNlc))
1983
            sheet.write(sheet_iterator, 33, getSalesPotential(mpHistory.lowestPossibleSp,mpHistory.ourNlc))
1951
            sheet.write(sheet_iterator, 34, mpHistory.totalSeller)
1984
            sheet.write(sheet_iterator, 34, mpHistory.totalSeller)
1952
            sheet_iterator+=1
1985
            sheet_iterator+=1
1953
    competitiveNoInventory[:]=[]
1986
    competitiveNoInventory[:]=[]
1954
    
1987
    
1955
    autoPricingItems = session.query(MarketPlaceHistory,Item).join((Item,MarketPlaceHistory.item_id==Item.id)).filter(MarketPlaceHistory.timestamp==timestamp).filter(MarketPlaceHistory.source==OrderSource.FLIPKART).filter(MarketPlaceHistory.decision.in_([1,2,3,4])).all()
1988
#    autoPricingItems = session.query(MarketPlaceHistory,Item).join((Item,MarketPlaceHistory.item_id==Item.id)).filter(MarketPlaceHistory.timestamp==timestamp).filter(MarketPlaceHistory.source==OrderSource.FLIPKART).filter(MarketPlaceHistory.decision.in_([1,2,3,4])).all()
1956
    sheet = wbk.add_sheet('Auto Inc and Dec')
1989
#    sheet = wbk.add_sheet('Auto Inc and Dec')
1957
 
1990
#
1958
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1991
#    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1959
    
1992
#    
1960
    excel_integer_format = '0'
1993
#    excel_integer_format = '0'
1961
    integer_style = xlwt.XFStyle()
1994
#    integer_style = xlwt.XFStyle()
1962
    integer_style.num_format_str = excel_integer_format
1995
#    integer_style.num_format_str = excel_integer_format
1963
    xstr = lambda s: s or ""
1996
#    xstr = lambda s: s or ""
1964
    
1997
#    
1965
    sheet.write(0, 0, "Item ID", heading_xf)
1998
#    sheet.write(0, 0, "Item ID", heading_xf)
1966
    sheet.write(0, 1, "Brand", heading_xf)
1999
#    sheet.write(0, 1, "Brand", heading_xf)
1967
    sheet.write(0, 2, "Product Name", heading_xf)
2000
#    sheet.write(0, 2, "Product Name", heading_xf)
1968
    sheet.write(0, 3, "Decision", heading_xf)
2001
#    sheet.write(0, 3, "Decision", heading_xf)
1969
    sheet.write(0, 4, "Reason", heading_xf)
2002
#    sheet.write(0, 4, "Reason", heading_xf)
1970
    sheet.write(0, 5, "Old Selling Price", heading_xf)
2003
#    sheet.write(0, 5, "Old Selling Price", heading_xf)
1971
    sheet.write(0, 6, "Selling Price Updated",heading_xf)
2004
#    sheet.write(0, 6, "Selling Price Updated",heading_xf)
1972
    
2005
#    
1973
    sheet_iterator=1
2006
#    sheet_iterator=1
1974
    for autoPricingItem in autoPricingItems:
2007
#    for autoPricingItem in autoPricingItems:
1975
        mpHistory = autoPricingItem[0]
2008
#        mpHistory = autoPricingItem[0]
1976
        item = autoPricingItem[1]
2009
#        item = autoPricingItem[1]
1977
        it = Item.query.filter_by(id=item.id).one()
2010
#        it = Item.query.filter_by(id=item.id).one()
1978
        sheet.write(sheet_iterator, 0, item.id)
2011
#        sheet.write(sheet_iterator, 0, item.id)
1979
        sheet.write(sheet_iterator, 1, it.brand)
2012
#        sheet.write(sheet_iterator, 1, it.brand)
1980
        sheet.write(sheet_iterator, 2, xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color))
2013
#        sheet.write(sheet_iterator, 2, xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color))
1981
        sheet.write(sheet_iterator, 3, Decision._VALUES_TO_NAMES.get(mpHistory.decision))
2014
#        sheet.write(sheet_iterator, 3, Decision._VALUES_TO_NAMES.get(mpHistory.decision))
1982
        sheet.write(sheet_iterator, 4, mpHistory.reason)
2015
#        sheet.write(sheet_iterator, 4, mpHistory.reason)
1983
        if Decision._VALUES_TO_NAMES.get(mpHistory.decision) == "AUTO_DECREMENT_SUCCESS":
2016
#        if Decision._VALUES_TO_NAMES.get(mpHistory.decision) == "AUTO_DECREMENT_SUCCESS":
1984
            sheet.write(sheet_iterator, 5, mpHistory.ourSellingPrice)
2017
#            sheet.write(sheet_iterator, 5, mpHistory.ourSellingPrice)
1985
            sheet.write(sheet_iterator, 6, math.ceil(mpHistory.proposedSellingPrice))
2018
#            sheet.write(sheet_iterator, 6, math.ceil(mpHistory.proposedSellingPrice))
1986
        if Decision._VALUES_TO_NAMES.get(mpHistory.decision) == "AUTO_INCREMENT_SUCCESS":
2019
#        if Decision._VALUES_TO_NAMES.get(mpHistory.decision) == "AUTO_INCREMENT_SUCCESS":
1987
            sheet.write(sheet_iterator, 5, mpHistory.ourSellingPrice)
2020
#            sheet.write(sheet_iterator, 5, mpHistory.ourSellingPrice)
1988
            sheet.write(sheet_iterator, 6, math.ceil(mpHistory.ourSellingPrice+max(10,.01*mpHistory.ourSellingPrice)))
2021
#            sheet.write(sheet_iterator, 6, math.ceil(mpHistory.ourSellingPrice+max(10,.01*mpHistory.ourSellingPrice)))
1989
        sheet_iterator+=1
2022
#        sheet_iterator+=1
1990
    
2023
    
1991
    filename = "/tmp/flipkart-report-"+runType+" " + str(timestamp) + ".xls"
2024
    filename = "/tmp/flipkart-report-"+runType+" " + str(timestamp) + ".xls"
1992
    wbk.save(filename)
2025
    wbk.save(filename)
1993
    try:
2026
    try:
1994
        EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@saholic.com"], " Flipkart Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], [""], [])
2027
        EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@saholic.com"], " Flipkart Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], [""], [])
Line 2445... Line 2478...
2445
        try:
2478
        try:
2446
            smtpServer.sendmail(sender, recipients, msg.as_string())
2479
            smtpServer.sendmail(sender, recipients, msg.as_string())
2447
            print "Successfully sent email"
2480
            print "Successfully sent email"
2448
        except:
2481
        except:
2449
            print "Error: unable to send email."
2482
            print "Error: unable to send email."
-
 
2483
            
-
 
2484
def sendAlertForNegativeMargins(timestamp):
-
 
2485
    xstr = lambda s: s or ""
-
 
2486
    negativeMargins = session.query(MarketPlaceHistory,Item).join((Item,MarketPlaceHistory.item_id==Item.id)).filter(MarketPlaceHistory.timestamp==timestamp).filter(MarketPlaceHistory.source==OrderSource.FLIPKART).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.NEGATIVE_MARGIN).all()
-
 
2487
    if len(negativeMargins) == 0:
-
 
2488
        return
-
 
2489
    message="""<html>
-
 
2490
            <body>
-
 
2491
            <h3 style="color:red;font-weight:bold;">Flipkart Negative Margins</h3>
-
 
2492
            <table border="1" style="width:100%;">
-
 
2493
            <thead>
-
 
2494
            <tr><th>Item Id</th>
-
 
2495
            <th>Product Name</th>
-
 
2496
            <th>SP</th>
-
 
2497
            <th>TP</th>
-
 
2498
            <th>Lowest Possible SP</th>
-
 
2499
            <th>Lowest Possible TP</th>
-
 
2500
            <th>Margin</th>
-
 
2501
            <th>Margin %</th>
-
 
2502
            <th>Flipkart Inventory</th>
-
 
2503
            <th>Total Inventory</th>
-
 
2504
            <th>Sales History</th>
-
 
2505
            </tr></thead>
-
 
2506
            <tbody>"""
-
 
2507
    for item in negativeMargins:
-
 
2508
        mpHistory = item[0]
-
 
2509
        catItem = item[1]
-
 
2510
        netInventory=''
-
 
2511
        if not inventoryMap.has_key(item):
-
 
2512
            netInventory='Info Not Available'
-
 
2513
        else:
-
 
2514
            netInventory = str(getNetAvailability(inventoryMap.get(item)))
-
 
2515
        message+="""<tr>
-
 
2516
            <td style="text-align:center">"""+str(mpHistory.item_id)+"""</td>
-
 
2517
            <td style="text-align:center">"""+xstr(catItem.brand)+" "+xstr(catItem.model_name)+" "+xstr(catItem.model_number)+" "+xstr(catItem.color)+"""</td>
-
 
2518
            <td style="text-align:center">"""+str(mpHistory.ourSellingPrice)+"""</td>
-
 
2519
            <td style="text-align:center">"""+str(mpHistory.ourTp)+"""</td>
-
 
2520
            <td style="text-align:center">"""+str(mpHistory.lowestPossibleSp)+"""</td>
-
 
2521
            <td style="text-align:center">"""+str(mpHistory.lowestPossibleTp)+"""</td>
-
 
2522
            <td style="text-align:center">"""+str(mpHistory.margin)+"""</td>
-
 
2523
            <td style="text-align:center">"""+str(round(mpHistory.margin/mpHistory.ourSellingPrice,2))+"""</td>
-
 
2524
            <td style="text-align:center">"""+str(mpHistory.ourInventory)+"""</td>
-
 
2525
            <td style="text-align:center">"""+netInventory+"""</td>
-
 
2526
            <td style="text-align:center">"""+getOosString((itemSaleMap.get(item))[1])+"""</td>
-
 
2527
            </tr>"""
-
 
2528
    message+="""</tbody></table></body></html>"""
-
 
2529
    print message
-
 
2530
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
-
 
2531
    mailServer.ehlo()
-
 
2532
    mailServer.starttls()
-
 
2533
    mailServer.ehlo()
-
 
2534
 
-
 
2535
    recipients = ['kshitij.sood@saholic.com']
-
 
2536
    #recipients = ['rajneesh.arora@saholic.com','anikendra.das@saholic.com','vikram.raghav@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
-
 
2537
    msg = MIMEMultipart()
-
 
2538
    msg['Subject'] = "Flipkart Negative Margin" + ' - ' + str(datetime.now())
-
 
2539
    msg['From'] = ""
-
 
2540
    msg['To'] = ",".join(recipients)
-
 
2541
    msg.preamble = "Flipkart Negative Margin" + ' - ' + str(datetime.now())
-
 
2542
    html_msg = MIMEText(message, 'html')
-
 
2543
    msg.attach(html_msg)
-
 
2544
    try:
-
 
2545
        mailServer.login("build@shop2020.in", "cafe@nes")
-
 
2546
        #mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
-
 
2547
        mailServer.sendmail("cafe@nes", recipients, msg.as_string())
-
 
2548
    except Exception as e:
-
 
2549
        print e
-
 
2550
        print "Unable to send Flipkart Negative margin mail.Lets try local SMTP"
-
 
2551
        smtpServer = smtplib.SMTP('localhost')
-
 
2552
        smtpServer.set_debuglevel(1)
-
 
2553
        sender = 'support@shop2020.in'
-
 
2554
        try:
-
 
2555
            smtpServer.sendmail(sender, recipients, msg.as_string())
-
 
2556
            print "Successfully sent email"
-
 
2557
        except:
-
 
2558
            print "Error: unable to send email."
-
 
2559
    
-
 
2560
    
2450
    
2561
    
2451
    
2562
    
2452
def main():
2563
def main():
2453
    parser = optparse.OptionParser()
2564
    parser = optparse.OptionParser()
2454
    parser.add_option("-t", "--type", dest="runType",
2565
    parser.add_option("-t", "--type", dest="runType",
Line 2488... Line 2599...
2488
    if previousProcessingTimestamp[0] is not None:
2599
    if previousProcessingTimestamp[0] is not None:
2489
        processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
2600
        processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
2490
    if options.runType=='FULL':
2601
    if options.runType=='FULL':
2491
        cheapButNotPrefAlert(timestamp)
2602
        cheapButNotPrefAlert(timestamp)
2492
        sendPricingMismatch(timestamp)
2603
        sendPricingMismatch(timestamp)
-
 
2604
        sendAlertForNegativeMargins(timestamp)
2493
 
2605
 
2494
if __name__ == '__main__':
2606
if __name__ == '__main__':
2495
    main()
2607
    main()
2496
2608