Subversion Repositories SmartDukaan

Rev

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

Rev 12813 Rev 12845
Line 47... Line 47...
47
 
47
 
48
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
48
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
49
 
49
 
50
class __AmazonItemInfo:
50
class __AmazonItemInfo:
51
    
51
    
52
    def __init__(self, asin, nlc, courierCost, sku, product_group, brand, model_name, model_number, color, weight, parent_category, risky, vatRate, runType, parent_category_name, sourcePercentage, ourInventory, state_id, otherCost, exceptionType):
52
    def __init__(self, asin, nlc, courierCost, sku, product_group, brand, model_name, model_number, color, weight, parent_category, risky, vatRate, runType, parent_category_name, sourcePercentage, ourInventory, state_id, otherCost, exceptionType, isNlcOverridden):
53
        self.asin = asin
53
        self.asin = asin
54
        self.nlc = nlc
54
        self.nlc = nlc
55
        self.courierCost = courierCost
55
        self.courierCost = courierCost
56
        self.sku = sku
56
        self.sku = sku
57
        self.product_group = product_group
57
        self.product_group = product_group
Line 67... Line 67...
67
        self.parent_category_name = parent_category_name
67
        self.parent_category_name = parent_category_name
68
        self.sourcePercentage = sourcePercentage
68
        self.sourcePercentage = sourcePercentage
69
        self.ourInventory = ourInventory
69
        self.ourInventory = ourInventory
70
        self.state_id = state_id
70
        self.state_id = state_id
71
        self.otherCost = otherCost
71
        self.otherCost = otherCost
72
        self.exceptionType = exceptionType 
72
        self.exceptionType = exceptionType
-
 
73
        self.isNlcOverridden = isNlcOverridden
73
 
74
 
74
class __AmazonDetails:
75
class __AmazonDetails:
75
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
76
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
76
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
77
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
77
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, \
78
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, \
Line 436... Line 437...
436
                notListed.append(sku)
437
                notListed.append(sku)
437
            else:
438
            else:
438
                pass
439
                pass
439
            continue
440
            continue
440
        if d_amazon_listed.overrrideWanlc:
441
        if d_amazon_listed.overrrideWanlc:
-
 
442
            isNlcOverridden = True
441
            wanlc = d_amazon_listed.exceptionalWanlc
443
            wanlc = d_amazon_listed.exceptionalWanlc
442
            if wanlc is None:
444
            if wanlc is None:
443
                wanlc = 0.0
445
                wanlc = 0.0
444
        else:
446
        else:
-
 
447
            isNlcOverridden = False
445
            wanlc = inventory_client.getWanNlcForSource(fbaInventoryItem.item_id,OrderSource.AMAZON)
448
            wanlc = inventory_client.getWanNlcForSource(fbaInventoryItem.item_id,OrderSource.AMAZON)
446
        it = Item.query.filter_by(id=fbaInventoryItem.item_id).one()
449
        it = Item.query.filter_by(id=fbaInventoryItem.item_id).one()
447
        category = Category.query.filter_by(id=it.category).one()
450
        category = Category.query.filter_by(id=it.category).one()
448
        parent_category = Category.query.filter_by(id=category.parent_category_id).first()
451
        parent_category = Category.query.filter_by(id=category.parent_category_id).first()
449
        sourcePercentage = None
452
        sourcePercentage = None
Line 465... Line 468...
465
            state_id = 2
468
            state_id = 2
466
        else:
469
        else:
467
            continue
470
            continue
468
        cc = computeCourierCost(it.weight)
471
        cc = computeCourierCost(it.weight)
469
            
472
            
470
        amazonItemInfo = __AmazonItemInfo(None, wanlc,cc, sku, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, None, runType, parent_category.display_name,sourcePercentage,fbaInventoryItem.availability,state_id,d_amazon_listed.otherCost,None)
473
        amazonItemInfo = __AmazonItemInfo(None, wanlc,cc, sku, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, None, runType, parent_category.display_name,sourcePercentage,fbaInventoryItem.availability,state_id,d_amazon_listed.otherCost,None,isNlcOverridden)
471
        itemInfo.append(amazonItemInfo)
474
        itemInfo.append(amazonItemInfo)
472
    #amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
475
    #amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
473
    #.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
476
    #.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
474
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
477
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
475
    .order_by(desc(AmazonPromotion.addedOn)).all()
478
    .order_by(desc(AmazonPromotion.addedOn)).all()
Line 812... Line 815...
812
        amazonScrapingHistory.reason = exceptionMap.get(val.exceptionType)
815
        amazonScrapingHistory.reason = exceptionMap.get(val.exceptionType)
813
        amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
816
        amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
814
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.EXCEPTION
817
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.EXCEPTION
815
        amazonScrapingHistory.exceptionType = val.exceptionType
818
        amazonScrapingHistory.exceptionType = val.exceptionType
816
        amazonScrapingHistory.ourInventory = val.ourInventory
819
        amazonScrapingHistory.ourInventory = val.ourInventory
-
 
820
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
817
        if val.exceptionType in (3,5):
821
        if val.exceptionType in (3,5):
818
            amDetails = exceptionItem[1]
822
            amDetails = exceptionItem[1]
819
            amPricing = exceptionItem[2]
823
            amPricing = exceptionItem[2]
820
            if amazonLongTermActivePromotions.has_key(val.sku):
824
            if amazonLongTermActivePromotions.has_key(val.sku):
821
                subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
825
                subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
Line 905... Line 909...
905
        if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
909
        if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
906
            amazonScrapingHistory.cheapestMfnCount = True
910
            amazonScrapingHistory.cheapestMfnCount = True
907
        else:
911
        else:
908
            amazonScrapingHistory.cheapestMfnCount = False
912
            amazonScrapingHistory.cheapestMfnCount = False
909
        amazonScrapingHistory.wanlc = val.nlc
913
        amazonScrapingHistory.wanlc = val.nlc
-
 
914
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
910
        amazonScrapingHistory.otherCost = val.otherCost
915
        amazonScrapingHistory.otherCost = val.otherCost
911
        amazonScrapingHistory.commission = spm.commission
916
        amazonScrapingHistory.commission = spm.commission
912
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
917
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
913
        amazonScrapingHistory.returnProvision = spm.returnProvision
918
        amazonScrapingHistory.returnProvision = spm.returnProvision
914
        amazonScrapingHistory.courierCost = val.courierCost
919
        amazonScrapingHistory.courierCost = val.courierCost
Line 960... Line 965...
960
        amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
965
        amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
961
        amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
966
        amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
962
        amazonScrapingHistory.cheapestMfnCount = False
967
        amazonScrapingHistory.cheapestMfnCount = False
963
        amazonScrapingHistory.otherCost = val.otherCost
968
        amazonScrapingHistory.otherCost = val.otherCost
964
        amazonScrapingHistory.wanlc = val.nlc
969
        amazonScrapingHistory.wanlc = val.nlc
-
 
970
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
965
        amazonScrapingHistory.commission = spm.commission
971
        amazonScrapingHistory.commission = spm.commission
966
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
972
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
967
        amazonScrapingHistory.returnProvision = spm.returnProvision
973
        amazonScrapingHistory.returnProvision = spm.returnProvision
968
        amazonScrapingHistory.courierCost = val.courierCost
974
        amazonScrapingHistory.courierCost = val.courierCost
969
        amazonScrapingHistory.risky = val.risky
975
        amazonScrapingHistory.risky = val.risky
Line 1036... Line 1042...
1036
            amazonScrapingHistory.cheapestMfnCount = True
1042
            amazonScrapingHistory.cheapestMfnCount = True
1037
        else:
1043
        else:
1038
            amazonScrapingHistory.cheapestMfnCount = False
1044
            amazonScrapingHistory.cheapestMfnCount = False
1039
        amazonScrapingHistory.otherCost = val.otherCost
1045
        amazonScrapingHistory.otherCost = val.otherCost
1040
        amazonScrapingHistory.wanlc = val.nlc
1046
        amazonScrapingHistory.wanlc = val.nlc
-
 
1047
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
1041
        amazonScrapingHistory.commission = spm.commission
1048
        amazonScrapingHistory.commission = spm.commission
1042
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1049
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1043
        amazonScrapingHistory.returnProvision = spm.returnProvision
1050
        amazonScrapingHistory.returnProvision = spm.returnProvision
1044
        amazonScrapingHistory.courierCost = val.courierCost
1051
        amazonScrapingHistory.courierCost = val.courierCost
1045
        amazonScrapingHistory.risky = val.risky
1052
        amazonScrapingHistory.risky = val.risky
Line 1104... Line 1111...
1104
            amazonScrapingHistory.cheapestMfnCount = True
1111
            amazonScrapingHistory.cheapestMfnCount = True
1105
        else:
1112
        else:
1106
            amazonScrapingHistory.cheapestMfnCount = False
1113
            amazonScrapingHistory.cheapestMfnCount = False
1107
        amazonScrapingHistory.otherCost = val.otherCost
1114
        amazonScrapingHistory.otherCost = val.otherCost
1108
        amazonScrapingHistory.wanlc = val.nlc
1115
        amazonScrapingHistory.wanlc = val.nlc
-
 
1116
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
1109
        amazonScrapingHistory.commission = spm.commission
1117
        amazonScrapingHistory.commission = spm.commission
1110
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1118
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1111
        amazonScrapingHistory.returnProvision = spm.returnProvision
1119
        amazonScrapingHistory.returnProvision = spm.returnProvision
1112
        amazonScrapingHistory.courierCost = val.courierCost
1120
        amazonScrapingHistory.courierCost = val.courierCost
1113
        amazonScrapingHistory.risky = val.risky
1121
        amazonScrapingHistory.risky = val.risky
Line 1172... Line 1180...
1172
            amazonScrapingHistory.cheapestMfnCount = True
1180
            amazonScrapingHistory.cheapestMfnCount = True
1173
        else:
1181
        else:
1174
            amazonScrapingHistory.cheapestMfnCount = False
1182
            amazonScrapingHistory.cheapestMfnCount = False
1175
        amazonScrapingHistory.otherCost = val.otherCost
1183
        amazonScrapingHistory.otherCost = val.otherCost
1176
        amazonScrapingHistory.wanlc = val.nlc
1184
        amazonScrapingHistory.wanlc = val.nlc
-
 
1185
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
1177
        amazonScrapingHistory.commission = spm.commission
1186
        amazonScrapingHistory.commission = spm.commission
1178
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1187
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1179
        amazonScrapingHistory.returnProvision = spm.returnProvision
1188
        amazonScrapingHistory.returnProvision = spm.returnProvision
1180
        amazonScrapingHistory.courierCost = val.courierCost
1189
        amazonScrapingHistory.courierCost = val.courierCost
1181
        amazonScrapingHistory.risky = val.risky
1190
        amazonScrapingHistory.risky = val.risky
Line 1243... Line 1252...
1243
        else:
1252
        else:
1244
            amazonScrapingHistory.cheapestMfnCount = False
1253
            amazonScrapingHistory.cheapestMfnCount = False
1245
        amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
1254
        amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
1246
        amazonScrapingHistory.otherCost = val.otherCost
1255
        amazonScrapingHistory.otherCost = val.otherCost
1247
        amazonScrapingHistory.wanlc = val.nlc
1256
        amazonScrapingHistory.wanlc = val.nlc
-
 
1257
        amazonScrapingHistory.isNlcOverridden = val.isNlcOverridden
1248
        amazonScrapingHistory.commission = spm.commission
1258
        amazonScrapingHistory.commission = spm.commission
1249
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1259
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
1250
        amazonScrapingHistory.returnProvision = spm.returnProvision
1260
        amazonScrapingHistory.returnProvision = spm.returnProvision
1251
        amazonScrapingHistory.courierCost = val.courierCost
1261
        amazonScrapingHistory.courierCost = val.courierCost
1252
        amazonScrapingHistory.risky = val.risky
1262
        amazonScrapingHistory.risky = val.risky
Line 1317... Line 1327...
1317
#Write the excel sheet headers for identical sheets
1327
#Write the excel sheet headers for identical sheets
1318
def writeheaders(sheet,heading_xf):
1328
def writeheaders(sheet,heading_xf):
1319
    sheet.write(0, 0, "Item Id", heading_xf)
1329
    sheet.write(0, 0, "Item Id", heading_xf)
1320
    sheet.write(0, 1, "Amazon Sku", heading_xf)
1330
    sheet.write(0, 1, "Amazon Sku", heading_xf)
1321
    sheet.write(0, 2, "Asin", heading_xf)
1331
    sheet.write(0, 2, "Asin", heading_xf)
-
 
1332
    sheet.write(0, 3, "URL", heading_xf)
1322
    sheet.write(0, 3, "Location", heading_xf)
1333
    sheet.write(0, 4, "Location", heading_xf)
1323
    sheet.write(0, 4, "Brand", heading_xf)
1334
    sheet.write(0, 5, "Brand", heading_xf)
1324
    sheet.write(0, 5, "Category", heading_xf)
1335
    sheet.write(0, 6, "Category", heading_xf)
1325
    sheet.write(0, 6, "Product Name", heading_xf)
1336
    sheet.write(0, 7, "Product Name", heading_xf)
1326
    sheet.write(0, 7, "Weight", heading_xf)
1337
    sheet.write(0, 8, "Weight", heading_xf)
1327
    sheet.write(0, 8, "Courier Cost", heading_xf)
1338
    sheet.write(0, 9, "Courier Cost", heading_xf)
-
 
1339
    sheet.write(0, 10, "MRP", heading_xf)
1328
    sheet.write(0, 9, "Our SP", heading_xf)
1340
    sheet.write(0, 11, "Our SP", heading_xf)
1329
    sheet.write(0, 10, "Promo Price", heading_xf)
1341
    sheet.write(0, 12, "Promo Price", heading_xf)
1330
    sheet.write(0, 11, "Is Promotion", heading_xf)
1342
    sheet.write(0, 13, "Is Promotion", heading_xf)
1331
    sheet.write(0, 12, "Lowest Possible SP", heading_xf)
1343
    sheet.write(0, 14, "Lowest Possible SP", heading_xf)
1332
    sheet.write(0, 13, "Rank", heading_xf)
1344
    sheet.write(0, 15, "Rank", heading_xf)
1333
    sheet.write(0, 14, "Competitive Category", heading_xf)
1345
    sheet.write(0, 16, "Competitive Category", heading_xf)
1334
    sheet.write(0, 15, "Our Inventory", heading_xf)
1346
    sheet.write(0, 17, "Our Inventory", heading_xf)
1335
    sheet.write(0, 16, "Lowest Seller SP", heading_xf)
1347
    sheet.write(0, 18, "Lowest Seller SP", heading_xf)
1336
    sheet.write(0, 17, "Lowest Seller Rating", heading_xf)
1348
    sheet.write(0, 19, "Lowest Seller Rating", heading_xf)
1337
    sheet.write(0, 18, "Lowest Seller Shipping Time", heading_xf)
1349
    sheet.write(0, 20, "Lowest Seller Shipping Time", heading_xf)
1338
    sheet.write(0, 19, "Second Lowest Seller SP", heading_xf)
1350
    sheet.write(0, 21, "Second Lowest Seller SP", heading_xf)
1339
    sheet.write(0, 20, "Second Lowest Seller Rating", heading_xf)
1351
    sheet.write(0, 22, "Second Lowest Seller Rating", heading_xf)
1340
    sheet.write(0, 21, "Second Lowest Seller Shipping Time", heading_xf)
1352
    sheet.write(0, 23, "Second Lowest Seller Shipping Time", heading_xf)
1341
    sheet.write(0, 22, "Third Lowest Seller SP", heading_xf)
1353
    sheet.write(0, 24, "Third Lowest Seller SP", heading_xf)
1342
    sheet.write(0, 23, "Third Lowest Seller Rating", heading_xf)
1354
    sheet.write(0, 25, "Third Lowest Seller Rating", heading_xf)
1343
    sheet.write(0, 24, "Third Lowest Seller Shipping Time", heading_xf)
1355
    sheet.write(0, 26, "Third Lowest Seller Shipping Time", heading_xf)
1344
    sheet.write(0, 25, "Lowest MFN Ignored", heading_xf)
1356
    sheet.write(0, 27, "Lowest MFN Ignored", heading_xf)
1345
    sheet.write(0, 26, "Lowest MFN", heading_xf)
1357
    sheet.write(0, 28, "Lowest MFN", heading_xf)
1346
    sheet.write(0, 27, "Lowest FBA", heading_xf)
1358
    sheet.write(0, 29, "Lowest FBA", heading_xf)
1347
    sheet.write(0, 28, "Competitive Price", heading_xf)
1359
    sheet.write(0, 30, "Competitive Price", heading_xf)
1348
    sheet.write(0, 29, "Other Cost", heading_xf)
1360
    sheet.write(0, 31, "Other Cost", heading_xf)
1349
    sheet.write(0, 30, "WANLC", heading_xf)
1361
    sheet.write(0, 32, "WANLC", heading_xf)
-
 
1362
    sheet.write(0, 33, "Overridden WANLC", heading_xf)
1350
    sheet.write(0, 31, "Subsidy", heading_xf)
1363
    sheet.write(0, 34, "Subsidy", heading_xf)
1351
    sheet.write(0, 32, "MAX SALE PRICE", heading_xf)
1364
    sheet.write(0, 35, "MAX SALE PRICE", heading_xf)
1352
    sheet.write(0, 33, "Commission", heading_xf)
1365
    sheet.write(0, 36, "Commission", heading_xf)
1353
    sheet.write(0, 34, "Competitor Commission", heading_xf)
1366
    sheet.write(0, 37, "Competitor Commission", heading_xf)
1354
    sheet.write(0, 35, "Return Provision", heading_xf)
1367
    sheet.write(0, 38, "Return Provision", heading_xf)
1355
    sheet.write(0, 36, "Vat Rate", heading_xf)
1368
    sheet.write(0, 39, "Vat Rate", heading_xf)
1356
    sheet.write(0, 37, "Margin", heading_xf)
1369
    sheet.write(0, 40, "Margin", heading_xf)
1357
    sheet.write(0, 38, "Proposed Sp", heading_xf)
1370
    sheet.write(0, 41, "Proposed Sp", heading_xf)
1358
    sheet.write(0, 39, "Avg Sale", heading_xf)
1371
    sheet.write(0, 42, "Avg Sale", heading_xf)
1359
    sheet.write(0, 40, "NOD", heading_xf)
1372
    sheet.write(0, 43, "NOD", heading_xf)
1360
    sheet.write(0, 41, "Sales History", heading_xf)
1373
    sheet.write(0, 44, "Sales History", heading_xf)
1361
    sheet.write(0, 42, "Decision", heading_xf)
1374
    sheet.write(0, 45, "Decision", heading_xf)
1362
    sheet.write(0, 43, "Reason", heading_xf)
1375
    sheet.write(0, 46, "Reason", heading_xf)
1363
    sheet.write(0, 44, "Updated Price", heading_xf)
1376
    sheet.write(0, 47, "Updated Price", heading_xf)
1364
    sheet.write(0, 45, "Proposed Margin", heading_xf)
1377
    sheet.write(0, 48, "Proposed Margin", heading_xf)
1365
    sheet.write(0, 46, "Inventory Movement Status", heading_xf)
1378
    sheet.write(0, 49, "Inventory Movement Status", heading_xf)
1366
 
1379
 
1367
def getPackagingCost(data):
1380
def getPackagingCost(data):
1368
    #TODO : Get packagingCost from marketplaceitems table
1381
    #TODO : Get packagingCost from marketplaceitems table
1369
    return 15
1382
    return 15
1370
 
1383
 
Line 1533... Line 1546...
1533
    sheet_iterator = 1
1546
    sheet_iterator = 1
1534
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1547
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1535
    for cantCompeteItem in cantCompeteItems:
1548
    for cantCompeteItem in cantCompeteItems:
1536
        amScraping =  cantCompeteItem[0]
1549
        amScraping =  cantCompeteItem[0]
1537
        item = cantCompeteItem[1]
1550
        item = cantCompeteItem[1]
1538
        print "Item = ",item
-
 
1539
        sheet.write(sheet_iterator, 0, amScraping.item_id)
1551
        sheet.write(sheet_iterator, 0, amScraping.item_id)
1540
        if amScraping.warehouseLocation == 1:
1552
        if amScraping.warehouseLocation == 1:
1541
            sku = 'FBA'+str(amScraping.item_id)
1553
            sku = 'FBA'+str(amScraping.item_id)
1542
            loc = 'MUMBAI'
1554
            loc = 'MUMBAI'
1543
        else:
1555
        else:
1544
            sku = 'FBB'+str(amScraping.item_id)
1556
            sku = 'FBB'+str(amScraping.item_id)
1545
            loc = 'BANGLORE'
1557
            loc = 'BANGLORE'
1546
        sheet.write(sheet_iterator, 1, sku)
1558
        sheet.write(sheet_iterator, 1, sku)
1547
        sheet.write(sheet_iterator, 2, amScraping.asin)
1559
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
1560
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
1548
        sheet.write(sheet_iterator, 3, loc)
1561
        sheet.write(sheet_iterator, 4, loc)
1549
        sheet.write(sheet_iterator, 4, item.brand)
1562
        sheet.write(sheet_iterator, 5, item.brand)
1550
        sheet.write(sheet_iterator, 5, getCategory(item))
1563
        sheet.write(sheet_iterator, 6, getCategory(item))
1551
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1564
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1552
        sheet.write(sheet_iterator, 7, item.weight)
1565
        sheet.write(sheet_iterator, 8, item.weight)
1553
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
1566
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
1567
        sheet.write(sheet_iterator, 10, item.mrp)
1554
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
1568
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
1555
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
1569
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
1556
        if amScraping.isPromotion:
1570
        if amScraping.isPromotion:
1557
            sheet.write(sheet_iterator, 11, "Yes")
1571
            sheet.write(sheet_iterator, 13, "Yes")
1558
        else:
1572
        else:
1559
            sheet.write(sheet_iterator, 11, "No")
1573
            sheet.write(sheet_iterator, 13, "No")
1560
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
1574
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
1561
        if amScraping.ourRank > 3:
1575
        if amScraping.ourRank > 3:
1562
            sheet.write(sheet_iterator, 13, 'Greater than 3')
1576
            sheet.write(sheet_iterator, 15, 'Greater than 3')
1563
        else:
1577
        else:
1564
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
1578
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
1565
        sheet.write(sheet_iterator, 14, 'Cant Compete')
1579
        sheet.write(sheet_iterator, 16, 'Cant Compete')
1566
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
1580
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
1567
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
1581
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
1568
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
1582
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
1569
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
1583
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
1570
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
1584
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
1571
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
1585
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
1572
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
1586
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
1573
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
1587
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
1574
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
1588
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
1575
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
1589
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
1576
        sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
1590
        sheet.write(sheet_iterator, 27, amScraping.lowestMfnIgnoredOffer)
1577
        sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
1591
        sheet.write(sheet_iterator, 28, amScraping.lowestMfnOffer)
1578
        sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
1592
        sheet.write(sheet_iterator, 29, amScraping.lowestFbaOffer)
1579
        sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
1593
        sheet.write(sheet_iterator, 30, amScraping.competitivePrice)
1580
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
1594
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
1581
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
1595
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
1596
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
1582
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
1597
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
1583
        if amScraping.isPromotion:
1598
        if amScraping.isPromotion:
1584
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1599
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1585
        else:
1600
        else:
1586
            sheet.write(sheet_iterator, 32, 0.0)
1601
            sheet.write(sheet_iterator, 35, 0.0)
1587
        sheet.write(sheet_iterator, 33, amScraping.commission)
1602
        sheet.write(sheet_iterator, 36, amScraping.commission)
1588
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
1603
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
1589
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
1604
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
1590
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
1605
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
1591
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
1606
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
1592
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
1607
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
1593
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
1608
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
1594
        try:
1609
        try:
1595
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1610
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1596
        except:
1611
        except:
1597
            daysOfStock = float("inf")
1612
            daysOfStock = float("inf")
1598
        if str(daysOfStock)=='inf':
1613
        if str(daysOfStock)=='inf':
1599
            sheet.write(sheet_iterator, 40, str(daysOfStock))
1614
            sheet.write(sheet_iterator, 43, str(daysOfStock))
1600
        else:
1615
        else:
1601
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
1616
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
1602
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
1617
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
1603
        #sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
1618
        #sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
1604
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1619
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1605
        sheet_iterator+=1
1620
        sheet_iterator+=1
1606
    #TODO : Take excell sheet generation code inside a function 
1621
    #TODO : Take excell sheet generation code inside a function 
1607
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1622
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1608
    for competitiveItem in competitiveItems:
1623
    for competitiveItem in competitiveItems:
1609
        amScraping =  competitiveItem[0]
1624
        amScraping =  competitiveItem[0]
Line 1615... Line 1630...
1615
        else:
1630
        else:
1616
            sku = 'FBB'+str(amScraping.item_id)
1631
            sku = 'FBB'+str(amScraping.item_id)
1617
            loc = 'BANGLORE'
1632
            loc = 'BANGLORE'
1618
        sheet.write(sheet_iterator, 1, sku)
1633
        sheet.write(sheet_iterator, 1, sku)
1619
        sheet.write(sheet_iterator, 2, amScraping.asin)
1634
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
1635
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
1620
        sheet.write(sheet_iterator, 3, loc)
1636
        sheet.write(sheet_iterator, 4, loc)
1621
        sheet.write(sheet_iterator, 4, item.brand)
1637
        sheet.write(sheet_iterator, 5, item.brand)
1622
        sheet.write(sheet_iterator, 5, getCategory(item))
1638
        sheet.write(sheet_iterator, 6, getCategory(item))
1623
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1639
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1624
        sheet.write(sheet_iterator, 7, item.weight)
1640
        sheet.write(sheet_iterator, 8, item.weight)
1625
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
1641
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
1642
        sheet.write(sheet_iterator, 10, item.mrp)
1626
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
1643
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
1627
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
1644
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
1628
        if amScraping.isPromotion:
1645
        if amScraping.isPromotion:
1629
            sheet.write(sheet_iterator, 11, "Yes")
1646
            sheet.write(sheet_iterator, 13, "Yes")
1630
        else:
1647
        else:
1631
            sheet.write(sheet_iterator, 11, "No")
1648
            sheet.write(sheet_iterator, 13, "No")
1632
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
1649
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
1633
        if amScraping.ourRank > 3:
1650
        if amScraping.ourRank > 3:
1634
            sheet.write(sheet_iterator, 13, 'Greater than 3')
1651
            sheet.write(sheet_iterator, 15, 'Greater than 3')
1635
        else:
1652
        else:
1636
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
1653
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
1637
        sheet.write(sheet_iterator, 14, 'Competitive')
1654
        sheet.write(sheet_iterator, 16, 'Competitive')
1638
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
1655
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
1639
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
1656
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
1640
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
1657
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
1641
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
1658
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
1642
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
1659
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
1643
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
1660
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
1644
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
1661
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
1645
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
1662
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
1646
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
1663
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
1647
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
1664
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
1648
        sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
1665
        sheet.write(sheet_iterator, 27, amScraping.lowestMfnIgnoredOffer)
1649
        sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
1666
        sheet.write(sheet_iterator, 28, amScraping.lowestMfnOffer)
1650
        sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
1667
        sheet.write(sheet_iterator, 29, amScraping.lowestFbaOffer)
1651
        sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
1668
        sheet.write(sheet_iterator, 30, amScraping.competitivePrice)
1652
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
1669
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
1653
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
1670
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
1671
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
1654
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
1672
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
1655
        if amScraping.isPromotion:
1673
        if amScraping.isPromotion:
1656
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1674
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1657
        else:
1675
        else:
1658
            sheet.write(sheet_iterator, 32, 0.0)
1676
            sheet.write(sheet_iterator, 35, 0.0)
1659
        sheet.write(sheet_iterator, 33, amScraping.commission)
1677
        sheet.write(sheet_iterator, 36, amScraping.commission)
1660
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
1678
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
1661
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
1679
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
1662
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
1680
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
1663
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
1681
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
1664
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
1682
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
1665
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
1683
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
1666
        try:
1684
        try:
1667
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1685
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1668
        except:
1686
        except:
1669
            daysOfStock = float("inf")
1687
            daysOfStock = float("inf")
1670
        if str(daysOfStock)=='inf':
1688
        if str(daysOfStock)=='inf':
1671
            sheet.write(sheet_iterator, 40, str(daysOfStock))
1689
            sheet.write(sheet_iterator, 43, str(daysOfStock))
1672
        else:
1690
        else:
1673
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
1691
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
1674
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
1692
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
1675
        if amScraping.decision is None:
1693
        if amScraping.decision is None:
1676
            sheet.write(sheet_iterator, 42, 'Auto Pricing Inactive')
1694
            sheet.write(sheet_iterator, 45, 'Auto Pricing Inactive')
1677
            sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1695
            sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1678
            sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1696
            sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1679
            sheet_iterator+=1
1697
            sheet_iterator+=1
1680
            continue
1698
            continue
1681
        sheet.write(sheet_iterator, 42, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1699
        sheet.write(sheet_iterator, 45, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1682
        sheet.write(sheet_iterator, 43, amScraping.reason)
1700
        sheet.write(sheet_iterator, 46, amScraping.reason)
1683
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1701
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1684
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.proposedSp))
1702
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.proposedSp))
1685
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1703
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1686
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1704
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1687
        sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1705
        sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1688
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1706
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1689
        sheet_iterator+=1
1707
        sheet_iterator+=1
1690
    
1708
    
1691
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1709
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1692
    for almostCompetitiveItem in almostCompetitiveItems:
1710
    for almostCompetitiveItem in almostCompetitiveItems:
1693
        amScraping =  almostCompetitiveItem[0]
1711
        amScraping =  almostCompetitiveItem[0]
Line 1699... Line 1717...
1699
        else:
1717
        else:
1700
            sku = 'FBB'+str(amScraping.item_id)
1718
            sku = 'FBB'+str(amScraping.item_id)
1701
            loc = 'BANGLORE'
1719
            loc = 'BANGLORE'
1702
        sheet.write(sheet_iterator, 1, sku)
1720
        sheet.write(sheet_iterator, 1, sku)
1703
        sheet.write(sheet_iterator, 2, amScraping.asin)
1721
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
1722
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
1704
        sheet.write(sheet_iterator, 3, loc)
1723
        sheet.write(sheet_iterator, 4, loc)
1705
        sheet.write(sheet_iterator, 4, item.brand)
1724
        sheet.write(sheet_iterator, 5, item.brand)
1706
        sheet.write(sheet_iterator, 5, getCategory(item))
1725
        sheet.write(sheet_iterator, 6, getCategory(item))
1707
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1726
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1708
        sheet.write(sheet_iterator, 7, item.weight)
1727
        sheet.write(sheet_iterator, 8, item.weight)
1709
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
1728
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
1729
        sheet.write(sheet_iterator, 10, item.mrp)
1710
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
1730
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
1711
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
1731
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
1712
        if amScraping.isPromotion:
1732
        if amScraping.isPromotion:
1713
            sheet.write(sheet_iterator, 11, "Yes")
1733
            sheet.write(sheet_iterator, 13, "Yes")
1714
        else:
1734
        else:
1715
            sheet.write(sheet_iterator, 11, "No")
1735
            sheet.write(sheet_iterator, 13, "No")
1716
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
1736
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
1717
        if amScraping.ourRank > 3:
1737
        if amScraping.ourRank > 3:
1718
            sheet.write(sheet_iterator, 13, 'Greater than 3')
1738
            sheet.write(sheet_iterator, 15, 'Greater than 3')
1719
        else:
1739
        else:
1720
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
1740
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
1721
        sheet.write(sheet_iterator, 14, 'Almost Competitive')
1741
        sheet.write(sheet_iterator, 16, 'Almost Competitive')
1722
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
1742
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
1723
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
1743
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
1724
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
1744
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
1725
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
1745
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
1726
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
1746
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
1727
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
1747
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
1728
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
1748
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
1729
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
1749
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
1730
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
1750
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
1731
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
1751
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
1732
        sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
1752
        sheet.write(sheet_iterator, 27, amScraping.lowestMfnIgnoredOffer)
1733
        sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
1753
        sheet.write(sheet_iterator, 28, amScraping.lowestMfnOffer)
1734
        sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
1754
        sheet.write(sheet_iterator, 29, amScraping.lowestFbaOffer)
1735
        sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
1755
        sheet.write(sheet_iterator, 30, amScraping.competitivePrice)
1736
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
1756
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
1737
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
1757
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
1758
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
1738
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
1759
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
1739
        if amScraping.isPromotion:
1760
        if amScraping.isPromotion:
1740
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1761
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1741
        else:
1762
        else:
1742
            sheet.write(sheet_iterator, 32, 0.0)
1763
            sheet.write(sheet_iterator, 35, 0.0)
1743
        sheet.write(sheet_iterator, 33, amScraping.commission)
1764
        sheet.write(sheet_iterator, 36, amScraping.commission)
1744
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
1765
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
1745
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
1766
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
1746
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
1767
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
1747
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
1768
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
1748
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
1769
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
1749
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
1770
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
1750
        try:
1771
        try:
1751
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1772
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1752
        except:
1773
        except:
1753
            daysOfStock = float("inf")
1774
            daysOfStock = float("inf")
1754
        if str(daysOfStock)=='inf':
1775
        if str(daysOfStock)=='inf':
1755
            sheet.write(sheet_iterator, 40, str(daysOfStock))
1776
            sheet.write(sheet_iterator, 43, str(daysOfStock))
1756
        else:
1777
        else:
1757
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
1778
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
1758
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
1779
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
1759
        if amScraping.decision is None:
1780
        if amScraping.decision is None:
1760
            sheet.write(sheet_iterator, 42, 'Auto Pricing Inactive')
1781
            sheet.write(sheet_iterator, 45, 'Auto Pricing Inactive')
1761
            sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1782
            sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1762
            sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1783
            sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1763
            sheet_iterator+=1
1784
            sheet_iterator+=1
1764
            continue
1785
            continue
1765
        sheet.write(sheet_iterator, 42, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1786
        sheet.write(sheet_iterator, 45, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1766
        sheet.write(sheet_iterator, 43, amScraping.reason)
1787
        sheet.write(sheet_iterator, 46, amScraping.reason)
1767
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1788
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1768
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.proposedSp))
1789
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.proposedSp))
1769
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1790
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1770
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1791
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1771
        sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1792
        sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1772
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1793
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1773
        sheet_iterator+=1
1794
        sheet_iterator+=1
1774
    
1795
    
1775
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1796
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1776
    for amongCheapestItem in amongCheapestItems:
1797
    for amongCheapestItem in amongCheapestItems:
1777
        amScraping =  amongCheapestItem[0]
1798
        amScraping =  amongCheapestItem[0]
Line 1783... Line 1804...
1783
        else:
1804
        else:
1784
            sku = 'FBB'+str(amScraping.item_id)
1805
            sku = 'FBB'+str(amScraping.item_id)
1785
            loc = 'BANGLORE'
1806
            loc = 'BANGLORE'
1786
        sheet.write(sheet_iterator, 1, sku)
1807
        sheet.write(sheet_iterator, 1, sku)
1787
        sheet.write(sheet_iterator, 2, amScraping.asin)
1808
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
1809
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
1788
        sheet.write(sheet_iterator, 3, loc)
1810
        sheet.write(sheet_iterator, 4, loc)
1789
        sheet.write(sheet_iterator, 4, item.brand)
1811
        sheet.write(sheet_iterator, 5, item.brand)
1790
        sheet.write(sheet_iterator, 5, getCategory(item))
1812
        sheet.write(sheet_iterator, 6, getCategory(item))
1791
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1813
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1792
        sheet.write(sheet_iterator, 7, item.weight)
1814
        sheet.write(sheet_iterator, 8, item.weight)
1793
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
1815
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
1816
        sheet.write(sheet_iterator, 10, item.mrp)
1794
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
1817
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
1795
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
1818
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
1796
        if amScraping.isPromotion:
1819
        if amScraping.isPromotion:
1797
            sheet.write(sheet_iterator, 11, "Yes")
1820
            sheet.write(sheet_iterator, 13, "Yes")
1798
        else:
1821
        else:
1799
            sheet.write(sheet_iterator, 11, "No")
1822
            sheet.write(sheet_iterator, 13, "No")
1800
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
1823
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
1801
        if amScraping.ourRank > 3:
1824
        if amScraping.ourRank > 3:
1802
            sheet.write(sheet_iterator, 13, 'Greater than 3')
1825
            sheet.write(sheet_iterator, 15, 'Greater than 3')
1803
        else:
1826
        else:
1804
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
1827
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
1805
        sheet.write(sheet_iterator, 14, 'Among Cheapest')
1828
        sheet.write(sheet_iterator, 16, 'Among Cheapest')
1806
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
1829
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
1807
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
1830
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
1808
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
1831
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
1809
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
1832
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
1810
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
1833
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
1811
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
1834
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
1812
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
1835
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
1813
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
1836
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
1814
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
1837
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
1815
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
1838
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
1816
        sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
1839
        sheet.write(sheet_iterator, 27, amScraping.lowestMfnIgnoredOffer)
1817
        sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
1840
        sheet.write(sheet_iterator, 28, amScraping.lowestMfnOffer)
1818
        sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
1841
        sheet.write(sheet_iterator, 29, amScraping.lowestFbaOffer)
1819
        sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
1842
        sheet.write(sheet_iterator, 30, amScraping.competitivePrice)
1820
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
1843
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
1821
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
1844
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
1845
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
1822
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
1846
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
1823
        if amScraping.isPromotion:
1847
        if amScraping.isPromotion:
1824
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1848
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1825
        else:
1849
        else:
1826
            sheet.write(sheet_iterator, 32, 0.0)
1850
            sheet.write(sheet_iterator, 35, 0.0)
1827
        sheet.write(sheet_iterator, 33, amScraping.commission)
1851
        sheet.write(sheet_iterator, 36, amScraping.commission)
1828
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
1852
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
1829
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
1853
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
1830
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
1854
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
1831
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
1855
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
1832
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
1856
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
1833
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
1857
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
1834
        try:
1858
        try:
1835
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1859
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1836
        except:
1860
        except:
1837
            daysOfStock = float("inf")
1861
            daysOfStock = float("inf")
1838
        if str(daysOfStock)=='inf':
1862
        if str(daysOfStock)=='inf':
1839
            sheet.write(sheet_iterator, 40, str(daysOfStock))
1863
            sheet.write(sheet_iterator, 43, str(daysOfStock))
1840
        else:
1864
        else:
1841
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
1865
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
1842
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
1866
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
1843
        if amScraping.decision is None:
1867
        if amScraping.decision is None:
1844
            sheet.write(sheet_iterator, 42, 'Auto Pricing Inactive')
1868
            sheet.write(sheet_iterator, 45, 'Auto Pricing Inactive')
1845
            sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1869
            sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1846
            sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1870
            sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1847
            sheet_iterator+=1
1871
            sheet_iterator+=1
1848
            continue
1872
            continue
1849
        sheet.write(sheet_iterator, 42, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1873
        sheet.write(sheet_iterator, 45, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1850
        sheet.write(sheet_iterator, 43, amScraping.reason)
1874
        sheet.write(sheet_iterator, 46, amScraping.reason)
1851
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1875
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1852
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.proposedSp))
1876
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.proposedSp))
1853
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1877
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1854
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1878
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1855
        sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
1879
        sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1856
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
1880
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1857
        sheet_iterator+=1
1881
        sheet_iterator+=1
1858
    
1882
    
1859
#    sheet = wbk.add_sheet('Cheapest')
1883
#    sheet = wbk.add_sheet('Cheapest')
1860
#    xstr = lambda s: s or ""
1884
#    xstr = lambda s: s or ""
1861
#    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1885
#    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1913... Line 1937...
1913
        else:
1937
        else:
1914
            sku = 'FBB'+str(amScraping.item_id)
1938
            sku = 'FBB'+str(amScraping.item_id)
1915
            loc = 'BANGLORE'
1939
            loc = 'BANGLORE'
1916
        sheet.write(sheet_iterator, 1, sku)
1940
        sheet.write(sheet_iterator, 1, sku)
1917
        sheet.write(sheet_iterator, 2, amScraping.asin)
1941
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
1942
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
1918
        sheet.write(sheet_iterator, 3, loc)
1943
        sheet.write(sheet_iterator, 4, loc)
1919
        sheet.write(sheet_iterator, 4, item.brand)
1944
        sheet.write(sheet_iterator, 5, item.brand)
1920
        sheet.write(sheet_iterator, 5, getCategory(item))
1945
        sheet.write(sheet_iterator, 6, getCategory(item))
1921
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1946
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1922
        sheet.write(sheet_iterator, 7, item.weight)
1947
        sheet.write(sheet_iterator, 8, item.weight)
1923
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
1948
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
1949
        sheet.write(sheet_iterator, 10, item.mrp)
1924
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
1950
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
1925
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
1951
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
1926
        if amScraping.isPromotion:
1952
        if amScraping.isPromotion:
1927
            sheet.write(sheet_iterator, 11, "Yes")
1953
            sheet.write(sheet_iterator, 13, "Yes")
1928
        else:
1954
        else:
1929
            sheet.write(sheet_iterator, 11, "No")
1955
            sheet.write(sheet_iterator, 13, "No")
1930
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
1956
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
1931
        if amScraping.ourRank > 3:
1957
        if amScraping.ourRank > 3:
1932
            sheet.write(sheet_iterator, 13, 'Greater than 3')
1958
            sheet.write(sheet_iterator, 15, 'Greater than 3')
1933
        else:
1959
        else:
1934
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
1960
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
1935
        sheet.write(sheet_iterator, 14, 'Cheapest')
1961
        sheet.write(sheet_iterator, 16, 'Cheapest')
1936
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
1962
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
1937
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
1963
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
1938
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
1964
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
1939
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
1965
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
1940
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
1966
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
1941
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
1967
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
1942
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
1968
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
1943
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
1969
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
1944
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
1970
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
1945
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
1971
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
1946
        sheet.write(sheet_iterator, 25, '')
-
 
1947
        sheet.write(sheet_iterator, 26, '')
-
 
1948
        sheet.write(sheet_iterator, 27, '')
1972
        sheet.write(sheet_iterator, 27, '')
1949
        sheet.write(sheet_iterator, 28, '')
1973
        sheet.write(sheet_iterator, 28, '')
-
 
1974
        sheet.write(sheet_iterator, 29, '')
-
 
1975
        sheet.write(sheet_iterator, 30, '')
1950
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
1976
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
1951
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
1977
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
1978
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
1952
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
1979
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
1953
        if amScraping.isPromotion:
1980
        if amScraping.isPromotion:
1954
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1981
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
1955
        else:
1982
        else:
1956
            sheet.write(sheet_iterator, 32, 0.0)
1983
            sheet.write(sheet_iterator, 35, 0.0)
1957
        sheet.write(sheet_iterator, 33, amScraping.commission)
1984
        sheet.write(sheet_iterator, 36, amScraping.commission)
1958
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
1985
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
1959
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
1986
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
1960
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
1987
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
1961
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
1988
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
1962
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
1989
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
1963
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
1990
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
1964
        try:
1991
        try:
1965
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1992
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
1966
        except:
1993
        except:
1967
            daysOfStock = float("inf")
1994
            daysOfStock = float("inf")
1968
        if str(daysOfStock)=='inf':
1995
        if str(daysOfStock)=='inf':
1969
            sheet.write(sheet_iterator, 40, str(daysOfStock))
1996
            sheet.write(sheet_iterator, 43, str(daysOfStock))
1970
        else:
1997
        else:
1971
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
1998
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
1972
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
1999
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
1973
        if amScraping.decision is None:
2000
        if amScraping.decision is None:
1974
            sheet.write(sheet_iterator, 42, 'Auto Pricing Inactive')
2001
            sheet.write(sheet_iterator, 45, 'Auto Pricing Inactive')
1975
            sheet.write(sheet_iterator, 45, getNewMargin(amScraping,amScraping.proposedSp))
2002
            sheet.write(sheet_iterator, 48, getNewMargin(amScraping,amScraping.proposedSp))
1976
            sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
2003
            sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1977
            sheet_iterator+=1
2004
            sheet_iterator+=1
1978
            continue
2005
            continue
1979
        sheet.write(sheet_iterator, 42, Decision._VALUES_TO_NAMES.get(amScraping.decision))
2006
        sheet.write(sheet_iterator, 45, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1980
        sheet.write(sheet_iterator, 43, amScraping.reason)
2007
        sheet.write(sheet_iterator, 46, amScraping.reason)
1981
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
2008
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1982
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.proposedSp))
2009
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.proposedSp))
1983
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2010
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1984
            sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
2011
            sheet.write(sheet_iterator, 47, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
1985
        sheet.write(sheet_iterator, 45, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
2012
        sheet.write(sheet_iterator, 48, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
1986
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
2013
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
1987
        sheet_iterator+=1
2014
        sheet_iterator+=1
1988
    
2015
    
1989
    exceptionCheapItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp)\
2016
    exceptionCheapItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp)\
1990
    .filter(or_(AmazonScrapingHistory.exceptionType==3,AmazonScrapingHistory.exceptionType==5)).all()
2017
    .filter(or_(AmazonScrapingHistory.exceptionType==3,AmazonScrapingHistory.exceptionType==5)).all()
1991
    
2018
    
Line 1999... Line 2026...
1999
        else:
2026
        else:
2000
            sku = 'FBB'+str(amScraping.item_id)
2027
            sku = 'FBB'+str(amScraping.item_id)
2001
            loc = 'BANGLORE'
2028
            loc = 'BANGLORE'
2002
        sheet.write(sheet_iterator, 1, sku)
2029
        sheet.write(sheet_iterator, 1, sku)
2003
        sheet.write(sheet_iterator, 2, amScraping.asin)
2030
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
2031
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
2004
        sheet.write(sheet_iterator, 3, loc)
2032
        sheet.write(sheet_iterator, 4, loc)
2005
        sheet.write(sheet_iterator, 4, item.brand)
2033
        sheet.write(sheet_iterator, 5, item.brand)
2006
        sheet.write(sheet_iterator, 5, getCategory(item))
2034
        sheet.write(sheet_iterator, 6, getCategory(item))
2007
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
2035
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
2008
        sheet.write(sheet_iterator, 7, item.weight)
2036
        sheet.write(sheet_iterator, 8, item.weight)
2009
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
2037
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
2038
        sheet.write(sheet_iterator, 10, item.mrp)
2010
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
2039
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
2011
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
2040
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
2012
        if amScraping.isPromotion:
2041
        if amScraping.isPromotion:
2013
            sheet.write(sheet_iterator, 11, "Yes")
2042
            sheet.write(sheet_iterator, 13, "Yes")
2014
        else:
2043
        else:
2015
            sheet.write(sheet_iterator, 11, "No")
2044
            sheet.write(sheet_iterator, 13, "No")
2016
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
2045
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
2017
        if amScraping.ourRank > 3:
2046
        if amScraping.ourRank > 3:
2018
            sheet.write(sheet_iterator, 13, 'Greater than 3')
2047
            sheet.write(sheet_iterator, 15, 'Greater than 3')
2019
        else:
2048
        else:
2020
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
2049
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
2021
        sheet.write(sheet_iterator, 14, 'Cheapest')
2050
        sheet.write(sheet_iterator, 16, 'Cheapest')
2022
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
2051
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
2023
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
2052
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
2024
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
2053
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
2025
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
2054
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
2026
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
2055
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
2027
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
2056
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
2028
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
2057
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
2029
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
2058
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
2030
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
2059
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
2031
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
2060
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
2032
        sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
2061
        sheet.write(sheet_iterator, 27, amScraping.lowestMfnIgnoredOffer)
2033
        sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
2062
        sheet.write(sheet_iterator, 28, amScraping.lowestMfnOffer)
2034
        sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
2063
        sheet.write(sheet_iterator, 29, amScraping.lowestFbaOffer)
2035
        sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
2064
        sheet.write(sheet_iterator, 30, amScraping.competitivePrice)
2036
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
2065
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
2037
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
2066
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
2067
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
2038
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
2068
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
2039
        if amScraping.isPromotion:
2069
        if amScraping.isPromotion:
2040
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
2070
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
2041
        else:
2071
        else:
2042
            sheet.write(sheet_iterator, 32, 0.0)
2072
            sheet.write(sheet_iterator, 35, 0.0)
2043
        sheet.write(sheet_iterator, 33, amScraping.commission)
2073
        sheet.write(sheet_iterator, 36, amScraping.commission)
2044
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
2074
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
2045
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
2075
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
2046
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
2076
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
2047
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
2077
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
2048
        sheet.write(sheet_iterator, 38, amScraping.proposedSp)
2078
        sheet.write(sheet_iterator, 41, amScraping.proposedSp)
2049
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
2079
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
2050
        try:
2080
        try:
2051
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2081
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2052
        except:
2082
        except:
2053
            daysOfStock = float("inf")
2083
            daysOfStock = float("inf")
2054
        if str(daysOfStock)=='inf':
2084
        if str(daysOfStock)=='inf':
2055
            sheet.write(sheet_iterator, 40, str(daysOfStock))
2085
            sheet.write(sheet_iterator, 43, str(daysOfStock))
2056
        else:
2086
        else:
2057
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
2087
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
2058
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
2088
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
2059
        sheet.write(sheet_iterator, 42, 'AUTO_INCREMENT_FAILED')
2089
        sheet.write(sheet_iterator, 45, 'AUTO_INCREMENT_FAILED')
2060
        if amScraping.exceptionType==3:
2090
        if amScraping.exceptionType==3:
2061
            sheet.write(sheet_iterator, 43, 'We are the only seller')
2091
            sheet.write(sheet_iterator, 46, 'We are the only seller')
2062
        else:
2092
        else:
2063
            sheet.write(sheet_iterator, 43, amScraping.reason)
2093
            sheet.write(sheet_iterator, 46, amScraping.reason)
2064
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
2094
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
2065
        sheet_iterator+=1
2095
        sheet_iterator+=1
2066
 
2096
 
2067
    
2097
    
2068
#    sheet = wbk.add_sheet('Negative Margin')
2098
#    sheet = wbk.add_sheet('Negative Margin')
2069
#    xstr = lambda s: s or ""
2099
#    xstr = lambda s: s or ""
Line 2119... Line 2149...
2119
        else:
2149
        else:
2120
            sku = 'FBB'+str(amScraping.item_id)
2150
            sku = 'FBB'+str(amScraping.item_id)
2121
            loc = 'BANGLORE'
2151
            loc = 'BANGLORE'
2122
        sheet.write(sheet_iterator, 1, sku)
2152
        sheet.write(sheet_iterator, 1, sku)
2123
        sheet.write(sheet_iterator, 2, amScraping.asin)
2153
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
2154
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
2124
        sheet.write(sheet_iterator, 3, loc)
2155
        sheet.write(sheet_iterator, 4, loc)
2125
        sheet.write(sheet_iterator, 4, item.brand)
2156
        sheet.write(sheet_iterator, 5, item.brand)
2126
        sheet.write(sheet_iterator, 5, getCategory(item))
2157
        sheet.write(sheet_iterator, 6, getCategory(item))
2127
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
2158
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
2128
        sheet.write(sheet_iterator, 7, item.weight)
2159
        sheet.write(sheet_iterator, 8, item.weight)
2129
        sheet.write(sheet_iterator, 8, amScraping.courierCost)
2160
        sheet.write(sheet_iterator, 9, amScraping.courierCost)
-
 
2161
        sheet.write(sheet_iterator, 10, item.mrp)
2130
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
2162
        sheet.write(sheet_iterator, 11, amScraping.ourSellingPrice)
2131
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
2163
        sheet.write(sheet_iterator, 12, amScraping.promoPrice)
2132
        if amScraping.isPromotion:
2164
        if amScraping.isPromotion:
2133
            sheet.write(sheet_iterator, 11, "Yes")
2165
            sheet.write(sheet_iterator, 13, "Yes")
2134
        else:
2166
        else:
2135
            sheet.write(sheet_iterator, 11, "No")
2167
            sheet.write(sheet_iterator, 13, "No")
2136
        sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
2168
        sheet.write(sheet_iterator, 14, amScraping.lowestPossibleSp)
2137
        if amScraping.ourRank > 3:
2169
        if amScraping.ourRank > 3:
2138
            sheet.write(sheet_iterator, 13, 'Greater than 3')
2170
            sheet.write(sheet_iterator, 15, 'Greater than 3')
2139
        else:
2171
        else:
2140
            sheet.write(sheet_iterator, 13, amScraping.ourRank)
2172
            sheet.write(sheet_iterator, 15, amScraping.ourRank)
2141
        sheet.write(sheet_iterator, 14, 'Negative Margin')
2173
        sheet.write(sheet_iterator, 16, 'Negative Margin')
2142
        sheet.write(sheet_iterator, 15, amScraping.ourInventory)
2174
        sheet.write(sheet_iterator, 17, amScraping.ourInventory)
2143
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
2175
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerSp)
2144
        sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
2176
        sheet.write(sheet_iterator, 19, amScraping.lowestSellerRating)
2145
        sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
2177
        sheet.write(sheet_iterator, 20, amScraping.lowestSellerShippingTime)
2146
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
2178
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerSp)
2147
        sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
2179
        sheet.write(sheet_iterator, 22, amScraping.secondLowestSellerRating)
2148
        sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
2180
        sheet.write(sheet_iterator, 23, amScraping.secondLowestSellerShippingTime)
2149
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
2181
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerSp)
2150
        sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
2182
        sheet.write(sheet_iterator, 25, amScraping.thirdLowestSellerRating)
2151
        sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
2183
        sheet.write(sheet_iterator, 26, amScraping.thirdLowestSellerShippingTime)
2152
        sheet.write(sheet_iterator, 25, '')
-
 
2153
        sheet.write(sheet_iterator, 26, '')
-
 
2154
        sheet.write(sheet_iterator, 27, '')
2184
        sheet.write(sheet_iterator, 27, '')
2155
        sheet.write(sheet_iterator, 28, '')
2185
        sheet.write(sheet_iterator, 28, '')
-
 
2186
        sheet.write(sheet_iterator, 29, '')
-
 
2187
        sheet.write(sheet_iterator, 30, '')
2156
        sheet.write(sheet_iterator, 29, amScraping.otherCost)
2188
        sheet.write(sheet_iterator, 31, amScraping.otherCost)
2157
        sheet.write(sheet_iterator, 30, amScraping.wanlc)
2189
        sheet.write(sheet_iterator, 32, amScraping.wanlc)
-
 
2190
        sheet.write(sheet_iterator, 33, amScraping.isNlcOverridden)
2158
        sheet.write(sheet_iterator, 31, amScraping.subsidy)
2191
        sheet.write(sheet_iterator, 34, amScraping.subsidy)
2159
        if amScraping.isPromotion:
2192
        if amScraping.isPromotion:
2160
            sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
2193
            sheet.write(sheet_iterator, 35, getMsp(amScraping.item_id,amScraping.warehouseLocation))
2161
        else:
2194
        else:
2162
            sheet.write(sheet_iterator, 32, 0.0)
2195
            sheet.write(sheet_iterator, 35, 0.0)
2163
        sheet.write(sheet_iterator, 33, amScraping.commission)
2196
        sheet.write(sheet_iterator, 36, amScraping.commission)
2164
        sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
2197
        sheet.write(sheet_iterator, 37, amScraping.competitorCommission)
2165
        sheet.write(sheet_iterator, 35, amScraping.returnProvision)
2198
        sheet.write(sheet_iterator, 38, amScraping.returnProvision)
2166
        sheet.write(sheet_iterator, 36, amScraping.vatRate)
2199
        sheet.write(sheet_iterator, 39, amScraping.vatRate)
2167
        sheet.write(sheet_iterator, 37, getMargin(amScraping))
2200
        sheet.write(sheet_iterator, 40, getMargin(amScraping))
2168
        sheet.write(sheet_iterator, 39, amScraping.avgSale)
2201
        sheet.write(sheet_iterator, 42, amScraping.avgSale)
2169
        try:
2202
        try:
2170
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2203
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2171
        except:
2204
        except:
2172
            daysOfStock = float("inf")
2205
            daysOfStock = float("inf")
2173
        if str(daysOfStock)=='inf':
2206
        if str(daysOfStock)=='inf':
2174
            sheet.write(sheet_iterator, 40, str(daysOfStock))
2207
            sheet.write(sheet_iterator, 43, str(daysOfStock))
2175
        else:
2208
        else:
2176
            sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
2209
            sheet.write(sheet_iterator, 43, str(round(daysOfStock,1)))
2177
        sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
2210
        sheet.write(sheet_iterator, 44, getOosString(saleMap.get(sku)))
2178
        sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
2211
        sheet.write(sheet_iterator, 49, getInventoryMovementStatus(amScraping))
2179
        sheet_iterator+=1
2212
        sheet_iterator+=1
2180
    
2213
    
2181
    sheet = wbk.add_sheet('Exception List')
2214
    sheet = wbk.add_sheet('Exception List')
2182
    xstr = lambda s: s or ""
2215
    xstr = lambda s: s or ""
2183
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
2216
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 2187... Line 2220...
2187
    integer_style.num_format_str = excel_integer_format
2220
    integer_style.num_format_str = excel_integer_format
2188
    
2221
    
2189
    sheet.write(0, 0, "Item Id", heading_xf)
2222
    sheet.write(0, 0, "Item Id", heading_xf)
2190
    sheet.write(0, 1, "Amazon Sku", heading_xf)
2223
    sheet.write(0, 1, "Amazon Sku", heading_xf)
2191
    sheet.write(0, 2, "Asin", heading_xf)
2224
    sheet.write(0, 2, "Asin", heading_xf)
-
 
2225
    sheet.write(0, 3, "URL", heading_xf)
2192
    sheet.write(0, 3, "Location", heading_xf)
2226
    sheet.write(0, 4, "Location", heading_xf)
2193
    sheet.write(0, 4, "Brand", heading_xf)
2227
    sheet.write(0, 5, "Brand", heading_xf)
2194
    sheet.write(0, 5, "Category", heading_xf)
2228
    sheet.write(0, 6, "Category", heading_xf)
2195
    sheet.write(0, 6, "Product Name", heading_xf)
2229
    sheet.write(0, 7, "Product Name", heading_xf)
-
 
2230
    sheet.write(0, 8, "MRP", heading_xf)
2196
    sheet.write(0, 7, "Selling Price", heading_xf)
2231
    sheet.write(0, 9, "Selling Price", heading_xf)
2197
    sheet.write(0, 8, "Promo Price", heading_xf)
2232
    sheet.write(0, 10, "Promo Price", heading_xf)
2198
    sheet.write(0, 9, "Inventory", heading_xf)
2233
    sheet.write(0, 11, "Inventory", heading_xf)
2199
    sheet.write(0, 10, "Avg Sale", heading_xf)
2234
    sheet.write(0, 12, "Avg Sale", heading_xf)
2200
    sheet.write(0, 11, "NOD", heading_xf)
2235
    sheet.write(0, 13, "NOD", heading_xf)
2201
    sheet.write(0, 12, "Sales History", heading_xf)
2236
    sheet.write(0, 14, "Sales History", heading_xf)
2202
    sheet.write(0, 13, "Inventory Movement Status", heading_xf)
2237
    sheet.write(0, 15, "Inventory Movement Status", heading_xf)
2203
    sheet.write(0, 14, "Reason", heading_xf)
2238
    sheet.write(0, 16, "Reason", heading_xf)
2204
    
2239
    
2205
    sheet_iterator = 1
2240
    sheet_iterator = 1
2206
    exceptionListItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
2241
    exceptionListItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
2207
    for exceptionListItem in exceptionListItems:
2242
    for exceptionListItem in exceptionListItems:
2208
        amScraping =  exceptionListItem[0]
2243
        amScraping =  exceptionListItem[0]
Line 2216... Line 2251...
2216
        else:
2251
        else:
2217
            sku = 'FBB'+str(amScraping.item_id)
2252
            sku = 'FBB'+str(amScraping.item_id)
2218
            loc = 'BANGLORE'
2253
            loc = 'BANGLORE'
2219
        sheet.write(sheet_iterator, 1, sku)
2254
        sheet.write(sheet_iterator, 1, sku)
2220
        sheet.write(sheet_iterator, 2, amScraping.asin)
2255
        sheet.write(sheet_iterator, 2, amScraping.asin)
-
 
2256
        sheet.write(sheet_iterator, 3, 'http://www.amazon.in/dp/'+amScraping.asin)
2221
        sheet.write(sheet_iterator, 3, loc)
2257
        sheet.write(sheet_iterator, 4, loc)
2222
        sheet.write(sheet_iterator, 4, item.brand)
2258
        sheet.write(sheet_iterator, 5, item.brand)
2223
        sheet.write(sheet_iterator, 5, getCategory(item))
2259
        sheet.write(sheet_iterator, 6, getCategory(item))
2224
        sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
2260
        sheet.write(sheet_iterator, 7, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
-
 
2261
        sheet.write(sheet_iterator, 8, item.mrp)
2225
        sheet.write(sheet_iterator, 7, amScraping.ourSellingPrice)
2262
        sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
2226
        sheet.write(sheet_iterator, 8, amScraping.promoPrice)
2263
        sheet.write(sheet_iterator, 10, amScraping.promoPrice)
2227
        sheet.write(sheet_iterator, 9, amScraping.ourInventory)
2264
        sheet.write(sheet_iterator, 11, amScraping.ourInventory)
2228
        sheet.write(sheet_iterator, 10, amScraping.avgSale)
2265
        sheet.write(sheet_iterator, 12, amScraping.avgSale)
2229
        try:
2266
        try:
2230
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2267
            daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
2231
        except:
2268
        except:
2232
            daysOfStock = float("inf")
2269
            daysOfStock = float("inf")
2233
        if str(daysOfStock)=='inf':
2270
        if str(daysOfStock)=='inf':
2234
            sheet.write(sheet_iterator, 11, str(daysOfStock))
2271
            sheet.write(sheet_iterator, 13, str(daysOfStock))
2235
        else:
2272
        else:
2236
            sheet.write(sheet_iterator, 11, str(round(daysOfStock,1)))
2273
            sheet.write(sheet_iterator, 13, str(round(daysOfStock,1)))
2237
        sheet.write(sheet_iterator, 12, getOosString(saleMap.get(sku)))
2274
        sheet.write(sheet_iterator, 14, getOosString(saleMap.get(sku)))
2238
        sheet.write(sheet_iterator, 13, getInventoryMovementStatus(amScraping))
2275
        sheet.write(sheet_iterator, 15, getInventoryMovementStatus(amScraping))
2239
        sheet.write(sheet_iterator, 14, amScraping.reason)
2276
        sheet.write(sheet_iterator, 16, amScraping.reason)
2240
        sheet_iterator+=1      
2277
        sheet_iterator+=1      
2241
    
2278
    
2242
    
2279
    
2243
    if (runType in ('FULL','FULL-OTHER')):    
2280
    if (runType in ('FULL','FULL-OTHER')):    
2244
        sheet = wbk.add_sheet('Auto Favorites')
2281
        sheet = wbk.add_sheet('Auto Favorites')