| Line 262... |
Line 262... |
| 262 |
amHistory.reason = reason
|
262 |
amHistory.reason = reason
|
| 263 |
|
263 |
|
| 264 |
def calculateAverageSale(sku):
|
264 |
def calculateAverageSale(sku):
|
| 265 |
count,sale = 0,0
|
265 |
count,sale = 0,0
|
| 266 |
oosStatus = saleMap.get(sku)
|
266 |
oosStatus = saleMap.get(sku)
|
| - |
|
267 |
if oosStatus is None:
|
| - |
|
268 |
return 0.0
|
| 267 |
for obj in oosStatus:
|
269 |
for obj in oosStatus:
|
| 268 |
if not obj.isOutOfStock:
|
270 |
if not obj.isOutOfStock:
|
| 269 |
count+=1
|
271 |
count+=1
|
| 270 |
sale = sale+obj.totalOrderCount
|
272 |
sale = sale+obj.totalOrderCount
|
| 271 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
273 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
| 272 |
return round(avgSalePerDay,2)
|
274 |
return round(avgSalePerDay,2)
|
| 273 |
|
275 |
|
| 274 |
|
276 |
|
| 275 |
def getOosString(oosStatus):
|
277 |
def getOosString(oosStatus):
|
| - |
|
278 |
if oosStatus is None:
|
| - |
|
279 |
return ""
|
| 276 |
lastNdaySale=""
|
280 |
lastNdaySale=""
|
| 277 |
for obj in oosStatus:
|
281 |
for obj in oosStatus:
|
| 278 |
if obj.isOutOfStock:
|
282 |
if obj.isOutOfStock:
|
| 279 |
lastNdaySale += "X-"
|
283 |
lastNdaySale += "X-"
|
| 280 |
else:
|
284 |
else:
|
| Line 287... |
Line 291... |
| 287 |
else:
|
291 |
else:
|
| 288 |
return fbaSaleSnapshot.totalOrderCount
|
292 |
return fbaSaleSnapshot.totalOrderCount
|
| 289 |
|
293 |
|
| 290 |
def getNoOfDaysInStock(oosStatus):
|
294 |
def getNoOfDaysInStock(oosStatus):
|
| 291 |
inStockCount = 0
|
295 |
inStockCount = 0
|
| - |
|
296 |
if oosStatus is None:
|
| - |
|
297 |
return 0
|
| 292 |
for obj in oosStatus:
|
298 |
for obj in oosStatus:
|
| 293 |
if not obj.isOutOfStock:
|
299 |
if not obj.isOutOfStock:
|
| 294 |
inStockCount+=1
|
300 |
inStockCount+=1
|
| 295 |
return inStockCount
|
301 |
return inStockCount
|
| 296 |
|
302 |
|
| Line 484... |
Line 490... |
| 484 |
if wpiTodayExpiry.has_key(amPromotion.sku):
|
490 |
if wpiTodayExpiry.has_key(amPromotion.sku):
|
| 485 |
continue
|
491 |
continue
|
| 486 |
wpiTodayExpiry[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
|
492 |
wpiTodayExpiry[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
|
| 487 |
session.close()
|
493 |
session.close()
|
| 488 |
print "No of items populated ",len(itemInfo)
|
494 |
print "No of items populated ",len(itemInfo)
|
| 489 |
sleep(5)
|
- |
|
| 490 |
return itemInfo
|
495 |
return itemInfo
|
| 491 |
|
496 |
|
| 492 |
def getPriceAndAsin(itemInfo):
|
497 |
def getPriceAndAsin(itemInfo):
|
| 493 |
skus = []
|
498 |
skus = []
|
| 494 |
for item in itemInfo:
|
499 |
for item in itemInfo:
|
| Line 535... |
Line 540... |
| 535 |
else:
|
540 |
else:
|
| 536 |
print "No other seller or Unable to fetch competitive pricing"
|
541 |
print "No other seller or Unable to fetch competitive pricing"
|
| 537 |
val.exceptionType = 3
|
542 |
val.exceptionType = 3
|
| 538 |
#temp.append("No other seller or Unable to fetch competitive pricing")
|
543 |
#temp.append("No other seller or Unable to fetch competitive pricing")
|
| 539 |
temp.append(val)
|
544 |
temp.append(val)
|
| - |
|
545 |
if val.exceptionType ==3:
|
| - |
|
546 |
val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
|
| - |
|
547 |
val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
|
| - |
|
548 |
val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
|
| - |
|
549 |
sku = val.sku
|
| - |
|
550 |
try:
|
| - |
|
551 |
val.vatRate = getVatRate(val.sku[3:],val.state_id,val.promoPrice)
|
| - |
|
552 |
except:
|
| - |
|
553 |
val.exceptionType = 6
|
| - |
|
554 |
if (ourPricingForSku.get(val.sku).get('promotion')!=(amazonLongTermActivePromotions.has_key(val.sku) or amazonShortTermActivePromotions.has_key(val.sku))):
|
| - |
|
555 |
val.exceptionType = 4
|
| - |
|
556 |
if val.exceptionType ==3:
|
| - |
|
557 |
lowestPossibleSp = getLowestPossibleSp(None,val,val.sourcePercentage)
|
| - |
|
558 |
amPricing = __AmazonPricing(val.ourSp,lowestPossibleSp)
|
| - |
|
559 |
amDetails = __AmazonDetails(sku, float(val.ourSp), 1, '',float(val.ourSp),'', float(0), '', float(0),1,False,val.promoPrice,val.isPromo, \
|
| - |
|
560 |
'0-0' ,0, '0-0', 0, '0-0' , 0, 'Amazon', '', '', \
|
| - |
|
561 |
0,0,0,False,False,True,None)
|
| - |
|
562 |
temp.append(amDetails)
|
| - |
|
563 |
temp.append(amPricing)
|
| 540 |
exceptionList.append(temp)
|
564 |
exceptionList.append(temp)
|
| 541 |
continue
|
565 |
continue
|
| 542 |
val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
|
566 |
val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
|
| 543 |
val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
|
567 |
val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
|
| 544 |
val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
|
568 |
val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
|
| Line 595... |
Line 619... |
| 595 |
lowestSellerShippingTime ,lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, \
|
619 |
lowestSellerShippingTime ,lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, \
|
| 596 |
competitvePricingInfo['lowestMfnIgnored'],competitvePricingInfo['lowestMfn'],competitvePricingInfo['lowestFba'],competitvePricingInfo['isLowestMfnIgnored'],competitvePricingInfo['isLowestMfn'],competitvePricingInfo['isLowestFba'],None)
|
620 |
competitvePricingInfo['lowestMfnIgnored'],competitvePricingInfo['lowestMfn'],competitvePricingInfo['lowestFba'],competitvePricingInfo['isLowestMfnIgnored'],competitvePricingInfo['isLowestMfn'],competitvePricingInfo['isLowestFba'],None)
|
| 597 |
|
621 |
|
| 598 |
competitivePrice = decideCompetitvePricing(amDetails,val.ourInventory,timestamp)
|
622 |
competitivePrice = decideCompetitvePricing(amDetails,val.ourInventory,timestamp)
|
| 599 |
amDetails.competitivePrice = competitivePrice
|
623 |
amDetails.competitivePrice = competitivePrice
|
| - |
|
624 |
|
| - |
|
625 |
try:
|
| 600 |
if amDetails.competitivePrice==0.0 and amDetails.ourRank > 1:
|
626 |
val.vatRate = getVatRate(val.sku[3:], val.state_id, amDetails.promoPrice)
|
| - |
|
627 |
except:
|
| 601 |
temp = []
|
628 |
temp = []
|
| 602 |
val.exceptionType = 5
|
629 |
val.exceptionType = 6
|
| 603 |
temp.append(val)
|
630 |
temp.append(val)
|
| 604 |
temp.append("Unable to calculate competitive pricing")
|
- |
|
| 605 |
exceptionList.append(temp)
|
631 |
exceptionList.append(temp)
|
| 606 |
continue
|
632 |
continue
|
| 607 |
try:
|
633 |
|
| 608 |
print "inside val getter"
|
- |
|
| 609 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==int(val.sku[3:]), ItemVatMaster.stateId==val.state_id)).first()
|
- |
|
| 610 |
if itemVatMaster is None:
|
- |
|
| 611 |
d_item = Item.query.filter_by(id=int(val.sku[3:])).first()
|
- |
|
| 612 |
if d_item is None:
|
- |
|
| 613 |
raise
|
- |
|
| 614 |
else:
|
- |
|
| 615 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==d_item.category, CategoryVatMaster.minVal<=amDetails.promoPrice, CategoryVatMaster.maxVal>=amDetails.promoPrice, CategoryVatMaster.stateId == val.state_id)).first()
|
634 |
if amDetails.competitivePrice==0.0 and amDetails.ourRank > 1:
|
| 616 |
if vatMaster is None:
|
- |
|
| 617 |
raise
|
- |
|
| 618 |
else:
|
- |
|
| 619 |
val.vatRate = vatMaster.vatPercent
|
- |
|
| 620 |
print "vat fetched"
|
- |
|
| 621 |
else:
|
- |
|
| 622 |
val.vatRate = itemVatMaster.vatPercentage
|
- |
|
| 623 |
print "vat fetched"
|
- |
|
| 624 |
except:
|
- |
|
| 625 |
print "vat exception"
|
- |
|
| 626 |
temp = []
|
635 |
temp = []
|
| 627 |
val.exceptionType = 6
|
636 |
val.exceptionType = 5
|
| 628 |
temp.append(val)
|
637 |
temp.append(val)
|
| 629 |
temp.append("Vat not available")
|
638 |
temp.append(amDetails)
|
| - |
|
639 |
lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
|
| - |
|
640 |
amPricing = __AmazonPricing(ourSp,lowestPossibleSp)
|
| - |
|
641 |
temp.append(amPricing)
|
| 630 |
exceptionList.append(temp)
|
642 |
exceptionList.append(temp)
|
| 631 |
continue
|
643 |
continue
|
| 632 |
|
644 |
|
| 633 |
lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
|
645 |
lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
|
| 634 |
print "Creating pricing obj"
|
646 |
print "Creating pricing obj"
|
| Line 789... |
Line 801... |
| 789 |
def commitExceptionList(exceptionList,timestamp,runType):
|
801 |
def commitExceptionList(exceptionList,timestamp,runType):
|
| 790 |
for exceptionItem in exceptionList:
|
802 |
for exceptionItem in exceptionList:
|
| 791 |
val = exceptionItem[0]
|
803 |
val = exceptionItem[0]
|
| 792 |
amazonScrapingHistory = AmazonScrapingHistory()
|
804 |
amazonScrapingHistory = AmazonScrapingHistory()
|
| 793 |
amazonScrapingHistory.item_id = val.sku[3:]
|
805 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| - |
|
806 |
amazonScrapingHistory.asin = val.asin
|
| 794 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
807 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 795 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
808 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 796 |
amazonScrapingHistory.ourSellingPrice = val.ourSp
|
809 |
amazonScrapingHistory.ourSellingPrice = val.ourSp
|
| 797 |
amazonScrapingHistory.promoPrice = val.promoPrice
|
810 |
amazonScrapingHistory.promoPrice = val.promoPrice
|
| 798 |
amazonScrapingHistory.reason = exceptionMap.get(val.exceptionType)
|
811 |
amazonScrapingHistory.reason = exceptionMap.get(val.exceptionType)
|
| 799 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
812 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
| 800 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.EXCEPTION
|
813 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.EXCEPTION
|
| - |
|
814 |
amazonScrapingHistory.exceptionType = val.exceptionType
|
| - |
|
815 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
| - |
|
816 |
if val.exceptionType in (3,5):
|
| - |
|
817 |
amDetails = exceptionItem[1]
|
| - |
|
818 |
amPricing = exceptionItem[2]
|
| - |
|
819 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
| - |
|
820 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
| - |
|
821 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
| - |
|
822 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
| - |
|
823 |
else:
|
| - |
|
824 |
subsidy = 0
|
| - |
|
825 |
spm = val.sourcePercentage
|
| - |
|
826 |
amazonScrapingHistory.subsidy = subsidy
|
| - |
|
827 |
amazonScrapingHistory.vatRate = val.vatRate
|
| - |
|
828 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
| - |
|
829 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
| - |
|
830 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| - |
|
831 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
| - |
|
832 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
| - |
|
833 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| - |
|
834 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| - |
|
835 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
| - |
|
836 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
| - |
|
837 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| - |
|
838 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| - |
|
839 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
| - |
|
840 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
| - |
|
841 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| - |
|
842 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
| - |
|
843 |
amazonScrapingHistory.cheapestMfnCount = True
|
| - |
|
844 |
else:
|
| - |
|
845 |
amazonScrapingHistory.cheapestMfnCount = False
|
| - |
|
846 |
amazonScrapingHistory.wanlc = val.nlc
|
| - |
|
847 |
amazonScrapingHistory.otherCost = val.otherCost
|
| - |
|
848 |
amazonScrapingHistory.commission = spm.commission
|
| - |
|
849 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| - |
|
850 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
| - |
|
851 |
amazonScrapingHistory.isLowestMfnIgnored = amDetails.isLowestMfnIgnored
|
| - |
|
852 |
amazonScrapingHistory.isLowestMfn = amDetails.isLowestMfn
|
| - |
|
853 |
amazonScrapingHistory.isLowestFba = amDetails.isLowestFba
|
| - |
|
854 |
amazonScrapingHistory.lowestMfnIgnoredOffer =amDetails.lowestMfnIgnoredOffer
|
| - |
|
855 |
amazonScrapingHistory.lowestMfnOffer = amDetails.lowestMfnOffer
|
| - |
|
856 |
amazonScrapingHistory.lowestFbaOffer = amDetails.lowestFbaOffer
|
| - |
|
857 |
amazonScrapingHistory.courierCost = val.courierCost
|
| - |
|
858 |
amazonScrapingHistory.risky = val.risky
|
| - |
|
859 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
| - |
|
860 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
| - |
|
861 |
amazonScrapingHistory.timestamp = timestamp
|
| - |
|
862 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| - |
|
863 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| - |
|
864 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 801 |
amazonScrapingHistory.timestamp = timestamp
|
865 |
amazonScrapingHistory.timestamp = timestamp
|
| 802 |
session.commit()
|
866 |
session.commit()
|
| 803 |
|
867 |
|
| 804 |
def commitNegativeMargin(negativeMargin,timestamp,runType):
|
868 |
def commitNegativeMargin(negativeMargin,timestamp,runType):
|
| 805 |
for negativeMarginItem in negativeMargin:
|
869 |
for negativeMarginItem in negativeMargin:
|
| Line 1204... |
Line 1268... |
| 1204 |
def markAutoFavourites(time):
|
1268 |
def markAutoFavourites(time):
|
| 1205 |
nowAutoFav = []
|
1269 |
nowAutoFav = []
|
| 1206 |
previouslyAutoFav = []
|
1270 |
previouslyAutoFav = []
|
| 1207 |
stockList = []
|
1271 |
stockList = []
|
| 1208 |
saleList = []
|
1272 |
saleList = []
|
| 1209 |
items = session.query(func.sum(AmazonScrapingHistory.ourInventory),AmazonScrapingHistory.item_id).group_by(AmazonScrapingHistory.item_id).all()
|
1273 |
items = session.query(func.sum(AmazonScrapingHistory.ourInventory),AmazonScrapingHistory.item_id).filter(AmazonScrapingHistory.timestamp==time).group_by(AmazonScrapingHistory.item_id).all()
|
| 1210 |
allItems = session.query(Amazonlisted).all()
|
1274 |
allItems = session.query(Amazonlisted).all()
|
| 1211 |
for item in items:
|
1275 |
for item in items:
|
| 1212 |
reason = ""
|
1276 |
reason = ""
|
| 1213 |
if item[0]>=5:
|
1277 |
if item[0]>=5:
|
| 1214 |
stockList.append(item[1])
|
1278 |
stockList.append(item[1])
|
| Line 1295... |
Line 1359... |
| 1295 |
sheet.write(0, 41, "Sales History", heading_xf)
|
1359 |
sheet.write(0, 41, "Sales History", heading_xf)
|
| 1296 |
sheet.write(0, 42, "Decision", heading_xf)
|
1360 |
sheet.write(0, 42, "Decision", heading_xf)
|
| 1297 |
sheet.write(0, 43, "Reason", heading_xf)
|
1361 |
sheet.write(0, 43, "Reason", heading_xf)
|
| 1298 |
sheet.write(0, 44, "Updated Price", heading_xf)
|
1362 |
sheet.write(0, 44, "Updated Price", heading_xf)
|
| 1299 |
sheet.write(0, 45, "Proposed Margin", heading_xf)
|
1363 |
sheet.write(0, 45, "Proposed Margin", heading_xf)
|
| 1300 |
sheet.write(0, 46, "Inventory Movement Status")
|
1364 |
sheet.write(0, 46, "Inventory Movement Status", heading_xf)
|
| 1301 |
|
1365 |
|
| 1302 |
def getPackagingCost(data):
|
1366 |
def getPackagingCost(data):
|
| 1303 |
#TODO : Get packagingCost from marketplaceitems table
|
1367 |
#TODO : Get packagingCost from marketplaceitems table
|
| 1304 |
return 15
|
1368 |
return 15
|
| 1305 |
|
1369 |
|
| Line 1390... |
Line 1454... |
| 1390 |
margin = amScraping.promoPrice - myCosts + amScraping.subsidy
|
1454 |
margin = amScraping.promoPrice - myCosts + amScraping.subsidy
|
| 1391 |
print 'margin for ',amScraping.item_id,' is ',margin
|
1455 |
print 'margin for ',amScraping.item_id,' is ',margin
|
| 1392 |
return round(margin)
|
1456 |
return round(margin)
|
| 1393 |
|
1457 |
|
| 1394 |
def getNewMargin(amScraping,proposedSp):
|
1458 |
def getNewMargin(amScraping,proposedSp):
|
| 1395 |
myCosts = amScraping.wanlc + getCourierCost(amScraping) + getClosingFee(amScraping) + getNewCommission(amScraping,proposedSp) + getPackagingCost(amScraping) + getNewVat(amScraping,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,proposedSp),proposedSp) + getNewReturnCost(amScraping,proposedSp) + amScraping.otherCost
|
1459 |
myCosts = amScraping.wanlc + getCourierCost(amScraping) + getClosingFee(amScraping) + getNewCommission(amScraping,proposedSp) + getPackagingCost(amScraping) + getNewVat(amScraping,getVatRate(amScraping.item_id,amScraping.warehouseLocation,proposedSp),proposedSp) + getNewReturnCost(amScraping,proposedSp) + amScraping.otherCost
|
| 1396 |
margin = proposedSp - myCosts + amScraping.subsidy
|
1460 |
margin = proposedSp - myCosts + amScraping.subsidy
|
| 1397 |
print 'New margin for ',amScraping.item_id,' is ',margin
|
1461 |
print 'New margin for ',amScraping.item_id,' is ',margin
|
| 1398 |
return round(margin)
|
1462 |
return round(margin)
|
| 1399 |
|
1463 |
|
| 1400 |
def getVat(data):
|
1464 |
def getVat(data):
|
| Line 1919... |
Line 1983... |
| 1919 |
sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
1983 |
sheet.write(sheet_iterator, 44, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
| 1920 |
sheet.write(sheet_iterator, 45, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
|
1984 |
sheet.write(sheet_iterator, 45, getNewMargin(amScraping,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))
|
| 1921 |
sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
|
1985 |
sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
|
| 1922 |
sheet_iterator+=1
|
1986 |
sheet_iterator+=1
|
| 1923 |
|
1987 |
|
| - |
|
1988 |
exceptionCheapItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp)\
|
| - |
|
1989 |
.filter(or_(AmazonScrapingHistory.exceptionType==3,AmazonScrapingHistory.exceptionType==5)).all()
|
| - |
|
1990 |
|
| - |
|
1991 |
for exceptionCheapItem in exceptionCheapItems:
|
| - |
|
1992 |
amScraping = exceptionCheapItem[0]
|
| - |
|
1993 |
item = exceptionCheapItem[1]
|
| - |
|
1994 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
| - |
|
1995 |
if amScraping.warehouseLocation == 1:
|
| - |
|
1996 |
sku = 'FBA'+str(amScraping.item_id)
|
| - |
|
1997 |
loc = 'MUMBAI'
|
| - |
|
1998 |
else:
|
| - |
|
1999 |
sku = 'FBB'+str(amScraping.item_id)
|
| - |
|
2000 |
loc = 'BANGLORE'
|
| - |
|
2001 |
sheet.write(sheet_iterator, 1, sku)
|
| - |
|
2002 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| - |
|
2003 |
sheet.write(sheet_iterator, 3, loc)
|
| - |
|
2004 |
sheet.write(sheet_iterator, 4, item.brand)
|
| - |
|
2005 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
| - |
|
2006 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
| - |
|
2007 |
sheet.write(sheet_iterator, 7, item.weight)
|
| - |
|
2008 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
| - |
|
2009 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
| - |
|
2010 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| - |
|
2011 |
if amScraping.isPromotion:
|
| - |
|
2012 |
sheet.write(sheet_iterator, 11, "Yes")
|
| - |
|
2013 |
else:
|
| - |
|
2014 |
sheet.write(sheet_iterator, 11, "No")
|
| - |
|
2015 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| - |
|
2016 |
if amScraping.ourRank > 3:
|
| - |
|
2017 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| - |
|
2018 |
else:
|
| - |
|
2019 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| - |
|
2020 |
sheet.write(sheet_iterator, 14, 'Cheapest')
|
| - |
|
2021 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
| - |
|
2022 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
| - |
|
2023 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
| - |
|
2024 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
| - |
|
2025 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
| - |
|
2026 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
| - |
|
2027 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
| - |
|
2028 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
| - |
|
2029 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
| - |
|
2030 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
| - |
|
2031 |
sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
|
| - |
|
2032 |
sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
|
| - |
|
2033 |
sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
|
| - |
|
2034 |
sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
|
| - |
|
2035 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
| - |
|
2036 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
| - |
|
2037 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
| - |
|
2038 |
if amScraping.isPromotion:
|
| - |
|
2039 |
sheet.write(sheet_iterator, 32, getMsp(amScraping.item_id,amScraping.warehouseLocation))
|
| - |
|
2040 |
else:
|
| - |
|
2041 |
sheet.write(sheet_iterator, 32, 0.0)
|
| - |
|
2042 |
sheet.write(sheet_iterator, 33, amScraping.commission)
|
| - |
|
2043 |
sheet.write(sheet_iterator, 34, amScraping.competitorCommission)
|
| - |
|
2044 |
sheet.write(sheet_iterator, 35, amScraping.returnProvision)
|
| - |
|
2045 |
sheet.write(sheet_iterator, 36, amScraping.vatRate)
|
| - |
|
2046 |
sheet.write(sheet_iterator, 37, getMargin(amScraping))
|
| - |
|
2047 |
sheet.write(sheet_iterator, 38, amScraping.proposedSp)
|
| - |
|
2048 |
sheet.write(sheet_iterator, 39, amScraping.avgSale)
|
| - |
|
2049 |
try:
|
| - |
|
2050 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
| - |
|
2051 |
except:
|
| - |
|
2052 |
daysOfStock = float("inf")
|
| - |
|
2053 |
if str(daysOfStock)=='inf':
|
| - |
|
2054 |
sheet.write(sheet_iterator, 40, str(daysOfStock))
|
| - |
|
2055 |
else:
|
| - |
|
2056 |
sheet.write(sheet_iterator, 40, str(round(daysOfStock,1)))
|
| - |
|
2057 |
sheet.write(sheet_iterator, 41, getOosString(saleMap.get(sku)))
|
| - |
|
2058 |
sheet.write(sheet_iterator, 42, 'AUTO_INCREMENT_FAILED')
|
| - |
|
2059 |
if amScraping.exceptionType==3:
|
| - |
|
2060 |
sheet.write(sheet_iterator, 43, 'We are the only seller')
|
| - |
|
2061 |
else:
|
| - |
|
2062 |
sheet.write(sheet_iterator, 43, amScraping.reason)
|
| - |
|
2063 |
sheet.write(sheet_iterator, 46, getInventoryMovementStatus(amScraping))
|
| - |
|
2064 |
sheet_iterator+=1
|
| - |
|
2065 |
|
| - |
|
2066 |
|
| 1924 |
# sheet = wbk.add_sheet('Negative Margin')
|
2067 |
# sheet = wbk.add_sheet('Negative Margin')
|
| 1925 |
# xstr = lambda s: s or ""
|
2068 |
# xstr = lambda s: s or ""
|
| 1926 |
# heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
2069 |
# heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| 1927 |
#
|
2070 |
#
|
| 1928 |
# excel_integer_format = '0'
|
2071 |
# excel_integer_format = '0'
|
| Line 2049... |
Line 2192... |
| 2049 |
sheet.write(0, 4, "Brand", heading_xf)
|
2192 |
sheet.write(0, 4, "Brand", heading_xf)
|
| 2050 |
sheet.write(0, 5, "Category", heading_xf)
|
2193 |
sheet.write(0, 5, "Category", heading_xf)
|
| 2051 |
sheet.write(0, 6, "Product Name", heading_xf)
|
2194 |
sheet.write(0, 6, "Product Name", heading_xf)
|
| 2052 |
sheet.write(0, 7, "Selling Price", heading_xf)
|
2195 |
sheet.write(0, 7, "Selling Price", heading_xf)
|
| 2053 |
sheet.write(0, 8, "Promo Price", heading_xf)
|
2196 |
sheet.write(0, 8, "Promo Price", heading_xf)
|
| - |
|
2197 |
sheet.write(0, 9, "Inventory", heading_xf)
|
| - |
|
2198 |
sheet.write(0, 10, "Avg Sale", heading_xf)
|
| - |
|
2199 |
sheet.write(0, 11, "NOD", heading_xf)
|
| - |
|
2200 |
sheet.write(0, 12, "Sales History", heading_xf)
|
| - |
|
2201 |
sheet.write(0, 13, "Inventory Movement Status", heading_xf)
|
| 2054 |
sheet.write(0, 9, "Reason", heading_xf)
|
2202 |
sheet.write(0, 14, "Reason", heading_xf)
|
| 2055 |
|
2203 |
|
| 2056 |
sheet_iterator = 1
|
2204 |
sheet_iterator = 1
|
| 2057 |
amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
2205 |
exceptionListItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 2058 |
for amongCheapestItem in amongCheapestItems:
|
2206 |
for exceptionListItem in exceptionListItems:
|
| 2059 |
amScraping = amongCheapestItem[0]
|
2207 |
amScraping = exceptionListItem[0]
|
| - |
|
2208 |
if amScraping.exceptionType in (3,5):
|
| - |
|
2209 |
continue
|
| 2060 |
item = amongCheapestItem[1]
|
2210 |
item = exceptionListItem[1]
|
| 2061 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
2211 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
| 2062 |
if amScraping.warehouseLocation == 1:
|
2212 |
if amScraping.warehouseLocation == 1:
|
| 2063 |
sku = 'FBA'+str(amScraping.item_id)
|
2213 |
sku = 'FBA'+str(amScraping.item_id)
|
| 2064 |
loc = 'MUMBAI'
|
2214 |
loc = 'MUMBAI'
|
| 2065 |
else:
|
2215 |
else:
|
| Line 2071... |
Line 2221... |
| 2071 |
sheet.write(sheet_iterator, 4, item.brand)
|
2221 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 2072 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
2222 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
| 2073 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
2223 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
| 2074 |
sheet.write(sheet_iterator, 7, amScraping.ourSellingPrice)
|
2224 |
sheet.write(sheet_iterator, 7, amScraping.ourSellingPrice)
|
| 2075 |
sheet.write(sheet_iterator, 8, amScraping.promoPrice)
|
2225 |
sheet.write(sheet_iterator, 8, amScraping.promoPrice)
|
| - |
|
2226 |
sheet.write(sheet_iterator, 9, amScraping.ourInventory)
|
| - |
|
2227 |
sheet.write(sheet_iterator, 10, amScraping.avgSale)
|
| - |
|
2228 |
try:
|
| - |
|
2229 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
| - |
|
2230 |
except:
|
| - |
|
2231 |
daysOfStock = float("inf")
|
| - |
|
2232 |
if str(daysOfStock)=='inf':
|
| - |
|
2233 |
sheet.write(sheet_iterator, 11, str(daysOfStock))
|
| - |
|
2234 |
else:
|
| - |
|
2235 |
sheet.write(sheet_iterator, 11, str(round(daysOfStock,1)))
|
| - |
|
2236 |
sheet.write(sheet_iterator, 12, getOosString(saleMap.get(sku)))
|
| - |
|
2237 |
sheet.write(sheet_iterator, 13, getInventoryMovementStatus(amScraping))
|
| 2076 |
sheet.write(sheet_iterator, 9, amScraping.reason)
|
2238 |
sheet.write(sheet_iterator, 14, amScraping.reason)
|
| 2077 |
sheet_iterator+=1
|
2239 |
sheet_iterator+=1
|
| 2078 |
|
2240 |
|
| 2079 |
|
2241 |
|
| 2080 |
if (runType in ('FULL','FULL-OTHER')):
|
2242 |
if (runType in ('FULL','FULL-OTHER')):
|
| 2081 |
sheet = wbk.add_sheet('Auto Favorites')
|
2243 |
sheet = wbk.add_sheet('Auto Favorites')
|
| Line 2138... |
Line 2300... |
| 2138 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
2300 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| 2139 |
print "Successfully sent email"
|
2301 |
print "Successfully sent email"
|
| 2140 |
except:
|
2302 |
except:
|
| 2141 |
print "Error: unable to send email."
|
2303 |
print "Error: unable to send email."
|
| 2142 |
|
2304 |
|
| 2143 |
def getNewVatRate(item_id,state,price):
|
2305 |
def getVatRate(item_id,state,price):
|
| 2144 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==item_id, ItemVatMaster.stateId==state)).first()
|
2306 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==item_id, ItemVatMaster.stateId==state)).first()
|
| 2145 |
if itemVatMaster is None:
|
2307 |
if itemVatMaster is None:
|
| 2146 |
d_item = Item.query.filter_by(id=item_id).first()
|
2308 |
d_item = Item.query.filter_by(id=item_id).first()
|
| 2147 |
if d_item is None:
|
2309 |
if d_item is None:
|
| 2148 |
raise
|
2310 |
raise
|