Subversion Repositories SmartDukaan

Rev

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

Rev 15665 Rev 15695
Line 51... Line 51...
51
 
51
 
52
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
52
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
53
 
53
 
54
class __AmazonItemInfo:
54
class __AmazonItemInfo:
55
    
55
    
56
    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):
56
    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, \
-
 
57
                 packagingLength, packagingWidth, packagingHeight, packagingWeight, isOversized):
57
        self.asin = asin
58
        self.asin = asin
58
        self.nlc = nlc
59
        self.nlc = nlc
59
        self.courierCost = courierCost
60
        self.courierCost = courierCost
60
        self.sku = sku
61
        self.sku = sku
61
        self.product_group = product_group
62
        self.product_group = product_group
Line 73... Line 74...
73
        self.ourInventory = ourInventory
74
        self.ourInventory = ourInventory
74
        self.state_id = state_id
75
        self.state_id = state_id
75
        self.otherCost = otherCost
76
        self.otherCost = otherCost
76
        self.exceptionType = exceptionType
77
        self.exceptionType = exceptionType
77
        self.isNlcOverridden = isNlcOverridden
78
        self.isNlcOverridden = isNlcOverridden
-
 
79
        self.packagingLength = packagingLength
-
 
80
        self.packagingWidth = packagingWidth
-
 
81
        self.packagingHeight = packagingHeight
-
 
82
        self.packagingWeight = packagingWeight
-
 
83
        self.isOversized = isOversized
-
 
84
        
78
 
85
 
79
class __AmazonDetails:
86
class __AmazonDetails:
80
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
87
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
81
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
88
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
82
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, \
89
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, \
Line 599... Line 606...
599
            state_id = 3
606
            state_id = 3
600
        else:
607
        else:
601
            continue
608
            continue
602
        cc = computeCourierCost(it.weight)
609
        cc = computeCourierCost(it.weight)
603
            
610
            
604
        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)
611
        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, \
-
 
612
                                          d_amazon_listed.packagingLength, d_amazon_listed.packagingWidth, d_amazon_listed.packagingHeight, d_amazon_listed.packagingWeight, checkOverSize(d_amazon_listed))
605
        itemInfo.append(amazonItemInfo)
613
        itemInfo.append(amazonItemInfo)
606
    #amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
614
    #amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
607
    #.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
615
    #.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
608
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
616
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
609
    .order_by(desc(AmazonPromotion.addedOn)).all()
617
    .order_by(desc(AmazonPromotion.addedOn)).all()
Line 999... Line 1007...
999
            amazonScrapingHistory.timestamp = timestamp
1007
            amazonScrapingHistory.timestamp = timestamp
1000
            amazonScrapingHistory.multipleListings = amDetails.multipleListings
1008
            amazonScrapingHistory.multipleListings = amDetails.multipleListings
1001
            amazonScrapingHistory.isPromotion = val.isPromo
1009
            amazonScrapingHistory.isPromotion = val.isPromo
1002
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1010
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1003
        amazonScrapingHistory.timestamp = timestamp
1011
        amazonScrapingHistory.timestamp = timestamp
-
 
1012
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1013
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1014
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1015
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1016
        amazonScrapingHistory.isOversized = val.isOversized 
1004
    session.commit()
1017
    session.commit()
1005
 
1018
 
1006
def commitNegativeMargin(negativeMargin,timestamp,runType):
1019
def commitNegativeMargin(negativeMargin,timestamp,runType):
1007
    for negativeMarginItem in negativeMargin:
1020
    for negativeMarginItem in negativeMargin:
1008
        val = negativeMarginItem[0]
1021
        val = negativeMarginItem[0]
Line 1056... Line 1069...
1056
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
1069
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
1057
        amazonScrapingHistory.timestamp = timestamp
1070
        amazonScrapingHistory.timestamp = timestamp
1058
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1071
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1059
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1072
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1060
        amazonScrapingHistory.isPromotion = val.isPromo
1073
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1074
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1075
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1076
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1077
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1078
        amazonScrapingHistory.isOversized = val.isOversized 
1061
    session.commit()
1079
    session.commit()
1062
        
1080
        
1063
 
1081
 
1064
def commitCheapest(cheapest,timestamp,runType):
1082
def commitCheapest(cheapest,timestamp,runType):
1065
    for cheapestItem in cheapest:
1083
    for cheapestItem in cheapest:
Line 1122... Line 1140...
1122
        #amazonScrapingHistory.proposedTp = proposed_tp
1140
        #amazonScrapingHistory.proposedTp = proposed_tp
1123
        #amazonScrapingHistory.marginIncreasedPotential = proposed_tp - amPricing.ourTp
1141
        #amazonScrapingHistory.marginIncreasedPotential = proposed_tp - amPricing.ourTp
1124
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1142
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1125
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1143
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1126
        amazonScrapingHistory.isPromotion = val.isPromo
1144
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1145
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1146
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1147
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1148
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1149
        amazonScrapingHistory.isOversized = val.isOversized 
1127
    session.commit()
1150
    session.commit()
1128
 
1151
 
1129
 
1152
 
1130
 
1153
 
1131
def commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,runType):
1154
def commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,runType):
Line 1193... Line 1216...
1193
        amazonScrapingHistory.proposedSp = proposed_sp
1216
        amazonScrapingHistory.proposedSp = proposed_sp
1194
        #amazonScrapingHistory.proposedTp = proposed_tp
1217
        #amazonScrapingHistory.proposedTp = proposed_tp
1195
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1218
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1196
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1219
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1197
        amazonScrapingHistory.isPromotion = val.isPromo
1220
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1221
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1222
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1223
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1224
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1225
        amazonScrapingHistory.isOversized = val.isOversized 
1198
    session.commit()
1226
    session.commit()
1199
 
1227
 
1200
def commitCanCompete(canCompete,timestamp,runType):
1228
def commitCanCompete(canCompete,timestamp,runType):
1201
    for canCompeteItem in canCompete:
1229
    for canCompeteItem in canCompete:
1202
        val = canCompeteItem[0]
1230
        val = canCompeteItem[0]
Line 1262... Line 1290...
1262
        amazonScrapingHistory.proposedSp = proposed_sp
1290
        amazonScrapingHistory.proposedSp = proposed_sp
1263
        #amazonScrapingHistory.proposedTp = proposed_tp
1291
        #amazonScrapingHistory.proposedTp = proposed_tp
1264
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1292
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1265
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1293
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1266
        amazonScrapingHistory.isPromotion = val.isPromo
1294
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1295
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1296
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1297
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1298
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1299
        amazonScrapingHistory.isOversized = val.isOversized 
1267
    session.commit()
1300
    session.commit()
1268
 
1301
 
1269
def commitAlmostCompete(almostCompete,timestamp,runType):
1302
def commitAlmostCompete(almostCompete,timestamp,runType):
1270
    for almostCompeteItem in almostCompete:
1303
    for almostCompeteItem in almostCompete:
1271
        val = almostCompeteItem[0]
1304
        val = almostCompeteItem[0]
Line 1333... Line 1366...
1333
        #amazonScrapingHistory.proposedTp = proposed_tp
1366
        #amazonScrapingHistory.proposedTp = proposed_tp
1334
        #amazonScrapingHistory.targetNlc = target_nlc
1367
        #amazonScrapingHistory.targetNlc = target_nlc
1335
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1368
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1336
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1369
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1337
        amazonScrapingHistory.isPromotion = val.isPromo
1370
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1371
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1372
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1373
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1374
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1375
        amazonScrapingHistory.isOversized = val.isOversized 
1338
    session.commit()
1376
    session.commit()
1339
 
1377
 
1340
 
1378
 
1341
def commitCantCompete(cantCompete, timestamp,runType):
1379
def commitCantCompete(cantCompete, timestamp,runType):
1342
    for cantCompeteItem in cantCompete:
1380
    for cantCompeteItem in cantCompete:
Line 1405... Line 1443...
1405
        #amazonScrapingHistory.proposedTp = proposed_tp
1443
        #amazonScrapingHistory.proposedTp = proposed_tp
1406
        #amazonScrapingHistory.targetNlc = target_nlc
1444
        #amazonScrapingHistory.targetNlc = target_nlc
1407
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1445
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
1408
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1446
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
1409
        amazonScrapingHistory.isPromotion = val.isPromo
1447
        amazonScrapingHistory.isPromotion = val.isPromo
-
 
1448
        amazonScrapingHistory.packagingHeight = val.packagingHeight
-
 
1449
        amazonScrapingHistory.packagingLength = val.packagingLength
-
 
1450
        amazonScrapingHistory.packagingWidth = val.packagingWidth
-
 
1451
        amazonScrapingHistory.packagingWeight = val.packagingWeight
-
 
1452
        amazonScrapingHistory.isOversized = val.isOversized 
1410
    session.commit()
1453
    session.commit()
1411
 
1454
 
1412
def markAutoFavourites(time):
1455
def markAutoFavourites(time):
1413
    nowAutoFav = []
1456
    nowAutoFav = []
1414
    previouslyAutoFav = []
1457
    previouslyAutoFav = []
Line 1520... Line 1563...
1520
    sheet.write(0, 54, "Decision", heading_xf)
1563
    sheet.write(0, 54, "Decision", heading_xf)
1521
    sheet.write(0, 55, "Reason", heading_xf)
1564
    sheet.write(0, 55, "Reason", heading_xf)
1522
    sheet.write(0, 56, "Updated Price", heading_xf)
1565
    sheet.write(0, 56, "Updated Price", heading_xf)
1523
    sheet.write(0, 57, "Proposed Margin", heading_xf)
1566
    sheet.write(0, 57, "Proposed Margin", heading_xf)
1524
    sheet.write(0, 58, "Inventory Movement Status", heading_xf)
1567
    sheet.write(0, 58, "Inventory Movement Status", heading_xf)
-
 
1568
    sheet.write(0, 59, "Packaging Length", heading_xf)
-
 
1569
    sheet.write(0, 60, "Packaging Width", heading_xf)
-
 
1570
    sheet.write(0, 61, "Packaging Height", heading_xf)
-
 
1571
    sheet.write(0, 62, "Packaging Weight", heading_xf)
-
 
1572
    sheet.write(0, 63, "Oversized Item", heading_xf)
-
 
1573
    
1525
 
1574
 
1526
def getPackagingCost(data):
1575
def getPackagingCost(data):
1527
    #TODO : Get packagingCost from marketplaceitems table
1576
    #TODO : Get packagingCost from marketplaceitems table
1528
    return 15
1577
    return 15
1529
 
1578
 
Line 1750... Line 1799...
1750
        sheet.write(sheet_iterator, 52, toDaysSale[0])
1799
        sheet.write(sheet_iterator, 52, toDaysSale[0])
1751
        sheet.write(sheet_iterator, 53, str(toDaysSale[1]))
1800
        sheet.write(sheet_iterator, 53, str(toDaysSale[1]))
1752
        
1801
        
1753
        #sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
1802
        #sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
1754
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
1803
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
1804
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
1805
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
1806
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
1807
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
1808
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
1755
        sheet_iterator+=1
1809
        sheet_iterator+=1
1756
    #TODO : Take excell sheet generation code inside a function 
1810
    #TODO : Take excell sheet generation code inside a function 
1757
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1811
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1758
    for competitiveItem in competitiveItems:
1812
    for competitiveItem in competitiveItems:
1759
        amScraping =  competitiveItem[0]
1813
        amScraping =  competitiveItem[0]
Line 1856... Line 1910...
1856
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
1910
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
1857
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1911
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1858
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
1912
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
1859
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
1913
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
1860
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
1914
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
1915
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
1916
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
1917
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
1918
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
1919
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
1861
        sheet_iterator+=1
1920
        sheet_iterator+=1
1862
    
1921
    
1863
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1922
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
1864
    for almostCompetitiveItem in almostCompetitiveItems:
1923
    for almostCompetitiveItem in almostCompetitiveItems:
1865
        amScraping =  almostCompetitiveItem[0]
1924
        amScraping =  almostCompetitiveItem[0]
Line 1962... Line 2021...
1962
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
2021
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
1963
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2022
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1964
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
2023
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
1965
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
2024
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
1966
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
2025
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
2026
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
2027
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
2028
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
2029
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
2030
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
1967
        sheet_iterator+=1
2031
        sheet_iterator+=1
1968
    
2032
    
1969
    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()
2033
    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()
1970
    for amongCheapestItem in amongCheapestItems:
2034
    for amongCheapestItem in amongCheapestItems:
1971
        amScraping =  amongCheapestItem[0]
2035
        amScraping =  amongCheapestItem[0]
Line 2068... Line 2132...
2068
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
2132
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
2069
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2133
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2070
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
2134
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
2071
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
2135
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,amScraping.proposedSp))
2072
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
2136
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
2137
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
2138
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
2139
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
2140
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
2141
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
2073
        sheet_iterator+=1
2142
        sheet_iterator+=1
2074
        
2143
        
2075
    
2144
    
2076
#    sheet = wbk.add_sheet('Cheapest')
2145
#    sheet = wbk.add_sheet('Cheapest')
2077
#    xstr = lambda s: s or ""
2146
#    xstr = lambda s: s or ""
Line 2221... Line 2290...
2221
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
2290
            sheet.write(sheet_iterator, 56, math.ceil(amScraping.proposedSp))
2222
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2291
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
2223
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
2292
            sheet.write(sheet_iterator, 56, min(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)),amScraping.proposedSp))
2224
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
2293
        sheet.write(sheet_iterator, 57, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
2225
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
2294
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
2295
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
2296
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
2297
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
2298
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
2299
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
2226
        sheet_iterator+=1
2300
        sheet_iterator+=1
2227
    
2301
    
2228
    exceptionCheapItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp)\
2302
    exceptionCheapItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp)\
2229
    .filter(or_(AmazonScrapingHistory.exceptionType==3,AmazonScrapingHistory.exceptionType==5)).all()
2303
    .filter(or_(AmazonScrapingHistory.exceptionType==3,AmazonScrapingHistory.exceptionType==5)).all()
2230
    
2304
    
Line 2321... Line 2395...
2321
        if amScraping.exceptionType==3:
2395
        if amScraping.exceptionType==3:
2322
            sheet.write(sheet_iterator, 55, 'We are the only seller')
2396
            sheet.write(sheet_iterator, 55, 'We are the only seller')
2323
        else:
2397
        else:
2324
            sheet.write(sheet_iterator, 55, amScraping.reason)
2398
            sheet.write(sheet_iterator, 55, amScraping.reason)
2325
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
2399
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
2400
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
2401
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
2402
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
2403
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
2404
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
2326
        sheet_iterator+=1
2405
        sheet_iterator+=1
2327
 
2406
 
2328
    
2407
    
2329
#    sheet = wbk.add_sheet('Negative Margin')
2408
#    sheet = wbk.add_sheet('Negative Margin')
2330
#    xstr = lambda s: s or ""
2409
#    xstr = lambda s: s or ""
Line 2457... Line 2536...
2457
        sheet.write(sheet_iterator, 51, getAvgSale(inStockStats[2], inStockStats[1]))
2536
        sheet.write(sheet_iterator, 51, getAvgSale(inStockStats[2], inStockStats[1]))
2458
        toDaysSale = getTodaysSale(sku)
2537
        toDaysSale = getTodaysSale(sku)
2459
        sheet.write(sheet_iterator, 52, toDaysSale[0])
2538
        sheet.write(sheet_iterator, 52, toDaysSale[0])
2460
        sheet.write(sheet_iterator, 53, str(toDaysSale[1]))
2539
        sheet.write(sheet_iterator, 53, str(toDaysSale[1]))
2461
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
2540
        sheet.write(sheet_iterator, 58, getInventoryMovementStatus(amScraping))
-
 
2541
        sheet.write(sheet_iterator, 59, amScraping.packagingLength)
-
 
2542
        sheet.write(sheet_iterator, 60, amScraping.packagingWidth)
-
 
2543
        sheet.write(sheet_iterator, 61, amScraping.packagingHeight)
-
 
2544
        sheet.write(sheet_iterator, 62, amScraping.packagingWeight)
-
 
2545
        sheet.write(sheet_iterator, 63, amScraping.isOversized)
2462
        sheet_iterator+=1
2546
        sheet_iterator+=1
2463
    
2547
    
2464
    sheet = wbk.add_sheet('Exception List')
2548
    sheet = wbk.add_sheet('Exception List')
2465
    xstr = lambda s: s or ""
2549
    xstr = lambda s: s or ""
2466
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
2550
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 2493... Line 2577...
2493
    sheet.write(0, 21, "Avg Sale Since InStock (Excluding Today)", heading_xf)
2577
    sheet.write(0, 21, "Avg Sale Since InStock (Excluding Today)", heading_xf)
2494
    sheet.write(0, 22, "Todays Sale Snapshot Time", heading_xf)
2578
    sheet.write(0, 22, "Todays Sale Snapshot Time", heading_xf)
2495
    sheet.write(0, 23, "Todays Sale", heading_xf)
2579
    sheet.write(0, 23, "Todays Sale", heading_xf)
2496
    sheet.write(0, 24, "Inventory Movement Status", heading_xf)
2580
    sheet.write(0, 24, "Inventory Movement Status", heading_xf)
2497
    sheet.write(0, 25, "Reason", heading_xf)
2581
    sheet.write(0, 25, "Reason", heading_xf)
-
 
2582
    sheet.write(0, 26, "Packaging Length", heading_xf)
-
 
2583
    sheet.write(0, 27, "Packaging Width", heading_xf)
-
 
2584
    sheet.write(0, 28, "Packaging Height", heading_xf)
-
 
2585
    sheet.write(0, 29, "Packaging Weight", heading_xf)
-
 
2586
    sheet.write(0, 30, "Oversized Item", heading_xf)
-
 
2587
    
2498
    
2588
    
2499
    sheet_iterator = 1
2589
    sheet_iterator = 1
2500
    exceptionListItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
2590
    exceptionListItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
2501
    for exceptionListItem in exceptionListItems:
2591
    for exceptionListItem in exceptionListItems:
2502
        amScraping =  exceptionListItem[0]
2592
        amScraping =  exceptionListItem[0]
Line 2550... Line 2640...
2550
        toDaysSale = getTodaysSale(sku)
2640
        toDaysSale = getTodaysSale(sku)
2551
        sheet.write(sheet_iterator, 22, toDaysSale[0])
2641
        sheet.write(sheet_iterator, 22, toDaysSale[0])
2552
        sheet.write(sheet_iterator, 23, str(toDaysSale[1]))
2642
        sheet.write(sheet_iterator, 23, str(toDaysSale[1]))
2553
        sheet.write(sheet_iterator, 24, getInventoryMovementStatus(amScraping))
2643
        sheet.write(sheet_iterator, 24, getInventoryMovementStatus(amScraping))
2554
        sheet.write(sheet_iterator, 25, amScraping.reason)
2644
        sheet.write(sheet_iterator, 25, amScraping.reason)
-
 
2645
        sheet.write(sheet_iterator, 26, amScraping.packagingLength)
-
 
2646
        sheet.write(sheet_iterator, 27, amScraping.packagingWidth)
-
 
2647
        sheet.write(sheet_iterator, 28, amScraping.packagingHeight)
-
 
2648
        sheet.write(sheet_iterator, 29, amScraping.packagingWeight)
-
 
2649
        sheet.write(sheet_iterator, 30, amScraping.isOversized)
2555
        sheet_iterator+=1      
2650
        sheet_iterator+=1      
2556
    
2651
    
2557
    
2652
    
2558
    if (runType in ('FULL','FULL-OTHER')):    
2653
    if (runType in ('FULL','FULL-OTHER')):    
2559
        sheet = wbk.add_sheet('Auto Favorites')
2654
        sheet = wbk.add_sheet('Auto Favorites')
Line 3178... Line 3273...
3178
            am_listed.isFbg = True
3273
            am_listed.isFbg = True
3179
        else:
3274
        else:
3180
            pass
3275
            pass
3181
    session.commit()
3276
    session.commit()
3182
 
3277
 
-
 
3278
def checkOverSize(d_amazon_listed):
-
 
3279
    try:
-
 
3280
        if d_amazon_listed.packagingWeight * .453592 > 12 or d_amazon_listed.packagingLength > 20 or d_amazon_listed.packagingWidth > 16 or d_amazon_listed.packagingHeight > 10:
-
 
3281
            return True
-
 
3282
        else:
-
 
3283
            return False
-
 
3284
    except:
-
 
3285
        return False 
-
 
3286
 
3183
def main():
3287
def main():
3184
    parser = optparse.OptionParser()
3288
    parser = optparse.OptionParser()
3185
    parser.add_option("-t", "--type", dest="runType",
3289
    parser.add_option("-t", "--type", dest="runType",
3186
                   default="FULL", type="string",
3290
                   default="FULL", type="string",
3187
                   help="Run type FULL or FAVOURITE or FULL-OTHER")
3291
                   help="Run type FULL or FAVOURITE or FULL-OTHER")