Subversion Repositories SmartDukaan

Rev

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

Rev 12444 Rev 12447
Line 33... Line 33...
33
 
33
 
34
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
34
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
35
 
35
 
36
class __AmazonItemInfo:
36
class __AmazonItemInfo:
37
    
37
    
38
    def __init__(self, asin, nlc, courierCost, sku, product_group, brand, model_name, model_number, color, weight, parent_category, risky, vatRate, runType, parent_category_name, sourcePercentage, ourInventory, state_id):
38
    def __init__(self, asin, nlc, courierCost, sku, product_group, brand, model_name, model_number, color, weight, parent_category, risky, vatRate, runType, parent_category_name, sourcePercentage, ourInventory, state_id, otherCost):
39
        self.asin = asin
39
        self.asin = asin
40
        self.nlc = nlc
40
        self.nlc = nlc
41
        self.courierCost = courierCost
41
        self.courierCost = courierCost
42
        self.sku = sku
42
        self.sku = sku
43
        self.product_group = product_group
43
        self.product_group = product_group
Line 52... Line 52...
52
        self.runType = runType
52
        self.runType = runType
53
        self.parent_category_name = parent_category_name
53
        self.parent_category_name = parent_category_name
54
        self.sourcePercentage = sourcePercentage
54
        self.sourcePercentage = sourcePercentage
55
        self.ourInventory = ourInventory
55
        self.ourInventory = ourInventory
56
        self.state_id = state_id
56
        self.state_id = state_id
-
 
57
        self.otherCost = otherCost
57
 
58
 
58
class __AmazonDetails:
59
class __AmazonDetails:
59
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
60
    def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
60
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
61
                 promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
61
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType):
62
                 thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType):
Line 78... Line 79...
78
        self.secondLowestSellerRating = secondLowestSellerRating
79
        self.secondLowestSellerRating = secondLowestSellerRating
79
        self.thirdLowestSellerShippingTime= thirdLowestSellerShippingTime
80
        self.thirdLowestSellerShippingTime= thirdLowestSellerShippingTime
80
        self.thirdLowestSellerRating = thirdLowestSellerRating
81
        self.thirdLowestSellerRating = thirdLowestSellerRating
81
        self.lowestSellerType = lowestSellerType
82
        self.lowestSellerType = lowestSellerType
82
        self.secondLowestSellerType = secondLowestSellerType
83
        self.secondLowestSellerType = secondLowestSellerType
83
        self.thirdLowestSellerType = thirdLowestSellerType    
84
        self.thirdLowestSellerType = thirdLowestSellerType
84
           
85
           
85
 
86
 
86
class __AmazonPricing:
87
class __AmazonPricing:
87
    
88
    
88
    def __init__(self, ourSp, lowestPossibleSp):
89
    def __init__(self, ourSp, lowestPossibleSp):
Line 178... Line 179...
178
            continue
179
            continue
179
        if autoIncrementItem.proposedSellingPrice >=10000 and autoIncrementItem.ourSellingPrice<10000:
180
        if autoIncrementItem.proposedSellingPrice >=10000 and autoIncrementItem.ourSellingPrice<10000:
180
            markReasonForItem(autoIncrementItem,'Proposed SP is greater than 10,000 and current sp is less than 10,000',Decision.AUTO_INCREMENT_FAILED)
181
            markReasonForItem(autoIncrementItem,'Proposed SP is greater than 10,000 and current sp is less than 10,000',Decision.AUTO_INCREMENT_FAILED)
181
            continue
182
            continue
182
        
183
        
-
 
184
        if autoIncrementItem.isPromotion and math.ceil(autoIncrementItem.promoPrice+max(10,.01*autoIncrementItem.promoPrice)) > (amazonLongTermActivePromotions.get(sku)).promoPrice:
-
 
185
            markReasonForItem(autoIncrementItem,'Proposed SP cant be greater than promo price',Decision.AUTO_INCREMENT_FAILED)
-
 
186
            continue
-
 
187
            
-
 
188
        
183
        if autoIncrementItem.avgSale==0:
189
        if autoIncrementItem.avgSale==0:
184
            markReasonForItem(autoIncrementItem,'Avg sale is 0',Decision.AUTO_INCREMENT_FAILED)
190
            markReasonForItem(autoIncrementItem,'Avg sale is 0',Decision.AUTO_INCREMENT_FAILED)
185
            continue
191
            continue
186
        
192
        
187
        daysOfStock = (float(autoIncrementItem.ourInventory))/autoIncrementItem.avgSale
193
        daysOfStock = (float(autoIncrementItem.ourInventory))/autoIncrementItem.avgSale
Line 371... Line 377...
371
            state_id = 2
377
            state_id = 2
372
        else:
378
        else:
373
            continue
379
            continue
374
        cc = computeCourierCost(it.weight)
380
        cc = computeCourierCost(it.weight)
375
            
381
            
376
        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)
382
        amazonItemInfo = __AmazonItemInfo(None, wanlc,cc, sku, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, None, runType, parent_category.display_name,sourcePercentage,fbaInventoryItem.availability,state_id,d_amazon_listed.otherCost)
377
        itemInfo.append(amazonItemInfo)
383
        itemInfo.append(amazonItemInfo)
378
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
384
    amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
379
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
385
    .group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
380
    for amPromotion in amPromotions:
386
    for amPromotion in amPromotions:
381
        amazonLongTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
387
        amazonLongTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
Line 557... Line 563...
557
        
563
        
558
    return exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete
564
    return exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete
559
 
565
 
560
 
566
 
561
def getLowestPossibleSp(amazonDetails,val,spm):
567
def getLowestPossibleSp(amazonDetails,val,spm):
562
    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));
568
    lowestPossibleSp = (val.nlc+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15+val.otherCost)*(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));
563
    if val.isPromo:
569
    if val.isPromo:
564
        if amazonLongTermActivePromotions.has_key(val.sku):
570
        if amazonLongTermActivePromotions.has_key(val.sku):
565
            subsidy = (amazonLongTermActivePromotions.has_key(val.sku)).subsidy
571
            subsidy = (amazonLongTermActivePromotions.has_key(val.sku)).subsidy
566
        else:
572
        else:
567
            subsidy = (amazonShortTermActivePromotions.has_key(val.sku)).subsidy
573
            subsidy = (amazonShortTermActivePromotions.has_key(val.sku)).subsidy
Line 603... Line 609...
603
        amazonScrapingHistory.ourInventory = val.ourInventory
609
        amazonScrapingHistory.ourInventory = val.ourInventory
604
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
610
        amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
605
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
611
        amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
606
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
612
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
607
        amazonScrapingHistory.wanlc = val.nlc
613
        amazonScrapingHistory.wanlc = val.nlc
-
 
614
        amazonScrapingHistory.otherCost = val.otherCost
608
        amazonScrapingHistory.commission = spm.commission
615
        amazonScrapingHistory.commission = spm.commission
609
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
616
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
610
        amazonScrapingHistory.returnProvision = spm.returnProvision
617
        amazonScrapingHistory.returnProvision = spm.returnProvision
611
        amazonScrapingHistory.courierCost = val.courierCost
618
        amazonScrapingHistory.courierCost = val.courierCost
612
        amazonScrapingHistory.risky = val.risky
619
        amazonScrapingHistory.risky = val.risky
Line 645... Line 652...
645
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
652
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
646
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
653
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
647
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
654
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
648
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
655
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
649
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
656
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
-
 
657
        amazonScrapingHistory.otherCost = val.otherCost
650
        amazonScrapingHistory.wanlc = val.nlc
658
        amazonScrapingHistory.wanlc = val.nlc
651
        amazonScrapingHistory.commission = spm.commission
659
        amazonScrapingHistory.commission = spm.commission
652
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
660
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
653
        amazonScrapingHistory.returnProvision = spm.returnProvision
661
        amazonScrapingHistory.returnProvision = spm.returnProvision
654
        amazonScrapingHistory.courierCost = val.courierCost
662
        amazonScrapingHistory.courierCost = val.courierCost
Line 700... Line 708...
700
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
708
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
701
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
709
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
702
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
710
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
703
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
711
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
704
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
712
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
-
 
713
        amazonScrapingHistory.otherCost = val.otherCost
705
        amazonScrapingHistory.wanlc = val.nlc
714
        amazonScrapingHistory.wanlc = val.nlc
706
        amazonScrapingHistory.commission = spm.commission
715
        amazonScrapingHistory.commission = spm.commission
707
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
716
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
708
        amazonScrapingHistory.returnProvision = spm.returnProvision
717
        amazonScrapingHistory.returnProvision = spm.returnProvision
709
        amazonScrapingHistory.courierCost = val.courierCost
718
        amazonScrapingHistory.courierCost = val.courierCost
Line 747... Line 756...
747
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
756
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
748
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
757
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
749
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
758
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
750
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
759
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
751
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
760
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
-
 
761
        amazonScrapingHistory.otherCost = val.otherCost
752
        amazonScrapingHistory.wanlc = val.nlc
762
        amazonScrapingHistory.wanlc = val.nlc
753
        amazonScrapingHistory.commission = spm.commission
763
        amazonScrapingHistory.commission = spm.commission
754
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
764
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
755
        amazonScrapingHistory.returnProvision = spm.returnProvision
765
        amazonScrapingHistory.returnProvision = spm.returnProvision
756
        amazonScrapingHistory.courierCost = val.courierCost
766
        amazonScrapingHistory.courierCost = val.courierCost
Line 794... Line 804...
794
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
804
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
795
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
805
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
796
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
806
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
797
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
807
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
798
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
808
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
-
 
809
        amazonScrapingHistory.otherCost = val.otherCost
799
        amazonScrapingHistory.wanlc = val.nlc
810
        amazonScrapingHistory.wanlc = val.nlc
800
        amazonScrapingHistory.commission = spm.commission
811
        amazonScrapingHistory.commission = spm.commission
801
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
812
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
802
        amazonScrapingHistory.returnProvision = spm.returnProvision
813
        amazonScrapingHistory.returnProvision = spm.returnProvision
803
        amazonScrapingHistory.courierCost = val.courierCost
814
        amazonScrapingHistory.courierCost = val.courierCost
Line 844... Line 855...
844
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
855
        amazonScrapingHistory.secondSellerType = amDetails.secondSellerType
845
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
856
        amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
846
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
857
        amazonScrapingHistory.thirdSellerShippingTime = amDetails.thirdSellerShippingTime
847
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
858
        amazonScrapingHistory.thirdSellerRating = amDetails.thirdSellerRating
848
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
859
        amazonScrapingHistory.thirdSellerType = amDetails.thirdSellerType
-
 
860
        amazonScrapingHistory.otherCost = val.otherCost
849
        amazonScrapingHistory.wanlc = val.nlc
861
        amazonScrapingHistory.wanlc = val.nlc
850
        amazonScrapingHistory.commission = spm.commission
862
        amazonScrapingHistory.commission = spm.commission
851
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
863
        amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
852
        amazonScrapingHistory.returnProvision = spm.returnProvision
864
        amazonScrapingHistory.returnProvision = spm.returnProvision
853
        amazonScrapingHistory.courierCost = val.courierCost
865
        amazonScrapingHistory.courierCost = val.courierCost
Line 947... Line 959...
947
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
959
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
948
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
960
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
949
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
961
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
950
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
962
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
951
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
963
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
964
    sheet.write(0, 23, "Other Cost", heading_xf)
952
    sheet.write(0, 23, "WANLC", heading_xf)
965
    sheet.write(0, 24, "WANLC", heading_xf)
953
    sheet.write(0, 24, "Commission", heading_xf)
966
    sheet.write(0, 25, "Commission", heading_xf)
954
    sheet.write(0, 25, "Competitor Commission", heading_xf)
967
    sheet.write(0, 26, "Competitor Commission", heading_xf)
955
    sheet.write(0, 26, "Return Provision", heading_xf)
968
    sheet.write(0, 27, "Return Provision", heading_xf)
956
    sheet.write(0, 27, "Margin", heading_xf)
969
    sheet.write(0, 28, "Margin", heading_xf)
957
    sheet.write(0, 28, "Risky", heading_xf)
970
    sheet.write(0, 29, "Risky", heading_xf)
958
    sheet.write(0, 29, "Proposed Sp", heading_xf)
971
    sheet.write(0, 30, "Proposed Sp", heading_xf)
959
    sheet.write(0, 30, "Proposed Tp", heading_xf)
972
    sheet.write(0, 31, "Proposed Tp", heading_xf)
960
    sheet.write(0, 31, "Target Nlc", heading_xf)
973
    sheet.write(0, 32, "Target Nlc", heading_xf)
961
    sheet.write(0, 32, "Avg Sale", heading_xf)
974
    sheet.write(0, 33, "Avg Sale", heading_xf)
962
    sheet.write(0, 33, "Sales History", heading_xf)
975
    sheet.write(0, 34, "Sales History", heading_xf)
963
    sheet.write(0, 34, "Decision", heading_xf)
976
    sheet.write(0, 35, "Decision", heading_xf)
964
    sheet.write(0, 35, "Reason", heading_xf)
977
    sheet.write(0, 36, "Reason", heading_xf)
965
    sheet.write(0, 36, "Updated Price", heading_xf)
978
    sheet.write(0, 37, "Updated Price", heading_xf)
966
    
979
    
967
    sheet_iterator = 1
980
    sheet_iterator = 1
968
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).all()
981
    cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).all()
969
    for cantCompeteItem in cantCompeteItems:
982
    for cantCompeteItem in cantCompeteItems:
970
        amScraping =  cantCompeteItem[0]
983
        amScraping =  cantCompeteItem[0]
Line 1002... Line 1015...
1002
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1015
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1003
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1016
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1004
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1017
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1005
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1018
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1006
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1019
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1020
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1007
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1021
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1008
        sheet.write(sheet_iterator, 24, amScraping.commission)
1022
        sheet.write(sheet_iterator, 25, amScraping.commission)
1009
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1023
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1010
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1024
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1011
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1025
        sheet.write(sheet_iterator, 28, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1012
        sheet.write(sheet_iterator, 28, item.risky)
1026
        sheet.write(sheet_iterator, 29, item.risky)
1013
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1027
        sheet.write(sheet_iterator, 30, amScraping.proposedSp)
1014
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1028
        sheet.write(sheet_iterator, 31, amScraping.proposedTp)
1015
        sheet.write(sheet_iterator, 31, amScraping.targetNlc)
1029
        sheet.write(sheet_iterator, 32, amScraping.targetNlc)
1016
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1030
        sheet.write(sheet_iterator, 33, amScraping.avgSale)
1017
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1031
        sheet.write(sheet_iterator, 34, getOosString(saleMap.get(sku)))
1018
        if amScraping.decision is None:
1032
        if amScraping.decision is None:
1019
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
1033
            sheet.write(sheet_iterator, 35, 'Auto Pricing Inactive')
1020
            sheet_iterator+=1
1034
            sheet_iterator+=1
1021
            continue
1035
            continue
1022
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1036
        sheet.write(sheet_iterator, 35, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1023
        sheet.write(sheet_iterator, 35, amScraping.reason)
1037
        sheet.write(sheet_iterator, 36, amScraping.reason)
1024
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1038
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1025
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.proposedSellingPrice))
1039
            sheet.write(sheet_iterator, 37, math.ceil(amScraping.proposedSellingPrice))
1026
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1040
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1027
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1041
            sheet.write(sheet_iterator, 37, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1028
        sheet_iterator+=1
1042
        sheet_iterator+=1
1029
    
1043
    
1030
    sheet = wbk.add_sheet('Competitive')
1044
    sheet = wbk.add_sheet('Competitive')
1031
    xstr = lambda s: s or ""
1045
    xstr = lambda s: s or ""
1032
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1046
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1056... Line 1070...
1056
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1070
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1057
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1071
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1058
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1072
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1059
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1073
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1060
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1074
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
1075
    sheet.write(0, 23, "Other Cost", heading_xf)
1061
    sheet.write(0, 23, "WANLC", heading_xf)
1076
    sheet.write(0, 24, "WANLC", heading_xf)
1062
    sheet.write(0, 24, "Commission", heading_xf)
1077
    sheet.write(0, 25, "Commission", heading_xf)
1063
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1078
    sheet.write(0, 26, "Competitor Commission", heading_xf)
1064
    sheet.write(0, 26, "Return Provision", heading_xf)
1079
    sheet.write(0, 27, "Return Provision", heading_xf)
1065
    sheet.write(0, 27, "Margin", heading_xf)
1080
    sheet.write(0, 28, "Margin", heading_xf)
1066
    sheet.write(0, 28, "Risky", heading_xf)
1081
    sheet.write(0, 29, "Risky", heading_xf)
1067
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1082
    sheet.write(0, 30, "Proposed Sp", heading_xf)
1068
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1083
    sheet.write(0, 31, "Proposed Tp", heading_xf)
1069
    sheet.write(0, 31, "Avg Sale", heading_xf)
1084
    sheet.write(0, 32, "Avg Sale", heading_xf)
1070
    sheet.write(0, 32, "Sales History", heading_xf)
1085
    sheet.write(0, 33, "Sales History", heading_xf)
1071
    sheet.write(0, 33, "Decision", heading_xf)
1086
    sheet.write(0, 34, "Decision", heading_xf)
1072
    sheet.write(0, 34, "Reason", heading_xf)
1087
    sheet.write(0, 35, "Reason", heading_xf)
1073
    sheet.write(0, 35, "Updated Price", heading_xf)
1088
    sheet.write(0, 36, "Updated Price", heading_xf)
1074
    
1089
    
1075
    sheet_iterator = 1
1090
    sheet_iterator = 1
1076
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).all()
1091
    competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).all()
1077
    for competitiveItem in competitiveItems:
1092
    for competitiveItem in competitiveItems:
1078
        amScraping =  competitiveItem[0]
1093
        amScraping =  competitiveItem[0]
Line 1110... Line 1125...
1110
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1125
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1111
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1126
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1112
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1127
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1113
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1128
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1114
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1129
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1130
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1115
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1131
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1116
        sheet.write(sheet_iterator, 24, amScraping.commission)
1132
        sheet.write(sheet_iterator, 25, amScraping.commission)
1117
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1133
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1118
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1134
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1119
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1135
        sheet.write(sheet_iterator, 28, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1120
        sheet.write(sheet_iterator, 28, item.risky)
1136
        sheet.write(sheet_iterator, 29, item.risky)
1121
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1137
        sheet.write(sheet_iterator, 30, amScraping.proposedSp)
1122
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1138
        sheet.write(sheet_iterator, 31, amScraping.proposedTp)
1123
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1139
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1124
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1140
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1125
        if amScraping.decision is None:
1141
        if amScraping.decision is None:
1126
            sheet.write(sheet_iterator, 33, 'Auto Pricing Inactive')
1142
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
1127
            sheet_iterator+=1
1143
            sheet_iterator+=1
1128
            continue
1144
            continue
1129
        sheet.write(sheet_iterator, 33, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1145
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1130
        sheet.write(sheet_iterator, 34, amScraping.reason)
1146
        sheet.write(sheet_iterator, 35, amScraping.reason)
1131
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1147
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1132
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.proposedSellingPrice))
1148
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.proposedSellingPrice))
1133
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1149
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1134
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1150
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1135
        sheet_iterator+=1
1151
        sheet_iterator+=1
1136
    
1152
    
1137
    sheet = wbk.add_sheet('Almost Competitive')
1153
    sheet = wbk.add_sheet('Almost Competitive')
1138
    xstr = lambda s: s or ""
1154
    xstr = lambda s: s or ""
1139
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1155
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1163... Line 1179...
1163
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1179
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1164
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1180
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1165
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1181
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1166
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1182
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1167
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1183
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
1184
    sheet.write(0, 23, "Other Cost", heading_xf)
1168
    sheet.write(0, 23, "WANLC", heading_xf)
1185
    sheet.write(0, 24, "WANLC", heading_xf)
1169
    sheet.write(0, 24, "Commission", heading_xf)
1186
    sheet.write(0, 25, "Commission", heading_xf)
1170
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1187
    sheet.write(0, 26, "Competitor Commission", heading_xf)
1171
    sheet.write(0, 26, "Return Provision", heading_xf)
1188
    sheet.write(0, 27, "Return Provision", heading_xf)
1172
    sheet.write(0, 27, "Margin", heading_xf)
1189
    sheet.write(0, 28, "Margin", heading_xf)
1173
    sheet.write(0, 28, "Risky", heading_xf)
1190
    sheet.write(0, 29, "Risky", heading_xf)
1174
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1191
    sheet.write(0, 30, "Proposed Sp", heading_xf)
1175
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1192
    sheet.write(0, 31, "Proposed Tp", heading_xf)
1176
    sheet.write(0, 31, "Avg Sale", heading_xf)
1193
    sheet.write(0, 32, "Avg Sale", heading_xf)
1177
    sheet.write(0, 32, "Sales History", heading_xf)
1194
    sheet.write(0, 33, "Sales History", heading_xf)
1178
    sheet.write(0, 33, "Decision", heading_xf)
1195
    sheet.write(0, 34, "Decision", heading_xf)
1179
    sheet.write(0, 34, "Reason", heading_xf)
1196
    sheet.write(0, 35, "Reason", heading_xf)
1180
    sheet.write(0, 35, "Updated Price", heading_xf)
1197
    sheet.write(0, 36, "Updated Price", heading_xf)
1181
    
1198
    
1182
    sheet_iterator = 1
1199
    sheet_iterator = 1
1183
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).all()
1200
    almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).all()
1184
    for almostCompetitiveItem in almostCompetitiveItems:
1201
    for almostCompetitiveItem in almostCompetitiveItems:
1185
        amScraping =  almostCompetitiveItem[0]
1202
        amScraping =  almostCompetitiveItem[0]
Line 1226... Line 1243...
1226
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1243
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1227
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1244
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1228
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1245
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1229
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1246
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1230
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1247
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1248
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1231
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1249
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1232
        sheet.write(sheet_iterator, 24, amScraping.commission)
1250
        sheet.write(sheet_iterator, 25, amScraping.commission)
1233
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1251
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1234
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1252
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1235
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1253
        sheet.write(sheet_iterator, 28, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1236
        sheet.write(sheet_iterator, 28, item.risky)
1254
        sheet.write(sheet_iterator, 29, item.risky)
1237
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1255
        sheet.write(sheet_iterator, 30, amScraping.proposedSp)
1238
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1256
        sheet.write(sheet_iterator, 31, amScraping.proposedTp)
1239
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1257
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1240
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1258
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1241
        if amScraping.decision is None:
1259
        if amScraping.decision is None:
1242
            sheet.write(sheet_iterator, 33, 'Auto Pricing Inactive')
1260
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
1243
            sheet_iterator+=1
1261
            sheet_iterator+=1
1244
            continue
1262
            continue
1245
        sheet.write(sheet_iterator, 33, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1263
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1246
        sheet.write(sheet_iterator, 34, amScraping.reason)
1264
        sheet.write(sheet_iterator, 35, amScraping.reason)
1247
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1265
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1248
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.proposedSellingPrice))
1266
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.proposedSellingPrice))
1249
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1267
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1250
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1268
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1251
        sheet_iterator+=1
1269
        sheet_iterator+=1
1252
    
1270
    
1253
    sheet = wbk.add_sheet('Among Cheapest')
1271
    sheet = wbk.add_sheet('Among Cheapest')
1254
    xstr = lambda s: s or ""
1272
    xstr = lambda s: s or ""
1255
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1273
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1279... Line 1297...
1279
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1297
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1280
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1298
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1281
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1299
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1282
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1300
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1283
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1301
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
1302
    sheet.write(0, 23, "Other Cost", heading_xf)
1284
    sheet.write(0, 23, "WANLC", heading_xf)
1303
    sheet.write(0, 24, "WANLC", heading_xf)
1285
    sheet.write(0, 24, "Commission", heading_xf)
1304
    sheet.write(0, 25, "Commission", heading_xf)
1286
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1305
    sheet.write(0, 26, "Competitor Commission", heading_xf)
1287
    sheet.write(0, 26, "Return Provision", heading_xf)
1306
    sheet.write(0, 27, "Return Provision", heading_xf)
1288
    sheet.write(0, 27, "Margin", heading_xf)
1307
    sheet.write(0, 28, "Margin", heading_xf)
1289
    sheet.write(0, 28, "Risky", heading_xf)
1308
    sheet.write(0, 29, "Risky", heading_xf)
1290
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1309
    sheet.write(0, 30, "Proposed Sp", heading_xf)
1291
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1310
    sheet.write(0, 31, "Proposed Tp", heading_xf)
1292
    sheet.write(0, 31, "Avg Sale", heading_xf)
1311
    sheet.write(0, 32, "Avg Sale", heading_xf)
1293
    sheet.write(0, 32, "Sales History", heading_xf)
1312
    sheet.write(0, 33, "Sales History", heading_xf)
1294
    sheet.write(0, 33, "Decision", heading_xf)
1313
    sheet.write(0, 34, "Decision", heading_xf)
1295
    sheet.write(0, 34, "Reason", heading_xf)
1314
    sheet.write(0, 35, "Reason", heading_xf)
1296
    sheet.write(0, 35, "Updated Price", heading_xf)
1315
    sheet.write(0, 36, "Updated Price", heading_xf)
1297
    
1316
    
1298
    sheet_iterator = 1
1317
    sheet_iterator = 1
1299
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1318
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1300
    for amongCheapestItem in amongCheapestItems:
1319
    for amongCheapestItem in amongCheapestItems:
1301
        amScraping =  amongCheapestItem[0]
1320
        amScraping =  amongCheapestItem[0]
Line 1333... Line 1352...
1333
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1352
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1334
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1353
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1335
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1354
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1336
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1355
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1337
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1356
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1357
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1338
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1358
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1339
        sheet.write(sheet_iterator, 24, amScraping.commission)
1359
        sheet.write(sheet_iterator, 25, amScraping.commission)
1340
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1360
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1341
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1361
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1342
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1362
        sheet.write(sheet_iterator, 28, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1343
        sheet.write(sheet_iterator, 28, item.risky)
1363
        sheet.write(sheet_iterator, 29, item.risky)
1344
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1364
        sheet.write(sheet_iterator, 30, amScraping.proposedSp)
1345
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1365
        sheet.write(sheet_iterator, 31, amScraping.proposedTp)
1346
        sheet.write(sheet_iterator, 31, amScraping.avgSale)
1366
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1347
        sheet.write(sheet_iterator, 32, getOosString(saleMap.get(sku)))
1367
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1348
        if amScraping.decision is None:
1368
        if amScraping.decision is None:
1349
            sheet.write(sheet_iterator, 33, 'Auto Pricing Inactive')
1369
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
1350
            sheet_iterator+=1
1370
            sheet_iterator+=1
1351
            continue
1371
            continue
1352
        sheet.write(sheet_iterator, 33, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1372
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1353
        sheet.write(sheet_iterator, 34, amScraping.reason)
1373
        sheet.write(sheet_iterator, 35, amScraping.reason)
1354
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1374
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1355
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.proposedSellingPrice))
1375
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.proposedSellingPrice))
1356
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1376
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1357
            sheet.write(sheet_iterator, 35, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1377
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1358
        sheet_iterator+=1
1378
        sheet_iterator+=1
1359
    
1379
    
1360
    sheet = wbk.add_sheet('Cheapest')
1380
    sheet = wbk.add_sheet('Cheapest')
1361
    xstr = lambda s: s or ""
1381
    xstr = lambda s: s or ""
1362
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1382
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1386... Line 1406...
1386
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1406
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1387
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1407
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1388
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1408
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1389
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1409
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1390
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1410
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
1411
    sheet.write(0, 23, "Other Cost", heading_xf)
1391
    sheet.write(0, 23, "WANLC", heading_xf)
1412
    sheet.write(0, 24, "WANLC", heading_xf)
1392
    sheet.write(0, 24, "Commission", heading_xf)
1413
    sheet.write(0, 25, "Commission", heading_xf)
1393
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1414
    sheet.write(0, 26, "Competitor Commission", heading_xf)
1394
    sheet.write(0, 26, "Return Provision", heading_xf)
1415
    sheet.write(0, 27, "Return Provision", heading_xf)
1395
    sheet.write(0, 27, "Margin", heading_xf)
1416
    sheet.write(0, 28, "Margin", heading_xf)
1396
    sheet.write(0, 28, "Risky", heading_xf)
1417
    sheet.write(0, 29, "Risky", heading_xf)
1397
    sheet.write(0, 29, "Proposed Sp", heading_xf)
1418
    sheet.write(0, 30, "Proposed Sp", heading_xf)
1398
    sheet.write(0, 30, "Proposed Tp", heading_xf)
1419
    sheet.write(0, 31, "Proposed Tp", heading_xf)
1399
    sheet.write(0, 31, "Margin Increased Potential", heading_xf)
1420
    sheet.write(0, 32, "Margin Increased Potential", heading_xf)
1400
    sheet.write(0, 32, "Avg Sale", heading_xf)
1421
    sheet.write(0, 33, "Avg Sale", heading_xf)
1401
    sheet.write(0, 33, "Sales History", heading_xf)
1422
    sheet.write(0, 34, "Sales History", heading_xf)
1402
    sheet.write(0, 34, "Decision", heading_xf)
1423
    sheet.write(0, 35, "Decision", heading_xf)
1403
    sheet.write(0, 35, "Reason", heading_xf)
1424
    sheet.write(0, 36, "Reason", heading_xf)
1404
    sheet.write(0, 36, "Updated Price", heading_xf)
1425
    sheet.write(0, 37, "Updated Price", heading_xf)
1405
    
1426
    
1406
    sheet_iterator = 1
1427
    sheet_iterator = 1
1407
    cheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX).all()
1428
    cheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX).all()
1408
    for cheapestItem in cheapestItems:
1429
    for cheapestItem in cheapestItems:
1409
        amScraping =  cheapestItem[0]
1430
        amScraping =  cheapestItem[0]
Line 1441... Line 1462...
1441
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1462
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1442
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1463
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1443
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1464
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1444
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1465
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1445
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1466
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1467
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1446
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1468
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1447
        sheet.write(sheet_iterator, 24, amScraping.commission)
1469
        sheet.write(sheet_iterator, 25, amScraping.commission)
1448
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1470
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1449
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1471
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1450
        sheet.write(sheet_iterator, 27, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1472
        sheet.write(sheet_iterator, 28, round(amScraping.ourSellingPrice - amScraping.lowestPossibleSp))
1451
        sheet.write(sheet_iterator, 28, item.risky)
1473
        sheet.write(sheet_iterator, 29, item.risky)
1452
        sheet.write(sheet_iterator, 29, amScraping.proposedSp)
1474
        sheet.write(sheet_iterator, 30, amScraping.proposedSp)
1453
        sheet.write(sheet_iterator, 30, amScraping.proposedTp)
1475
        sheet.write(sheet_iterator, 31, amScraping.proposedTp)
1454
        sheet.write(sheet_iterator, 31, amScraping.targetNlc)
1476
        sheet.write(sheet_iterator, 32, amScraping.targetNlc)
1455
        sheet.write(sheet_iterator, 32, amScraping.avgSale)
1477
        sheet.write(sheet_iterator, 33, amScraping.avgSale)
1456
        sheet.write(sheet_iterator, 33, getOosString(saleMap.get(sku)))
1478
        sheet.write(sheet_iterator, 34, getOosString(saleMap.get(sku)))
1457
        if amScraping.decision is None:
1479
        if amScraping.decision is None:
1458
            sheet.write(sheet_iterator, 34, 'Auto Pricing Inactive')
1480
            sheet.write(sheet_iterator, 35, 'Auto Pricing Inactive')
1459
            sheet_iterator+=1
1481
            sheet_iterator+=1
1460
            continue
1482
            continue
1461
        sheet.write(sheet_iterator, 34, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1483
        sheet.write(sheet_iterator, 35, Decision._VALUES_TO_NAMES.get(amScraping.decision))
1462
        sheet.write(sheet_iterator, 35, amScraping.reason)
1484
        sheet.write(sheet_iterator, 36, amScraping.reason)
1463
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1485
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
1464
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.proposedSellingPrice))
1486
            sheet.write(sheet_iterator, 37, math.ceil(amScraping.proposedSellingPrice))
1465
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1487
        if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
1466
            sheet.write(sheet_iterator, 36, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1488
            sheet.write(sheet_iterator, 37, math.ceil(amScraping.ourSellingPrice+max(10,.01*amScraping.ourSellingPrice)))
1467
        sheet_iterator+=1
1489
        sheet_iterator+=1
1468
    
1490
    
1469
    sheet = wbk.add_sheet('Negative Margin')
1491
    sheet = wbk.add_sheet('Negative Margin')
1470
    xstr = lambda s: s or ""
1492
    xstr = lambda s: s or ""
1471
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1493
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
Line 1495... Line 1517...
1495
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1517
    sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
1496
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1518
    sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
1497
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1519
    sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
1498
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1520
    sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
1499
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
1521
    sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
-
 
1522
    sheet.write(0, 23, "Other Cost", heading_xf)
1500
    sheet.write(0, 23, "WANLC", heading_xf)
1523
    sheet.write(0, 24, "WANLC", heading_xf)
1501
    sheet.write(0, 24, "Commission", heading_xf)
1524
    sheet.write(0, 25, "Commission", heading_xf)
1502
    sheet.write(0, 25, "Competitor Commission", heading_xf)
1525
    sheet.write(0, 26, "Competitor Commission", heading_xf)
1503
    sheet.write(0, 26, "Return Provision", heading_xf)
1526
    sheet.write(0, 27, "Return Provision", heading_xf)
1504
    sheet.write(0, 27, "Margin", heading_xf)
1527
    sheet.write(0, 28, "Margin", heading_xf)
1505
    sheet.write(0, 28, "Avg Sale", heading_xf)
1528
    sheet.write(0, 29, "Avg Sale", heading_xf)
1506
    sheet.write(0, 29, "Sales History", heading_xf)
1529
    sheet.write(0, 30, "Sales History", heading_xf)
1507
    
1530
    
1508
    sheet_iterator = 1
1531
    sheet_iterator = 1
1509
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1532
    amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).all()
1510
    for amongCheapestItem in amongCheapestItems:
1533
    for amongCheapestItem in amongCheapestItems:
1511
        amScraping =  amongCheapestItem[0]
1534
        amScraping =  amongCheapestItem[0]
Line 1543... Line 1566...
1543
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1566
        sheet.write(sheet_iterator, 18, amScraping.secondLowestSellerRating)
1544
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1567
        sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerShippingTime)
1545
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1568
        sheet.write(sheet_iterator, 20, amScraping.thirdLowestSellerSp)
1546
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1569
        sheet.write(sheet_iterator, 21, amScraping.thirdLowestSellerRating)
1547
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
1570
        sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerShippingTime)
-
 
1571
        sheet.write(sheet_iterator, 23, amScraping.otherCost)
1548
        sheet.write(sheet_iterator, 23, amScraping.wanlc)
1572
        sheet.write(sheet_iterator, 24, amScraping.wanlc)
1549
        sheet.write(sheet_iterator, 24, amScraping.commission)
1573
        sheet.write(sheet_iterator, 25, amScraping.commission)
1550
        sheet.write(sheet_iterator, 25, amScraping.competitorCommission)
1574
        sheet.write(sheet_iterator, 26, amScraping.competitorCommission)
1551
        sheet.write(sheet_iterator, 26, amScraping.returnProvision)
1575
        sheet.write(sheet_iterator, 27, amScraping.returnProvision)
1552
        sheet.write(sheet_iterator, 27, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1576
        sheet.write(sheet_iterator, 28, round(amScraping.ourTp - amScraping.lowestPossibleTp))
1553
        sheet.write(sheet_iterator, 28, amScraping.avgSale)
1577
        sheet.write(sheet_iterator, 29, amScraping.avgSale)
1554
        sheet.write(sheet_iterator, 29, getOosString(saleMap.get(sku)))
1578
        sheet.write(sheet_iterator, 30, getOosString(saleMap.get(sku)))
1555
        sheet_iterator+=1
1579
        sheet_iterator+=1
1556
    
1580
    
1557
    sheet = wbk.add_sheet('Exception List')
1581
    sheet = wbk.add_sheet('Exception List')
1558
    xstr = lambda s: s or ""
1582
    xstr = lambda s: s or ""
1559
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
1583
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')