Subversion Repositories SmartDukaan

Rev

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

Rev 12430 Rev 12432
Line 24... Line 24...
24
config_client = ConfigClient()
24
config_client = ConfigClient()
25
host = config_client.get_property('staging_hostname')
25
host = config_client.get_property('staging_hostname')
26
syncPrice=config_client.get_property('sync_price_on_marketplace')
26
syncPrice=config_client.get_property('sync_price_on_marketplace')
27
 
27
 
28
amazonAsinPrice={}
28
amazonAsinPrice={}
29
amazonLongTermActivePromotions = []
29
amazonLongTermActivePromotions = {}
30
amazonShortTermActivePromotions = []
30
amazonShortTermActivePromotions = {}
31
saleMap = {}
31
saleMap = {}
32
DataService.initialize(db_hostname=host)
32
DataService.initialize(db_hostname=host)
33
 
33
 
34
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
34
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
35
 
35
 
Line 83... Line 83...
83
        self.thirdLowestSellerType = thirdLowestSellerType    
83
        self.thirdLowestSellerType = thirdLowestSellerType    
84
           
84
           
85
 
85
 
86
class __AmazonPricing:
86
class __AmazonPricing:
87
    
87
    
88
    def __init__(self, ourSp, ourTp, lowestPossibleTp, lowestPossibleSp):
88
    def __init__(self, ourSp, lowestPossibleSp):
89
        self.ourTp = ourTp
-
 
90
        self.lowestPossibleTp = lowestPossibleTp
-
 
91
        self.ourSp = ourSp
89
        self.ourSp = ourSp
92
        self.lowestPossibleSp = lowestPossibleSp
90
        self.lowestPossibleSp = lowestPossibleSp
93
 
91
 
-
 
92
class __Promotion:
-
 
93
    def __init__(self, promoPrice, subsidy, promotionType):
-
 
94
        self.promoPrice = promoPrice
-
 
95
        self.subsidy = subsidy
-
 
96
        self.promotionType = promotionType
-
 
97
    
-
 
98
 
94
 
99
 
95
def fetchItemsForAutoDecrease(time):
100
def fetchItemsForAutoDecrease(time):
96
    successfulAutoDecrease = []
101
    successfulAutoDecrease = []
97
    autoDecrementItems = session.query(AmazonScrapingHistory).join((Amazonlisted,AmazonScrapingHistory.item_id==Amazonlisted.itemId))\
102
    autoDecrementItems = session.query(AmazonScrapingHistory).join((Amazonlisted,AmazonScrapingHistory.item_id==Amazonlisted.itemId))\
98
    .filter(AmazonScrapingHistory.timestamp==time).filter(or_(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE,AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE, AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE ))\
103
    .filter(AmazonScrapingHistory.timestamp==time).filter(or_(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE,AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE, AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE ))\
Line 100... Line 105...
100
    for autoDecrementItem in autoDecrementItems:
105
    for autoDecrementItem in autoDecrementItems:
101
        if autoDecrementItem.warehouseLocation == 1:
106
        if autoDecrementItem.warehouseLocation == 1:
102
            sku = 'FBA'+str(autoDecrementItem.item_id)
107
            sku = 'FBA'+str(autoDecrementItem.item_id)
103
        else:
108
        else:
104
            sku = 'FBB'+str(autoDecrementItem.item_id)
109
            sku = 'FBB'+str(autoDecrementItem.item_id)
105
        if sku in amazonShortTermActivePromotions:
110
        if amazonShortTermActivePromotions.has_key(sku):
106
            markReasonForItem(autoDecrementItem,'Item in short term promotion',Decision.AUTO_DECREMENT_FAILED)
111
            markReasonForItem(autoDecrementItem,'Item in short term promotion',Decision.AUTO_DECREMENT_FAILED)
107
            continue
112
            continue
108
        if math.ceil(autoDecrementItem.proposedSp) >= autoDecrementItem.ourSellingPrice:
113
        if math.ceil(autoDecrementItem.proposedSp) >= autoDecrementItem.ourSellingPrice:
109
            markReasonForItem(autoDecrementItem,'Proposed SP greater than or equal to current SP',Decision.AUTO_DECREMENT_FAILED)
114
            markReasonForItem(autoDecrementItem,'Proposed SP greater than or equal to current SP',Decision.AUTO_DECREMENT_FAILED)
110
            continue
115
            continue
Line 144... Line 149...
144
    for autoIncrementItem in autoIncrementItems:
149
    for autoIncrementItem in autoIncrementItems:
145
        if autoIncrementItem.warehouseLocation == 1:
150
        if autoIncrementItem.warehouseLocation == 1:
146
            sku = 'FBA'+str(autoIncrementItem.item_id)
151
            sku = 'FBA'+str(autoIncrementItem.item_id)
147
        else:
152
        else:
148
            sku = 'FBB'+str(autoIncrementItem.item_id)
153
            sku = 'FBB'+str(autoIncrementItem.item_id)
149
        if sku in amazonShortTermActivePromotions:
154
        if amazonShortTermActivePromotions.has_key(sku):
150
            markReasonForItem(autoIncrementItem,'Item in short term promotion',Decision.AUTO_INCREMENT_FAILED)
155
            markReasonForItem(autoIncrementItem,'Item in short term promotion',Decision.AUTO_INCREMENT_FAILED)
151
            continue
156
            continue
152
        if autoIncrementItem.totalSeller==1 and autoIncrementItem.ourRank==1:
157
        if autoIncrementItem.totalSeller==1 and autoIncrementItem.ourRank==1:
153
            markReasonForItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
158
            markReasonForItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
154
            continue 
159
            continue 
Line 355... Line 360...
355
        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)
360
        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)
356
        itemInfo.append(amazonItemInfo)
361
        itemInfo.append(amazonItemInfo)
357
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
362
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
358
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
363
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
359
    for amPromotion in amPromotions:
364
    for amPromotion in amPromotions:
360
        amazonLongTermActivePromotions.append(amPromotion.sku)
365
        amazonLongTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType)
361
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.SHORTTERM).filter(AmazonPromotion.promotionActive==True) \
366
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.SHORTTERM).filter(AmazonPromotion.promotionActive==True) \
362
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
367
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
363
    for amPromotion in amPromotions:
368
    for amPromotion in amPromotions:
364
        amazonShortTermActivePromotions.append(amPromotion.sku)
369
        amazonShortTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType)
365
    session.close()
370
    session.close()
366
    return itemInfo
371
    return itemInfo
367
 
372
 
368
def getPriceAndAsin(itemInfo):
373
def getPriceAndAsin(itemInfo):
369
    skus = []
374
    skus = []
Line 407... Line 412...
407
        val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
412
        val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
408
        val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
413
        val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
409
        val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
414
        val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
410
        iterator = 0
415
        iterator = 0
411
        sku, lowestSellerName,secondLowestSellerName, thirdLowestSellerName = ('',)*4
416
        sku, lowestSellerName,secondLowestSellerName, thirdLowestSellerName = ('',)*4
412
        ourSp, ourRank, lowestSellerSp, secondLowestSellerSp, thirdLowestSellerSp, ourTp, lowestPossibleSp, lowestPossibleTp = (0,)*8
417
        ourSp, ourRank, lowestSellerSp, secondLowestSellerSp, thirdLowestSellerSp, lowestPossibleSp = (0,)*6
413
        lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
418
        lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
414
        thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType = (0,)*9
419
        thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType = (0,)*9
415
        isPromo = False
420
        isPromo = False
416
        sku = val.sku
421
        sku = val.sku
417
        scrapedSkuLocation = None
-
 
418
        multipleListings = False
422
        multipleListings = False
419
        ourSkuDetails = ourPricingForSku.get(val.sku)
423
        ourSkuDetails = ourPricingForSku.get(val.sku)
-
 
424
        if not (ourSkuDetails.promotion and (amazonLongTermActivePromotions.has_key(val.sku) or amazonShortTermActivePromotions.has_key(val.sku))):
-
 
425
            temp = []
-
 
426
            temp.append(val)
-
 
427
            temp.append("Promo misconfigured")
-
 
428
            continue
-
 
429
            
420
        scrapInfo.append(ourSkuDetails)
430
        scrapInfo.append(ourSkuDetails)
421
        sortedScrapInfo =  sorted(scrapInfo, key=itemgetter('promoPrice','notOurSku'))
431
        sortedScrapInfo =  sorted(scrapInfo, key=itemgetter('promoPrice','notOurSku'))
422
        for info in sortedScrapInfo:
432
        for info in sortedScrapInfo:
423
            if  not info.notOurSku:
433
            if  not info.notOurSku:
424
                ourSp = info.sellingPrice
434
                ourSp = info.sellingPrice
Line 475... Line 485...
475
            temp.append(val)
485
            temp.append(val)
476
            temp.append("Vat not available")
486
            temp.append("Vat not available")
477
            exceptionList.append(temp)
487
            exceptionList.append(temp)
478
            continue
488
            continue
479
        
489
        
480
        ourTp = getOurTp(amDetails,val,val.sourcePercentage)
-
 
481
        lowestPossibleTp = getLowestPossibleTp(amDetails,val,val.sourcePercentage)
-
 
482
        lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
490
        lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
483
        print "Creating pricing obj"
491
        print "Creating pricing obj"
484
        amPricing = __AmazonPricing(ourSp,ourTp,lowestPossibleTp,lowestPossibleSp)
492
        amPricing = __AmazonPricing(ourSp,lowestPossibleSp)
485
        
493
        
486
        if amPricing.ourTp < amPricing.lowestPossibleTp:
494
        if amPricing.promoPrice < amPricing.lowestPossibleSp:
487
            temp = []
495
            temp = []
488
            temp.append(val)
496
            temp.append(val)
489
            temp.append(amDetails)
497
            temp.append(amDetails)
490
            temp.append(amPricing)
498
            temp.append(amPricing)
491
            negativeMargin.append(temp)
499
            negativeMargin.append(temp)
Line 531... Line 539...
531
        cantCompete.append(temp)
539
        cantCompete.append(temp)
532
    print "Created category..."
540
    print "Created category..."
533
        
541
        
534
    return exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete
542
    return exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete
535
 
543
 
536
def getOurTp(amazonDetails,val,spm):
-
 
537
    ourTp = amazonDetails.promoPrice- amazonDetails.promoPrice*(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost)*(1+(spm.serviceTax/100))*(1+(spm.serviceTax/100));
-
 
538
    return round(ourTp,2)
-
 
539
 
-
 
540
def getLowestPossibleTp(amazonDetails,val,spm):
-
 
541
    vat = (amazonDetails.promoPrice/(1+(val.vatRate/100))-(val.nlc/(1+(val.vatRate/100))))*(val.vatRate/100)
-
 
542
    inHouseCost = 15+vat+(spm.returnProvision/100)*amazonDetails.promoPrice
-
 
543
    lowest_possible_tp = val.nlc+inHouseCost
-
 
544
    return round(lowest_possible_tp,2)
-
 
545
 
544
 
546
def getLowestPossibleSp(amazonDetails,val,spm):
545
def getLowestPossibleSp(amazonDetails,val,spm):
547
    lowestPossibleSp = (val.nlc+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15)*(1+(val.vatRate)/100))/(1-(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))*(1+(val.vatRate)/100)-(spm.returnProvision/100)*(1+(val.vatRate)/100));
546
    lowestPossibleSp = (val.nlc+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15)*(1+(val.vatRate)/100))/(1-(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))*(1+(val.vatRate)/100)-(spm.returnProvision/100)*(1+(val.vatRate)/100));
-
 
547
    if val.isPromo:
-
 
548
        if amazonLongTermActivePromotions.has_key(val.sku):
-
 
549
            subsidy = (amazonLongTermActivePromotions.has_key(val.sku)).subsidy
-
 
550
        else:
-
 
551
            subsidy = (amazonShortTermActivePromotions.has_key(val.sku)).subsidy
-
 
552
        lowestPossibleSp = lowestPossibleSp - subsidy
548
    return round(lowestPossibleSp,2)
553
    return round(lowestPossibleSp,2)
549
 
554
 
550
def getTargetTp(targetSp,spm,val):
555
def getTargetTp(targetSp,spm,val):
551
    targetTp = targetSp- targetSp*(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost)*(1+(spm.serviceTax/100))
556
    targetTp = targetSp- targetSp*(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost)*(1+(spm.serviceTax/100))
552
    return round(targetTp,2)
557
    return round(targetTp,2)
Line 574... Line 579...
574
        amazonScrapingHistory = AmazonScrapingHistory()
579
        amazonScrapingHistory = AmazonScrapingHistory()
575
        amazonScrapingHistory.item_id = val.sku[3:]
580
        amazonScrapingHistory.item_id = val.sku[3:]
576
        amazonScrapingHistory.warehouseLocation = val.state_id
581
        amazonScrapingHistory.warehouseLocation = val.state_id
577
        amazonScrapingHistory.parentCategoryId = val.parent_category
582
        amazonScrapingHistory.parentCategoryId = val.parent_category
578
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
583
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
579
        amazonScrapingHistory.ourTp = amPricing.ourTp
584
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
580
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
581
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
585
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
582
        amazonScrapingHistory.ourRank = amDetails.ourRank
586
        amazonScrapingHistory.ourRank = amDetails.ourRank
583
        amazonScrapingHistory.ourInventory = val.ourInventory
587
        amazonScrapingHistory.ourInventory = val.ourInventory
584
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
585
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
588
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
586
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
587
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
589
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
588
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
589
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
590
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
590
        amazonScrapingHistory.wanlc = val.nlc
591
        amazonScrapingHistory.wanlc = val.nlc
591
        amazonScrapingHistory.commission = spm.commission
592
        amazonScrapingHistory.commission = spm.commission
592
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
593
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
593
        amazonScrapingHistory.returnProvision = spm.returnProvision
594
        amazonScrapingHistory.returnProvision = spm.returnProvision
Line 597... Line 598...
597
        amazonScrapingHistory.totalSeller = amDetails.totalSeller
598
        amazonScrapingHistory.totalSeller = amDetails.totalSeller
598
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
599
        amazonScrapingHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
599
        amazonScrapingHistory.timestamp = timestamp
600
        amazonScrapingHistory.timestamp = timestamp
600
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
601
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
601
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
602
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
603
        amazonScrapingHistory.isPromotion = val.isPromo
602
    session.commit()
604
    session.commit()
603
        
605
        
604
 
606
 
605
def commitCheapest(cheapest,timestamp,runType):
607
def commitCheapest(cheapest,timestamp,runType):
606
    for cheapestItem in cheapest:
608
    for cheapestItem in cheapest:
Line 611... Line 613...
611
        amazonScrapingHistory = AmazonScrapingHistory()
613
        amazonScrapingHistory = AmazonScrapingHistory()
612
        amazonScrapingHistory.item_id = val.sku[3:]
614
        amazonScrapingHistory.item_id = val.sku[3:]
613
        amazonScrapingHistory.warehouseLocation = val.state_id
615
        amazonScrapingHistory.warehouseLocation = val.state_id
614
        amazonScrapingHistory.parentCategoryId = val.parent_category
616
        amazonScrapingHistory.parentCategoryId = val.parent_category
615
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
617
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
616
        amazonScrapingHistory.ourTp = amPricing.ourTp
618
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
617
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
618
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
619
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
619
        amazonScrapingHistory.ourRank = amDetails.ourRank
620
        amazonScrapingHistory.ourRank = amDetails.ourRank
620
        amazonScrapingHistory.ourInventory = val.ourInventory
621
        amazonScrapingHistory.ourInventory = val.ourInventory
621
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
622
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
622
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
623
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
623
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
624
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
624
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
625
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
625
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
626
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
627
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
626
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
628
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
627
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
629
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
628
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
630
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
629
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
631
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
632
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
630
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
633
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
631
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
634
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
632
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
635
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
633
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
636
        amazonScrapingHistory.wanlc = val.nlc
634
        amazonScrapingHistory.wanlc = val.nlc
Line 649... Line 647...
649
        amazonScrapingHistory.proposedSp = proposed_sp
647
        amazonScrapingHistory.proposedSp = proposed_sp
650
        amazonScrapingHistory.proposedTp = proposed_tp
648
        amazonScrapingHistory.proposedTp = proposed_tp
651
        amazonScrapingHistory.marginIncreasedPotential = proposed_tp - amPricing.ourTp
649
        amazonScrapingHistory.marginIncreasedPotential = proposed_tp - amPricing.ourTp
652
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
650
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
653
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
651
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
652
        amazonScrapingHistory.isPromotion = val.isPromo
654
    session.commit()
653
    session.commit()
655
 
654
 
656
 
655
 
657
 
656
 
658
def commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,runType):
657
def commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,runType):
Line 664... Line 663...
664
        amazonScrapingHistory = AmazonScrapingHistory()
663
        amazonScrapingHistory = AmazonScrapingHistory()
665
        amazonScrapingHistory.item_id = val.sku[3:]
664
        amazonScrapingHistory.item_id = val.sku[3:]
666
        amazonScrapingHistory.warehouseLocation = val.state_id
665
        amazonScrapingHistory.warehouseLocation = val.state_id
667
        amazonScrapingHistory.parentCategoryId = val.parent_category
666
        amazonScrapingHistory.parentCategoryId = val.parent_category
668
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
667
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
669
        amazonScrapingHistory.ourTp = amPricing.ourTp
668
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
670
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
671
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
669
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
672
        amazonScrapingHistory.ourRank = amDetails.ourRank
670
        amazonScrapingHistory.ourRank = amDetails.ourRank
673
        amazonScrapingHistory.ourInventory = val.ourInventory
671
        amazonScrapingHistory.ourInventory = val.ourInventory
674
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
675
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
672
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
676
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
673
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
677
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
674
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
678
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
675
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
679
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
680
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
676
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
681
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
677
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
682
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
678
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
683
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
679
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
684
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
685
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
680
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
686
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
681
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
687
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
682
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
688
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
683
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
689
        amazonScrapingHistory.wanlc = val.nlc
684
        amazonScrapingHistory.wanlc = val.nlc
Line 701... Line 696...
701
        proposed_tp = getTargetTp(proposed_sp,spm,val)
696
        proposed_tp = getTargetTp(proposed_sp,spm,val)
702
        amazonScrapingHistory.proposedSp = proposed_sp
697
        amazonScrapingHistory.proposedSp = proposed_sp
703
        amazonScrapingHistory.proposedTp = proposed_tp
698
        amazonScrapingHistory.proposedTp = proposed_tp
704
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
699
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
705
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
700
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
701
        amazonScrapingHistory.isPromotion = val.isPromo
706
    session.commit()
702
    session.commit()
707
 
703
 
708
def commitCanCompete(canCompete,timestamp,runType):
704
def commitCanCompete(canCompete,timestamp,runType):
709
    for canCompeteItem in canCompete:
705
    for canCompeteItem in canCompete:
710
        val = canCompeteItem[0]
706
        val = canCompeteItem[0]
Line 714... Line 710...
714
        amazonScrapingHistory = AmazonScrapingHistory()
710
        amazonScrapingHistory = AmazonScrapingHistory()
715
        amazonScrapingHistory.item_id = val.sku[3:]
711
        amazonScrapingHistory.item_id = val.sku[3:]
716
        amazonScrapingHistory.warehouseLocation = val.state_id
712
        amazonScrapingHistory.warehouseLocation = val.state_id
717
        amazonScrapingHistory.parentCategoryId = val.parent_category
713
        amazonScrapingHistory.parentCategoryId = val.parent_category
718
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
714
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
719
        amazonScrapingHistory.ourTp = amPricing.ourTp
715
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
720
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
721
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
716
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
722
        amazonScrapingHistory.ourRank = amDetails.ourRank
717
        amazonScrapingHistory.ourRank = amDetails.ourRank
723
        amazonScrapingHistory.ourInventory = val.ourInventory
718
        amazonScrapingHistory.ourInventory = val.ourInventory
724
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
725
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
719
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
726
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
720
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
727
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
721
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
728
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
722
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
729
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
730
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
723
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
731
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
724
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
732
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
725
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
733
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
726
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
734
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
735
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
727
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
736
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
728
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
737
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
729
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
738
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
730
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
739
        amazonScrapingHistory.wanlc = val.nlc
731
        amazonScrapingHistory.wanlc = val.nlc
Line 751... Line 743...
751
        proposed_tp = getTargetTp(proposed_sp,spm,val)
743
        proposed_tp = getTargetTp(proposed_sp,spm,val)
752
        amazonScrapingHistory.proposedSp = proposed_sp
744
        amazonScrapingHistory.proposedSp = proposed_sp
753
        amazonScrapingHistory.proposedTp = proposed_tp
745
        amazonScrapingHistory.proposedTp = proposed_tp
754
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
746
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
755
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
747
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
748
        amazonScrapingHistory.isPromotion = val.isPromo
756
    session.commit()
749
    session.commit()
757
 
750
 
758
def commitAlmostCompete(almostCompete,timestamp,runType):
751
def commitAlmostCompete(almostCompete,timestamp,runType):
759
    for almostCompeteItem in almostCompete:
752
    for almostCompeteItem in almostCompete:
760
        val = almostCompeteItem[0]
753
        val = almostCompeteItem[0]
Line 764... Line 757...
764
        amazonScrapingHistory = AmazonScrapingHistory()
757
        amazonScrapingHistory = AmazonScrapingHistory()
765
        amazonScrapingHistory.item_id = val.sku[3:]
758
        amazonScrapingHistory.item_id = val.sku[3:]
766
        amazonScrapingHistory.warehouseLocation = val.state_id
759
        amazonScrapingHistory.warehouseLocation = val.state_id
767
        amazonScrapingHistory.parentCategoryId = val.parent_category
760
        amazonScrapingHistory.parentCategoryId = val.parent_category
768
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
761
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
769
        amazonScrapingHistory.ourTp = amPricing.ourTp
762
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
770
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
771
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
763
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
772
        amazonScrapingHistory.ourRank = amDetails.ourRank
764
        amazonScrapingHistory.ourRank = amDetails.ourRank
773
        amazonScrapingHistory.ourInventory = val.ourInventory
765
        amazonScrapingHistory.ourInventory = val.ourInventory
774
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
775
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
766
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
776
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
767
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
777
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
768
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
778
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
769
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
779
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
780
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
770
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
781
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
771
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
782
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
772
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
783
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
773
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
784
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
785
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
774
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
786
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
775
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
787
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
776
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
788
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
777
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
789
        amazonScrapingHistory.wanlc = val.nlc
778
        amazonScrapingHistory.wanlc = val.nlc
Line 803... Line 792...
803
        amazonScrapingHistory.proposedSp = proposed_sp
792
        amazonScrapingHistory.proposedSp = proposed_sp
804
        amazonScrapingHistory.proposedTp = proposed_tp
793
        amazonScrapingHistory.proposedTp = proposed_tp
805
        amazonScrapingHistory.targetNlc = target_nlc
794
        amazonScrapingHistory.targetNlc = target_nlc
806
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
795
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
807
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
796
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
797
        amazonScrapingHistory.isPromotion = val.isPromo
808
    session.commit()
798
    session.commit()
809
 
799
 
810
 
800
 
811
def commitCantCompete(cantCompete, timestamp,runType):
801
def commitCantCompete(cantCompete, timestamp,runType):
812
    for cantCompeteItem in cantCompete:
802
    for cantCompeteItem in cantCompete:
Line 817... Line 807...
817
        amazonScrapingHistory = AmazonScrapingHistory()
807
        amazonScrapingHistory = AmazonScrapingHistory()
818
        amazonScrapingHistory.item_id = val.sku[3:]
808
        amazonScrapingHistory.item_id = val.sku[3:]
819
        amazonScrapingHistory.warehouseLocation = val.state_id
809
        amazonScrapingHistory.warehouseLocation = val.state_id
820
        amazonScrapingHistory.parentCategoryId = val.parent_category
810
        amazonScrapingHistory.parentCategoryId = val.parent_category
821
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
811
        amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
822
        amazonScrapingHistory.ourTp = amPricing.ourTp
812
        amazonScrapingHistory.promoPrice = amDetails.promoPrice
823
        amazonScrapingHistory.lowestPossibleTp = amPricing.lowestPossibleTp
-
 
824
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
813
        amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
825
        amazonScrapingHistory.ourRank = amDetails.ourRank
814
        amazonScrapingHistory.ourRank = amDetails.ourRank
826
        amazonScrapingHistory.ourInventory = val.ourInventory
815
        amazonScrapingHistory.ourInventory = val.ourInventory
827
        amazonScrapingHistory.lowestSellerName = amDetails.lowestSellerName
-
 
828
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
816
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
829
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
817
        amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
830
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
818
        amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
831
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
819
        amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
832
        amazonScrapingHistory.secondLowestSellerName = amDetails.secondLowestSellerName
-
 
833
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
820
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
834
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
821
        amazonScrapingHistory.secondSellerShippingTime = amDetails.secondSellerShippingTime
835
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
822
        amazonScrapingHistory.secondSellerRating = amDetails.secondSellerRating
836
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
823
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
837
        amazonScrapingHistory.thirdLowestSellerName = amDetails.thirdLowestSellerName
-
 
838
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
824
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
839
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
825
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
840
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
826
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
841
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
827
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
842
        amazonScrapingHistory.wanlc = val.nlc
828
        amazonScrapingHistory.wanlc = val.nlc
Line 856... Line 842...
856
        amazonScrapingHistory.proposedSp = proposed_sp
842
        amazonScrapingHistory.proposedSp = proposed_sp
857
        amazonScrapingHistory.proposedTp = proposed_tp
843
        amazonScrapingHistory.proposedTp = proposed_tp
858
        amazonScrapingHistory.targetNlc = target_nlc
844
        amazonScrapingHistory.targetNlc = target_nlc
859
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
845
        amazonScrapingHistory.multipleListings = amDetails.multipleListings
860
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
846
        amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
-
 
847
        amazonScrapingHistory.isPromotion = val.isPromo
861
    session.commit()
848
    session.commit()
862
 
849
 
863
def markAutoFavourites(time):
850
def markAutoFavourites(time):
864
    nowAutoFav = []
851
    nowAutoFav = []
865
    previouslyAutoFav = []
852
    previouslyAutoFav = []
Line 925... Line 912...
925
    sheet.write(0, 4, "Brand", heading_xf)
912
    sheet.write(0, 4, "Brand", heading_xf)
926
    sheet.write(0, 5, "Product Name", heading_xf)
913
    sheet.write(0, 5, "Product Name", heading_xf)
927
    sheet.write(0, 6, "Weight", heading_xf)
914
    sheet.write(0, 6, "Weight", heading_xf)
928
    sheet.write(0, 7, "Courier Cost", heading_xf)
915
    sheet.write(0, 7, "Courier Cost", heading_xf)
929
    sheet.write(0, 8, "Our SP", heading_xf)
916
    sheet.write(0, 8, "Our SP", heading_xf)
930
    sheet.write(0, 9, "Our Tp", heading_xf)
917
    sheet.write(0, 9, "Promo Price", heading_xf)
931
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
918
    sheet.write(0, 10, "Is Promotion", heading_xf)
932
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
919
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
933
    sheet.write(0, 12, "Rank", heading_xf)
920
    sheet.write(0, 12, "Rank", heading_xf)
934
    sheet.write(0, 13, "Our Inventory", heading_xf)
921
    sheet.write(0, 13, "Our Inventory", heading_xf)
935
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
922
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
936
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
923
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
937
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
924
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
938
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
925
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
939
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
926
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
927
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
940
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
928
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
929
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
930
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
941
    sheet.write(0, 20, "WANLC", heading_xf)
931
    sheet.write(0, 23, "WANLC", heading_xf)
942
    sheet.write(0, 21, "Commission", heading_xf)
932
    sheet.write(0, 24, "Commission", heading_xf)
943
    sheet.write(0, 22, "Competitor Commission", heading_xf)
933
    sheet.write(0, 25, "Competitor Commission", heading_xf)
944
    sheet.write(0, 23, "Return Provision", heading_xf)
934
    sheet.write(0, 26, "Return Provision", heading_xf)
945
    sheet.write(0, 24, "Margin", heading_xf)
935
    sheet.write(0, 27, "Margin", heading_xf)
946
    sheet.write(0, 25, "Risky", heading_xf)
936
    sheet.write(0, 28, "Risky", heading_xf)
947
    sheet.write(0, 26, "Proposed Sp", heading_xf)
937
    sheet.write(0, 29, "Proposed Sp", heading_xf)
948
    sheet.write(0, 27, "Proposed Tp", heading_xf)
938
    sheet.write(0, 30, "Proposed Tp", heading_xf)
949
    sheet.write(0, 28, "Target Nlc", heading_xf)
939
    sheet.write(0, 31, "Target Nlc", heading_xf)
950
    sheet.write(0, 29, "Avg Sale", heading_xf)
940
    sheet.write(0, 32, "Avg Sale", heading_xf)
951
    sheet.write(0, 30, "Sales History", heading_xf)
941
    sheet.write(0, 33, "Sales History", heading_xf)
952
    
942
    
953
    sheet_iterator = 1
943
    sheet_iterator = 1
954
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).all()
944
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).all()
955
    for cantCompeteItem in cantCompeteItems:
945
    for cantCompeteItem in cantCompeteItems:
956
        amScraping =  cantCompeteItem[0]
946
        amScraping =  cantCompeteItem[0]
Line 968... Line 958...
968
        sheet.write(sheet_iterator, 4, item.brand)
958
        sheet.write(sheet_iterator, 4, item.brand)
969
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
959
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
970
        sheet.write(sheet_iterator, 6, item.weight)
960
        sheet.write(sheet_iterator, 6, item.weight)
971
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
961
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
972
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
962
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
973
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
963
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
964
        if amScraping.isPromotion:
-
 
965
            sheet.write(sheet_iterator, 10, "Yes")
-
 
966
        else:
974
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
967
            sheet.write(sheet_iterator, 10, "Yes")
975
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
968
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
976
        if amScraping.ourRank > 3:
969
        if amScraping.ourRank > 3:
977
            sheet.write(sheet_iterator, 12, 'Greater than 3')
970
            sheet.write(sheet_iterator, 12, 'Greater than 3')
978
        else:
971
        else:
979
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
972
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
980
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
973
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
981
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
974
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
982
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
975
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
983
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
976
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
984
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
977
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
985
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
978
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
979
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
986
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
980
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
981
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
982
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
987
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
983
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
988
        sheet.write(sheet_iterator, 21, amScraping.commission)
984
        sheet.write(sheet_iterator, 24, amScraping.commission)
989
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
985
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
990
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
986
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
991
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
987
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
992
        sheet.write(sheet_iterator, 25, item.risky)
988
        sheet.write(sheet_iterator, 28, item.risky)
993
        sheet.write(sheet_iterator, 26, amScraping.proposedSp)
989
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
994
        sheet.write(sheet_iterator, 27, amScraping.proposedTp)
990
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
995
        sheet.write(sheet_iterator, 28, amScraping.targetNlc)
991
        sheet.write(sheet_iterator, 31, amScraping.targetNlc)
996
        sheet.write(sheet_iterator, 29, amScraping.avgSale)
992
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
997
        sheet.write(sheet_iterator, 30, getOosString(saleMap.get(sku)))
993
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
998
        sheet_iterator+=1
994
        sheet_iterator+=1
999
    
995
    
1000
    sheet = wbk.add_sheet('Competitive')
996
    sheet = wbk.add_sheet('Competitive')
1001
    xstr = lambda s: s or ""
997
    xstr = lambda s: s or ""
1002
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
998
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1012... Line 1008...
1012
    sheet.write(0, 4, "Brand", heading_xf)
1008
    sheet.write(0, 4, "Brand", heading_xf)
1013
    sheet.write(0, 5, "Product Name", heading_xf)
1009
    sheet.write(0, 5, "Product Name", heading_xf)
1014
    sheet.write(0, 6, "Weight", heading_xf)
1010
    sheet.write(0, 6, "Weight", heading_xf)
1015
    sheet.write(0, 7, "Courier Cost", heading_xf)
1011
    sheet.write(0, 7, "Courier Cost", heading_xf)
1016
    sheet.write(0, 8, "Our SP", heading_xf)
1012
    sheet.write(0, 8, "Our SP", heading_xf)
1017
    sheet.write(0, 9, "Our Tp", heading_xf)
1013
    sheet.write(0, 9, "Promo Price", heading_xf)
1018
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
1014
    sheet.write(0, 10, "Is Promotion", heading_xf)
1019
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
1015
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
1020
    sheet.write(0, 12, "Rank", heading_xf)
1016
    sheet.write(0, 12, "Rank", heading_xf)
1021
    sheet.write(0, 13, "Our Inventory", heading_xf)
1017
    sheet.write(0, 13, "Our Inventory", heading_xf)
1022
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
1018
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
1023
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
1019
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
1024
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
1020
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
1025
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1021
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1026
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
1022
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
1023
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1027
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
1024
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
1025
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
1026
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1028
    sheet.write(0, 20, "WANLC", heading_xf)
1027
    sheet.write(0, 23, "WANLC", heading_xf)
1029
    sheet.write(0, 21, "Commission", heading_xf)
1028
    sheet.write(0, 24, "Commission", heading_xf)
1030
    sheet.write(0, 22, "Competitor Commission", heading_xf)
1029
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1031
    sheet.write(0, 23, "Return Provision", heading_xf)
1030
    sheet.write(0, 26, "Return Provision", heading_xf)
1032
    sheet.write(0, 24, "Margin", heading_xf)
1031
    sheet.write(0, 27, "Margin", heading_xf)
1033
    sheet.write(0, 25, "Risky", heading_xf)
1032
    sheet.write(0, 28, "Risky", heading_xf)
1034
    sheet.write(0, 26, "Proposed Sp", heading_xf)
1033
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1035
    sheet.write(0, 27, "Proposed Tp", heading_xf)
1034
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1036
    sheet.write(0, 28, "Avg Sale", heading_xf)
1035
    sheet.write(0, 31, "Avg Sale", heading_xf)
1037
    sheet.write(0, 29, "Sales History", heading_xf)
1036
    sheet.write(0, 32, "Sales History", heading_xf)
1038
    
1037
    
1039
    sheet_iterator = 1
1038
    sheet_iterator = 1
1040
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).all()
1039
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).all()
1041
    for competitiveItem in competitiveItems:
1040
    for competitiveItem in competitiveItems:
1042
        amScraping =  competitiveItem[0]
1041
        amScraping =  competitiveItem[0]
Line 1054... Line 1053...
1054
        sheet.write(sheet_iterator, 4, item.brand)
1053
        sheet.write(sheet_iterator, 4, item.brand)
1055
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1054
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1056
        sheet.write(sheet_iterator, 6, item.weight)
1055
        sheet.write(sheet_iterator, 6, item.weight)
1057
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1056
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1058
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1057
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1059
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
1058
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
1059
        if amScraping.isPromotion:
-
 
1060
            sheet.write(sheet_iterator, 10, "Yes")
-
 
1061
        else:
1060
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
1062
            sheet.write(sheet_iterator, 10, "Yes")
1061
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
1063
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
1062
        if amScraping.ourRank > 3:
1064
        if amScraping.ourRank > 3:
1063
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1065
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1064
        else:
1066
        else:
1065
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1067
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1066
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1068
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1067
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
1069
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
1068
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
1070
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
1069
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
1071
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
1070
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1072
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1071
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
1073
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
1074
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1072
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
1075
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
1076
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
1077
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1073
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
1078
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1074
        sheet.write(sheet_iterator, 21, amScraping.commission)
1079
        sheet.write(sheet_iterator, 24, amScraping.commission)
1075
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
1080
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1076
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
1081
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1077
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1082
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1078
        sheet.write(sheet_iterator, 25, item.risky)
1083
        sheet.write(sheet_iterator, 28, item.risky)
1079
        sheet.write(sheet_iterator, 26, amScraping.proposedSp)
1084
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1080
        sheet.write(sheet_iterator, 27, amScraping.proposedTp)
1085
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1081
        sheet.write(sheet_iterator, 28, amScraping.avgSale)
1086
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1082
        sheet.write(sheet_iterator, 29, getOosString(saleMap.get(sku)))
1087
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1083
        sheet_iterator+=1
1088
        sheet_iterator+=1
1084
    
1089
    
1085
    sheet = wbk.add_sheet('Almost Competitive')
1090
    sheet = wbk.add_sheet('Almost Competitive')
1086
    xstr = lambda s: s or ""
1091
    xstr = lambda s: s or ""
1087
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1092
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1097... Line 1102...
1097
    sheet.write(0, 4, "Brand", heading_xf)
1102
    sheet.write(0, 4, "Brand", heading_xf)
1098
    sheet.write(0, 5, "Product Name", heading_xf)
1103
    sheet.write(0, 5, "Product Name", heading_xf)
1099
    sheet.write(0, 6, "Weight", heading_xf)
1104
    sheet.write(0, 6, "Weight", heading_xf)
1100
    sheet.write(0, 7, "Courier Cost", heading_xf)
1105
    sheet.write(0, 7, "Courier Cost", heading_xf)
1101
    sheet.write(0, 8, "Our SP", heading_xf)
1106
    sheet.write(0, 8, "Our SP", heading_xf)
1102
    sheet.write(0, 9, "Our Tp", heading_xf)
1107
    sheet.write(0, 9, "Promo Price", heading_xf)
1103
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
1108
    sheet.write(0, 10, "Is Promotion", heading_xf)
1104
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
1109
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
1105
    sheet.write(0, 12, "Rank", heading_xf)
1110
    sheet.write(0, 12, "Rank", heading_xf)
1106
    sheet.write(0, 13, "Our Inventory", heading_xf)
1111
    sheet.write(0, 13, "Our Inventory", heading_xf)
1107
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
1112
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
1108
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
1113
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
1109
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
1114
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
1110
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1115
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1111
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
1116
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
1117
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1112
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
1118
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
1119
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
1120
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1113
    sheet.write(0, 20, "WANLC", heading_xf)
1121
    sheet.write(0, 23, "WANLC", heading_xf)
1114
    sheet.write(0, 21, "Commission", heading_xf)
1122
    sheet.write(0, 24, "Commission", heading_xf)
1115
    sheet.write(0, 22, "Competitor Commission", heading_xf)
1123
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1116
    sheet.write(0, 23, "Return Provision", heading_xf)
1124
    sheet.write(0, 26, "Return Provision", heading_xf)
1117
    sheet.write(0, 24, "Margin", heading_xf)
1125
    sheet.write(0, 27, "Margin", heading_xf)
1118
    sheet.write(0, 25, "Risky", heading_xf)
1126
    sheet.write(0, 28, "Risky", heading_xf)
1119
    sheet.write(0, 26, "Proposed Sp", heading_xf)
1127
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1120
    sheet.write(0, 27, "Proposed Tp", heading_xf)
1128
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1121
    sheet.write(0, 28, "Avg Sale", heading_xf)
1129
    sheet.write(0, 31, "Avg Sale", heading_xf)
1122
    sheet.write(0, 29, "Sales History", heading_xf)
1130
    sheet.write(0, 32, "Sales History", heading_xf)
1123
    
1131
    
1124
    sheet_iterator = 1
1132
    sheet_iterator = 1
1125
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).all()
1133
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).all()
1126
    for almostCompetitiveItem in almostCompetitiveItems:
1134
    for almostCompetitiveItem in almostCompetitiveItems:
1127
        amScraping =  almostCompetitiveItem[0]
1135
        amScraping =  almostCompetitiveItem[0]
Line 1131... Line 1139...
1131
            sku = 'FBA'+str(amScraping.item_id)
1139
            sku = 'FBA'+str(amScraping.item_id)
1132
            loc = 'MUMBAI'
1140
            loc = 'MUMBAI'
1133
        else:
1141
        else:
1134
            sku = 'FBB'+str(amScraping.item_id)
1142
            sku = 'FBB'+str(amScraping.item_id)
1135
            loc = 'BANGLORE'
1143
            loc = 'BANGLORE'
-
 
1144
        amScraping =  competitiveItem[0]
-
 
1145
        item = competitiveItem[1]
-
 
1146
        sheet.write(sheet_iterator, 0, amScraping.item_id)
-
 
1147
        if amScraping.warehouseLocation == 1:
-
 
1148
            sku = 'FBA'+str(amScraping.item_id)
-
 
1149
            loc = 'MUMBAI'
-
 
1150
        else:
-
 
1151
            sku = 'FBB'+str(amScraping.item_id)
-
 
1152
            loc = 'BANGLORE'
1136
        sheet.write(sheet_iterator, 1, sku)
1153
        sheet.write(sheet_iterator, 1, sku)
1137
        sheet.write(sheet_iterator, 2, (amazonAsinPrice.get(sku).asin))
1154
        sheet.write(sheet_iterator, 2, (amazonAsinPrice.get(sku).asin))
1138
        sheet.write(sheet_iterator, 3, loc)
1155
        sheet.write(sheet_iterator, 3, loc)
1139
        sheet.write(sheet_iterator, 4, item.brand)
1156
        sheet.write(sheet_iterator, 4, item.brand)
1140
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1157
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1141
        sheet.write(sheet_iterator, 6, item.weight)
1158
        sheet.write(sheet_iterator, 6, item.weight)
1142
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1159
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1143
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1160
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1144
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
1161
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
1162
        if amScraping.isPromotion:
-
 
1163
            sheet.write(sheet_iterator, 10, "Yes")
-
 
1164
        else:
1145
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
1165
            sheet.write(sheet_iterator, 10, "Yes")
1146
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
1166
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
1147
        if amScraping.ourRank > 3:
1167
        if amScraping.ourRank > 3:
1148
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1168
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1149
        else:
1169
        else:
1150
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1170
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1151
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1171
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1152
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
1172
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
1153
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
1173
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
1154
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
1174
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
1155
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1175
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1156
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
1176
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
1177
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1157
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
1178
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
1179
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
1180
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1158
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
1181
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1159
        sheet.write(sheet_iterator, 21, amScraping.commission)
1182
        sheet.write(sheet_iterator, 24, amScraping.commission)
1160
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
1183
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1161
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
1184
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1162
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1185
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1163
        sheet.write(sheet_iterator, 25, item.risky)
1186
        sheet.write(sheet_iterator, 28, item.risky)
1164
        sheet.write(sheet_iterator, 26, amScraping.proposedSp)
1187
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1165
        sheet.write(sheet_iterator, 27, amScraping.proposedTp)
1188
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1166
        sheet.write(sheet_iterator, 28, amScraping.avgSale)
1189
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1167
        sheet.write(sheet_iterator, 29, getOosString(saleMap.get(sku)))
1190
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1168
        sheet_iterator+=1
1191
        sheet_iterator+=1
1169
    
1192
    
1170
    sheet = wbk.add_sheet('Among Cheapest')
1193
    sheet = wbk.add_sheet('Among Cheapest')
1171
    xstr = lambda s: s or ""
1194
    xstr = lambda s: s or ""
1172
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1195
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1182... Line 1205...
1182
    sheet.write(0, 4, "Brand", heading_xf)
1205
    sheet.write(0, 4, "Brand", heading_xf)
1183
    sheet.write(0, 5, "Product Name", heading_xf)
1206
    sheet.write(0, 5, "Product Name", heading_xf)
1184
    sheet.write(0, 6, "Weight", heading_xf)
1207
    sheet.write(0, 6, "Weight", heading_xf)
1185
    sheet.write(0, 7, "Courier Cost", heading_xf)
1208
    sheet.write(0, 7, "Courier Cost", heading_xf)
1186
    sheet.write(0, 8, "Our SP", heading_xf)
1209
    sheet.write(0, 8, "Our SP", heading_xf)
1187
    sheet.write(0, 9, "Our Tp", heading_xf)
1210
    sheet.write(0, 9, "Promo Price", heading_xf)
1188
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
1211
    sheet.write(0, 10, "Is Promotion", heading_xf)
1189
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
1212
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
1190
    sheet.write(0, 12, "Rank", heading_xf)
1213
    sheet.write(0, 12, "Rank", heading_xf)
1191
    sheet.write(0, 13, "Our Inventory", heading_xf)
1214
    sheet.write(0, 13, "Our Inventory", heading_xf)
1192
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
1215
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
1193
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
1216
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
1194
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
1217
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
1195
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1218
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1196
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
1219
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
1220
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1197
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
1221
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
1222
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
1223
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1198
    sheet.write(0, 20, "WANLC", heading_xf)
1224
    sheet.write(0, 23, "WANLC", heading_xf)
1199
    sheet.write(0, 21, "Commission", heading_xf)
1225
    sheet.write(0, 24, "Commission", heading_xf)
1200
    sheet.write(0, 22, "Competitor Commission", heading_xf)
1226
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1201
    sheet.write(0, 23, "Return Provision", heading_xf)
1227
    sheet.write(0, 26, "Return Provision", heading_xf)
1202
    sheet.write(0, 24, "Margin", heading_xf)
1228
    sheet.write(0, 27, "Margin", heading_xf)
1203
    sheet.write(0, 25, "Risky", heading_xf)
1229
    sheet.write(0, 28, "Risky", heading_xf)
1204
    sheet.write(0, 26, "Proposed Sp", heading_xf)
1230
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1205
    sheet.write(0, 27, "Proposed Tp", heading_xf)
1231
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1206
    sheet.write(0, 28, "Avg Sale", heading_xf)
1232
    sheet.write(0, 31, "Avg Sale", heading_xf)
1207
    sheet.write(0, 29, "Sales History", heading_xf)
1233
    sheet.write(0, 32, "Sales History", heading_xf)
1208
    
1234
    
1209
    sheet_iterator = 1
1235
    sheet_iterator = 1
1210
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1236
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1211
    for amongCheapestItem in amongCheapestItems:
1237
    for amongCheapestItem in amongCheapestItems:
1212
        amScraping =  amongCheapestItem[0]
1238
        amScraping =  amongCheapestItem[0]
Line 1224... Line 1250...
1224
        sheet.write(sheet_iterator, 4, item.brand)
1250
        sheet.write(sheet_iterator, 4, item.brand)
1225
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1251
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1226
        sheet.write(sheet_iterator, 6, item.weight)
1252
        sheet.write(sheet_iterator, 6, item.weight)
1227
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1253
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1228
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1254
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1229
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
1255
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
1256
        if amScraping.isPromotion:
-
 
1257
            sheet.write(sheet_iterator, 10, "Yes")
-
 
1258
        else:
1230
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
1259
            sheet.write(sheet_iterator, 10, "Yes")
1231
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
1260
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
1232
        if amScraping.ourRank > 3:
1261
        if amScraping.ourRank > 3:
1233
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1262
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1234
        else:
1263
        else:
1235
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1264
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1236
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1265
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1237
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
1266
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
1238
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
1267
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
1239
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
1268
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
1240
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1269
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1241
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
1270
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
1271
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1242
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
1272
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
1273
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
1274
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1243
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
1275
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1244
        sheet.write(sheet_iterator, 21, amScraping.commission)
1276
        sheet.write(sheet_iterator, 24, amScraping.commission)
1245
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
1277
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1246
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
1278
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1247
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1279
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1248
        sheet.write(sheet_iterator, 25, item.risky)
1280
        sheet.write(sheet_iterator, 28, item.risky)
1249
        sheet.write(sheet_iterator, 26, amScraping.proposedSp)
1281
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1250
        sheet.write(sheet_iterator, 27, amScraping.proposedTp)
1282
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1251
        sheet.write(sheet_iterator, 28, amScraping.avgSale)
1283
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1252
        sheet.write(sheet_iterator, 29, getOosString(saleMap.get(sku)))
1284
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1253
        sheet_iterator+=1
1285
        sheet_iterator+=1
1254
    
1286
    
1255
    sheet = wbk.add_sheet('Cheapest')
1287
    sheet = wbk.add_sheet('Cheapest')
1256
    xstr = lambda s: s or ""
1288
    xstr = lambda s: s or ""
1257
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1289
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1267... Line 1299...
1267
    sheet.write(0, 4, "Brand", heading_xf)
1299
    sheet.write(0, 4, "Brand", heading_xf)
1268
    sheet.write(0, 5, "Product Name", heading_xf)
1300
    sheet.write(0, 5, "Product Name", heading_xf)
1269
    sheet.write(0, 6, "Weight", heading_xf)
1301
    sheet.write(0, 6, "Weight", heading_xf)
1270
    sheet.write(0, 7, "Courier Cost", heading_xf)
1302
    sheet.write(0, 7, "Courier Cost", heading_xf)
1271
    sheet.write(0, 8, "Our SP", heading_xf)
1303
    sheet.write(0, 8, "Our SP", heading_xf)
1272
    sheet.write(0, 9, "Our Tp", heading_xf)
1304
    sheet.write(0, 9, "Promo Price", heading_xf)
1273
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
1305
    sheet.write(0, 10, "Is Promotion", heading_xf)
1274
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
1306
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
1275
    sheet.write(0, 12, "Rank", heading_xf)
1307
    sheet.write(0, 12, "Rank", heading_xf)
1276
    sheet.write(0, 13, "Our Inventory", heading_xf)
1308
    sheet.write(0, 13, "Our Inventory", heading_xf)
1277
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
1309
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
1278
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
1310
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
1279
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
1311
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
1280
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1312
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1281
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
1313
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
1314
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1282
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
1315
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
1316
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
1317
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1283
    sheet.write(0, 20, "WANLC", heading_xf)
1318
    sheet.write(0, 23, "WANLC", heading_xf)
1284
    sheet.write(0, 21, "Commission", heading_xf)
1319
    sheet.write(0, 24, "Commission", heading_xf)
1285
    sheet.write(0, 22, "Competitor Commission", heading_xf)
1320
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1286
    sheet.write(0, 23, "Return Provision", heading_xf)
1321
    sheet.write(0, 26, "Return Provision", heading_xf)
1287
    sheet.write(0, 24, "Margin", heading_xf)
1322
    sheet.write(0, 27, "Margin", heading_xf)
1288
    sheet.write(0, 25, "Risky", heading_xf)
1323
    sheet.write(0, 28, "Risky", heading_xf)
1289
    sheet.write(0, 26, "Proposed Sp", heading_xf)
1324
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1290
    sheet.write(0, 27, "Proposed Tp", heading_xf)
1325
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1291
    sheet.write(0, 28, "Margin Increased Potential", heading_xf)
1326
    sheet.write(0, 31, "Margin Increased Potential", heading_xf)
1292
    sheet.write(0, 29, "Avg Sale", heading_xf)
1327
    sheet.write(0, 32, "Avg Sale", heading_xf)
1293
    sheet.write(0, 30, "Sales History", heading_xf)
1328
    sheet.write(0, 33, "Sales History", heading_xf)
1294
    
1329
    
1295
    sheet_iterator = 1
1330
    sheet_iterator = 1
1296
    cheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX).all()
1331
    cheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX).all()
1297
    for cheapestItem in cheapestItems:
1332
    for cheapestItem in cheapestItems:
1298
        amScraping =  cheapestItem[0]
1333
        amScraping =  cheapestItem[0]
Line 1310... Line 1345...
1310
        sheet.write(sheet_iterator, 4, item.brand)
1345
        sheet.write(sheet_iterator, 4, item.brand)
1311
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1346
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1312
        sheet.write(sheet_iterator, 6, item.weight)
1347
        sheet.write(sheet_iterator, 6, item.weight)
1313
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1348
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1314
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1349
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1315
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
1350
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
1351
        if amScraping.isPromotion:
-
 
1352
            sheet.write(sheet_iterator, 10, "Yes")
-
 
1353
        else:
1316
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
1354
            sheet.write(sheet_iterator, 10, "Yes")
1317
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
1355
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
1318
        if amScraping.ourRank > 3:
1356
        if amScraping.ourRank > 3:
1319
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1357
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1320
        else:
1358
        else:
1321
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1359
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1322
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1360
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1323
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
1361
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
1324
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
1362
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
1325
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
1363
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
1326
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1364
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1327
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
1365
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
1366
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1328
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
1367
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
1368
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
1369
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1329
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
1370
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1330
        sheet.write(sheet_iterator, 21, amScraping.commission)
1371
        sheet.write(sheet_iterator, 24, amScraping.commission)
1331
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
1372
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1332
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
1373
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1333
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1374
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1334
        sheet.write(sheet_iterator, 25, item.risky)
1375
        sheet.write(sheet_iterator, 28, item.risky)
1335
        sheet.write(sheet_iterator, 26, amScraping.proposedSp)
1376
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1336
        sheet.write(sheet_iterator, 27, amScraping.proposedTp)
1377
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1337
        sheet.write(sheet_iterator, 28, amScraping.marginIncreasedPotential)
1378
        sheet.write(sheet_iterator, 31, amScraping.targetNlc)
1338
        sheet.write(sheet_iterator, 29, amScraping.avgSale)
1379
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1339
        sheet.write(sheet_iterator, 30, getOosString(saleMap.get(sku)))
1380
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1340
        sheet_iterator+=1
1381
        sheet_iterator+=1
1341
    
1382
    
1342
    sheet = wbk.add_sheet('Negative Margin')
1383
    sheet = wbk.add_sheet('Negative Margin')
1343
    xstr = lambda s: s or ""
1384
    xstr = lambda s: s or ""
1344
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1385
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1354... Line 1395...
1354
    sheet.write(0, 4, "Brand", heading_xf)
1395
    sheet.write(0, 4, "Brand", heading_xf)
1355
    sheet.write(0, 5, "Product Name", heading_xf)
1396
    sheet.write(0, 5, "Product Name", heading_xf)
1356
    sheet.write(0, 6, "Weight", heading_xf)
1397
    sheet.write(0, 6, "Weight", heading_xf)
1357
    sheet.write(0, 7, "Courier Cost", heading_xf)
1398
    sheet.write(0, 7, "Courier Cost", heading_xf)
1358
    sheet.write(0, 8, "Our SP", heading_xf)
1399
    sheet.write(0, 8, "Our SP", heading_xf)
1359
    sheet.write(0, 9, "Our Tp", heading_xf)
1400
    sheet.write(0, 9, "Promo Price", heading_xf)
1360
    sheet.write(0, 10, "Lowest Possible SP", heading_xf)
1401
    sheet.write(0, 10, "Is Promotion", heading_xf)
1361
    sheet.write(0, 11, "Lowest Possible TP", heading_xf)
1402
    sheet.write(0, 11, "Lowest Possible SP", heading_xf)
1362
    sheet.write(0, 12, "Rank", heading_xf)
1403
    sheet.write(0, 12, "Rank", heading_xf)
1363
    sheet.write(0, 13, "Our Inventory", heading_xf)
1404
    sheet.write(0, 13, "Our Inventory", heading_xf)
1364
    sheet.write(0, 14, "Lowest Seller Name", heading_xf)
1405
    sheet.write(0, 14, "Lowest Seller SP", heading_xf)
1365
    sheet.write(0, 15, "Lowest Seller SP", heading_xf)
1406
    sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
1366
    sheet.write(0, 16, "Second Lowest Seller Name", heading_xf)
1407
    sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
1367
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1408
    sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
1368
    sheet.write(0, 18, "Third Lowest Seller Name", heading_xf)
1409
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
-
 
1410
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1369
    sheet.write(0, 19, "Third Lowest Seller SP", heading_xf)
1411
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
-
 
1412
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
-
 
1413
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1370
    sheet.write(0, 20, "WANLC", heading_xf)
1414
    sheet.write(0, 23, "WANLC", heading_xf)
1371
    sheet.write(0, 21, "Commission", heading_xf)
1415
    sheet.write(0, 24, "Commission", heading_xf)
1372
    sheet.write(0, 22, "Competitor Commission", heading_xf)
1416
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1373
    sheet.write(0, 23, "Return Provision", heading_xf)
1417
    sheet.write(0, 26, "Return Provision", heading_xf)
1374
    sheet.write(0, 24, "Margin", heading_xf)
1418
    sheet.write(0, 27, "Margin", heading_xf)
1375
    sheet.write(0, 25, "Avg Sale", heading_xf)
1419
    sheet.write(0, 28, "Avg Sale", heading_xf)
1376
    sheet.write(0, 26, "Sales History", heading_xf)
1420
    sheet.write(0, 29, "Sales History", heading_xf)
1377
    
1421
    
1378
    sheet_iterator = 1
1422
    sheet_iterator = 1
1379
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1423
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1380
    for amongCheapestItem in amongCheapestItems:
1424
    for amongCheapestItem in amongCheapestItems:
1381
        amScraping =  amongCheapestItem[0]
1425
        amScraping =  amongCheapestItem[0]
Line 1393... Line 1437...
1393
        sheet.write(sheet_iterator, 4, item.brand)
1437
        sheet.write(sheet_iterator, 4, item.brand)
1394
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1438
        sheet.write(sheet_iterator, 5, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
1395
        sheet.write(sheet_iterator, 6, item.weight)
1439
        sheet.write(sheet_iterator, 6, item.weight)
1396
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1440
        sheet.write(sheet_iterator, 7, amScraping.courierCost)
1397
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1441
        sheet.write(sheet_iterator, 8, amScraping.ourSellingPrice)
1398
        sheet.write(sheet_iterator, 9, amScraping.ourTp)
1442
        sheet.write(sheet_iterator, 9, amScraping.promoPrice)
-
 
1443
        if amScraping.isPromotion:
-
 
1444
            sheet.write(sheet_iterator, 10, "Yes")
-
 
1445
        else:
1399
        sheet.write(sheet_iterator, 10, amScraping.lowestPossibleSp)
1446
            sheet.write(sheet_iterator, 10, "Yes")
1400
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleTp)
1447
        sheet.write(sheet_iterator, 11, amScraping.lowestPossibleSp)
1401
        if amScraping.ourRank > 3:
1448
        if amScraping.ourRank > 3:
1402
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1449
            sheet.write(sheet_iterator, 12, 'Greater than 3')
1403
        else:
1450
        else:
1404
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1451
            sheet.write(sheet_iterator, 12, amScraping.ourRank)
1405
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1452
        sheet.write(sheet_iterator, 13, amScraping.ourInventory)
1406
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerName)
1453
        sheet.write(sheet_iterator, 14, amScraping.lowestSellerSp)
1407
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerSp)
1454
        sheet.write(sheet_iterator, 15, amScraping.lowestSellerRating)
1408
        sheet.write(sheet_iterator, 16, amScraping.secondLowestSellerName)
1455
        sheet.write(sheet_iterator, 16, amScraping.lowestSellerShippingTime)
1409
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1456
        sheet.write(sheet_iterator, 17, amScraping.secondLowestSellerSp)
1410
        sheet.write(sheet_iterator, 18, amScraping.thirdLowestSellerName)
1457
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
-
 
1458
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1411
        sheet.write(sheet_iterator, 19, amScraping.thirdLowestSellerSp)
1459
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
-
 
1460
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
-
 
1461
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1412
        sheet.write(sheet_iterator, 20, amScraping.wanlc)
1462
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1413
        sheet.write(sheet_iterator, 21, amScraping.commission)
1463
        sheet.write(sheet_iterator, 24, amScraping.commission)
1414
        sheet.write(sheet_iterator, 22, amScraping.competitorCommission)
1464
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1415
        sheet.write(sheet_iterator, 23, amScraping.returnProvision)
1465
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1416
        sheet.write(sheet_iterator, 24, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1466
        sheet.write(sheet_iterator, 27, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1417
        sheet.write(sheet_iterator, 25, amScraping.avgSale)
1467
        sheet.write(sheet_iterator, 28, amScraping.avgSale)
1418
        sheet.write(sheet_iterator, 26, getOosString(saleMap.get(sku)))
1468
        sheet.write(sheet_iterator, 29, getOosString(saleMap.get(sku)))
1419
        sheet_iterator+=1
1469
        sheet_iterator+=1
1420
    
1470
    
1421
    sheet = wbk.add_sheet('Exception List')
1471
    sheet = wbk.add_sheet('Exception List')
1422
    xstr = lambda s: s or ""
1472
    xstr = lambda s: s or ""
1423
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1473
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')