| 12363 |
kshitij.so |
1 |
from elixir import *
|
| 12418 |
kshitij.so |
2 |
from sqlalchemy.sql import or_ ,func, asc, desc, and_
|
| 12363 |
kshitij.so |
3 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
4 |
from shop2020.model.v1.catalog.impl import DataService
|
| 12364 |
kshitij.so |
5 |
from shop2020.model.v1.catalog.impl.DataService import Amazonlisted, Item, \
|
| 12418 |
kshitij.so |
6 |
Category, SourcePercentageMaster,SourceCategoryPercentage, SourceItemPercentage, AmazonPromotion, AmazonScrapingHistory, \
|
|
|
7 |
ItemVatMaster, CategoryVatMaster
|
| 12363 |
kshitij.so |
8 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
| 12430 |
kshitij.so |
9 |
from shop2020.thriftpy.model.v1.catalog.ttypes import CompetitionCategory, \
|
| 12363 |
kshitij.so |
10 |
Decision, RunType, AmazonPromotionType
|
| 12430 |
kshitij.so |
11 |
from shop2020.model.v1.catalog.script import AmazonAsyncScraper
|
| 12363 |
kshitij.so |
12 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
13 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 12452 |
kshitij.so |
14 |
import time
|
|
|
15 |
from time import sleep
|
| 12363 |
kshitij.so |
16 |
from datetime import date, datetime, timedelta
|
|
|
17 |
import math
|
|
|
18 |
import simplejson as json
|
|
|
19 |
import xlwt
|
|
|
20 |
import optparse
|
|
|
21 |
import sys
|
| 12430 |
kshitij.so |
22 |
from operator import itemgetter
|
| 12489 |
kshitij.so |
23 |
from shop2020.utils import EmailAttachmentSender
|
|
|
24 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
|
|
25 |
import smtplib
|
|
|
26 |
from multiprocessing import Process
|
|
|
27 |
from email.mime.text import MIMEText
|
|
|
28 |
import email
|
|
|
29 |
from email.mime.multipart import MIMEMultipart
|
|
|
30 |
import email.encoders
|
| 12363 |
kshitij.so |
31 |
|
|
|
32 |
|
|
|
33 |
config_client = ConfigClient()
|
|
|
34 |
host = config_client.get_property('staging_hostname')
|
|
|
35 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
|
|
36 |
|
|
|
37 |
amazonAsinPrice={}
|
| 12432 |
kshitij.so |
38 |
amazonLongTermActivePromotions = {}
|
|
|
39 |
amazonShortTermActivePromotions = {}
|
| 12363 |
kshitij.so |
40 |
saleMap = {}
|
| 12526 |
anikendra |
41 |
categoryMap = {}
|
| 12363 |
kshitij.so |
42 |
DataService.initialize(db_hostname=host)
|
|
|
43 |
|
| 12430 |
kshitij.so |
44 |
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
| 12363 |
kshitij.so |
45 |
|
|
|
46 |
class __AmazonItemInfo:
|
|
|
47 |
|
| 12447 |
kshitij.so |
48 |
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):
|
| 12382 |
kshitij.so |
49 |
self.asin = asin
|
| 12363 |
kshitij.so |
50 |
self.nlc = nlc
|
|
|
51 |
self.courierCost = courierCost
|
|
|
52 |
self.sku = sku
|
|
|
53 |
self.product_group = product_group
|
|
|
54 |
self.brand = brand
|
|
|
55 |
self.model_name = model_name
|
|
|
56 |
self.model_number = model_number
|
|
|
57 |
self.color = color
|
|
|
58 |
self.weight = weight
|
|
|
59 |
self.parent_category = parent_category
|
|
|
60 |
self.risky = risky
|
|
|
61 |
self.vatRate = vatRate
|
|
|
62 |
self.runType = runType
|
|
|
63 |
self.parent_category_name = parent_category_name
|
|
|
64 |
self.sourcePercentage = sourcePercentage
|
|
|
65 |
self.ourInventory = ourInventory
|
|
|
66 |
self.state_id = state_id
|
| 12447 |
kshitij.so |
67 |
self.otherCost = otherCost
|
| 12363 |
kshitij.so |
68 |
|
|
|
69 |
class __AmazonDetails:
|
| 12430 |
kshitij.so |
70 |
def __init__(self, sku, ourSp, ourRank, lowestSellerName,lowestSellerSp,secondLowestSellerName, secondLowestSellerSp, thirdLowestSellerName, thirdLowestSellerSp, totalSeller, multipleListings, \
|
|
|
71 |
promoPrice, isPromotion, lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
|
| 12597 |
kshitij.so |
72 |
thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, \
|
|
|
73 |
isLowestMfnIgnored, isLowestMfn, isLowestFba, competitivePrice):
|
| 12363 |
kshitij.so |
74 |
self.sku =sku
|
|
|
75 |
self.ourSp = ourSp
|
|
|
76 |
self.ourRank = ourRank
|
|
|
77 |
self.lowestSellerName = lowestSellerName
|
|
|
78 |
self.lowestSellerSp = lowestSellerSp
|
|
|
79 |
self.secondLowestSellerName = secondLowestSellerName
|
|
|
80 |
self.secondLowestSellerSp = secondLowestSellerSp
|
|
|
81 |
self.thirdLowestSellerName = thirdLowestSellerName
|
|
|
82 |
self.thirdLowestSellerSp = thirdLowestSellerSp
|
|
|
83 |
self.totalSeller = totalSeller
|
| 12430 |
kshitij.so |
84 |
self.multipleListings = multipleListings
|
|
|
85 |
self.promoPrice = promoPrice
|
|
|
86 |
self.isPromotion = isPromotion
|
|
|
87 |
self.lowestSellerShippingTime =lowestSellerShippingTime
|
|
|
88 |
self.lowestSellerRating = lowestSellerRating
|
|
|
89 |
self.secondLowestSellerShippingTime = secondLowestSellerShippingTime
|
|
|
90 |
self.secondLowestSellerRating = secondLowestSellerRating
|
|
|
91 |
self.thirdLowestSellerShippingTime= thirdLowestSellerShippingTime
|
|
|
92 |
self.thirdLowestSellerRating = thirdLowestSellerRating
|
|
|
93 |
self.lowestSellerType = lowestSellerType
|
|
|
94 |
self.secondLowestSellerType = secondLowestSellerType
|
| 12447 |
kshitij.so |
95 |
self.thirdLowestSellerType = thirdLowestSellerType
|
| 12597 |
kshitij.so |
96 |
self.lowestMfnIgnoredOffer = lowestMfnIgnoredOffer
|
|
|
97 |
self.isLowestMfnIgnored = isLowestMfnIgnored
|
|
|
98 |
self.lowestMfnOffer = lowestMfnOffer
|
|
|
99 |
self.isLowestMfn = isLowestMfn
|
|
|
100 |
self.lowestFbaOffer = lowestFbaOffer
|
|
|
101 |
self.isLowestFba = isLowestFba
|
|
|
102 |
self.competitivePrice = competitivePrice
|
| 12430 |
kshitij.so |
103 |
|
| 12363 |
kshitij.so |
104 |
|
|
|
105 |
class __AmazonPricing:
|
|
|
106 |
|
| 12432 |
kshitij.so |
107 |
def __init__(self, ourSp, lowestPossibleSp):
|
| 12363 |
kshitij.so |
108 |
self.ourSp = ourSp
|
|
|
109 |
self.lowestPossibleSp = lowestPossibleSp
|
|
|
110 |
|
| 12432 |
kshitij.so |
111 |
class __Promotion:
|
| 12433 |
kshitij.so |
112 |
def __init__(self, promoPrice, subsidy, promotionType,expiryDate):
|
| 12432 |
kshitij.so |
113 |
self.promoPrice = promoPrice
|
|
|
114 |
self.subsidy = subsidy
|
|
|
115 |
self.promotionType = promotionType
|
| 12433 |
kshitij.so |
116 |
self.expiryDate = expiryDate
|
| 12432 |
kshitij.so |
117 |
|
| 12363 |
kshitij.so |
118 |
|
| 12432 |
kshitij.so |
119 |
|
| 12396 |
kshitij.so |
120 |
def fetchItemsForAutoDecrease(time):
|
|
|
121 |
successfulAutoDecrease = []
|
|
|
122 |
autoDecrementItems = session.query(AmazonScrapingHistory).join((Amazonlisted,AmazonScrapingHistory.item_id==Amazonlisted.itemId))\
|
|
|
123 |
.filter(AmazonScrapingHistory.timestamp==time).filter(or_(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE,AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE, AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE ))\
|
|
|
124 |
.filter(Amazonlisted.autoDecrement==True).all()
|
| 12477 |
kshitij.so |
125 |
print len(autoDecrementItems)
|
| 12396 |
kshitij.so |
126 |
for autoDecrementItem in autoDecrementItems:
|
|
|
127 |
if autoDecrementItem.warehouseLocation == 1:
|
|
|
128 |
sku = 'FBA'+str(autoDecrementItem.item_id)
|
|
|
129 |
else:
|
|
|
130 |
sku = 'FBB'+str(autoDecrementItem.item_id)
|
| 12432 |
kshitij.so |
131 |
if amazonShortTermActivePromotions.has_key(sku):
|
| 12396 |
kshitij.so |
132 |
markReasonForItem(autoDecrementItem,'Item in short term promotion',Decision.AUTO_DECREMENT_FAILED)
|
|
|
133 |
continue
|
| 12484 |
kshitij.so |
134 |
if math.ceil(autoDecrementItem.proposedSp) >= autoDecrementItem.promoPrice:
|
| 12396 |
kshitij.so |
135 |
markReasonForItem(autoDecrementItem,'Proposed SP greater than or equal to current SP',Decision.AUTO_DECREMENT_FAILED)
|
|
|
136 |
continue
|
| 12479 |
kshitij.so |
137 |
if autoDecrementItem.proposedSp < autoDecrementItem.lowestPossibleSp:
|
| 12396 |
kshitij.so |
138 |
markReasonForItem(autoDecrementItem,'Proposed SP less than lowest possible SP',Decision.AUTO_DECREMENT_FAILED)
|
|
|
139 |
continue
|
|
|
140 |
try:
|
|
|
141 |
daysOfStock = (float(autoDecrementItem.ourInventory))/autoDecrementItem.avgSale
|
|
|
142 |
except:
|
|
|
143 |
daysOfStock = float("inf")
|
|
|
144 |
if autoDecrementItem.competitiveCategory == CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE:
|
|
|
145 |
if daysOfStock < 20:
|
|
|
146 |
markReasonForItem(autoDecrementItem,'Days of stock less than 20',Decision.AUTO_DECREMENT_FAILED)
|
| 12433 |
kshitij.so |
147 |
continue
|
| 12396 |
kshitij.so |
148 |
|
| 12433 |
kshitij.so |
149 |
if autoDecrementItem.competitiveCategory == CompetitionCategory.COMPETITIVE and not autoDecrementItem.isPromotion:
|
| 12396 |
kshitij.so |
150 |
if autoDecrementItem.parentCategoryId in [10006,10009,11001]:
|
| 12433 |
kshitij.so |
151 |
if daysOfStock < 1 :
|
| 12396 |
kshitij.so |
152 |
markReasonForItem(autoDecrementItem,'Days of stock less than 1',Decision.AUTO_DECREMENT_FAILED)
|
| 12433 |
kshitij.so |
153 |
continue
|
|
|
154 |
|
| 12396 |
kshitij.so |
155 |
else:
|
|
|
156 |
if daysOfStock < 3:
|
|
|
157 |
markReasonForItem(autoDecrementItem,'Days of stock less than 3',Decision.AUTO_DECREMENT_FAILED)
|
| 12433 |
kshitij.so |
158 |
continue
|
|
|
159 |
|
|
|
160 |
if autoDecrementItem.competitiveCategory == CompetitionCategory.COMPETITIVE and autoDecrementItem.isPromotion:
|
|
|
161 |
if autoDecrementItem.parentCategoryId in [10006,10009,11001]:
|
|
|
162 |
if (amazonLongTermActivePromotions.get(sku).expiryDate - datetime.now()).days >2 and daysOfStock < 1 :
|
|
|
163 |
markReasonForItem(autoDecrementItem,'Promo Item, expiry after 2 days or not enough stock',Decision.AUTO_DECREMENT_FAILED)
|
|
|
164 |
continue
|
|
|
165 |
|
|
|
166 |
else:
|
|
|
167 |
if (amazonLongTermActivePromotions.get(sku).expiryDate - datetime.now()).days >2 and daysOfStock < 3:
|
|
|
168 |
markReasonForItem(autoDecrementItem,'Promo Item, expiry after 2 days or not enough stock',Decision.AUTO_DECREMENT_FAILED)
|
|
|
169 |
continue
|
| 12396 |
kshitij.so |
170 |
|
|
|
171 |
autoDecrementItem.ourEnoughStock=True
|
|
|
172 |
autoDecrementItem.decision = Decision.AUTO_DECREMENT_SUCCESS
|
|
|
173 |
autoDecrementItem.reason = 'All conditions for auto decrement true'
|
|
|
174 |
successfulAutoDecrease.append(autoDecrementItem)
|
|
|
175 |
session.commit()
|
|
|
176 |
return successfulAutoDecrease
|
|
|
177 |
|
|
|
178 |
def fetchItemsForAutoIncrease(time):
|
|
|
179 |
successfulAutoIncrease = []
|
|
|
180 |
autoIncrementItems = session.query(AmazonScrapingHistory).join((Amazonlisted,AmazonScrapingHistory.item_id==Amazonlisted.itemId))\
|
|
|
181 |
.filter(AmazonScrapingHistory.timestamp==time).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX)\
|
|
|
182 |
.filter(Amazonlisted.autoIncrement==True).all()
|
|
|
183 |
transaction_client = TransactionClient().get_client()
|
| 12477 |
kshitij.so |
184 |
print len(autoIncrementItems)
|
| 12396 |
kshitij.so |
185 |
for autoIncrementItem in autoIncrementItems:
|
|
|
186 |
if autoIncrementItem.warehouseLocation == 1:
|
|
|
187 |
sku = 'FBA'+str(autoIncrementItem.item_id)
|
|
|
188 |
else:
|
|
|
189 |
sku = 'FBB'+str(autoIncrementItem.item_id)
|
| 12432 |
kshitij.so |
190 |
if amazonShortTermActivePromotions.has_key(sku):
|
| 12396 |
kshitij.so |
191 |
markReasonForItem(autoIncrementItem,'Item in short term promotion',Decision.AUTO_INCREMENT_FAILED)
|
|
|
192 |
continue
|
|
|
193 |
if autoIncrementItem.totalSeller==1 and autoIncrementItem.ourRank==1:
|
|
|
194 |
markReasonForItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
|
|
|
195 |
continue
|
| 12484 |
kshitij.so |
196 |
if autoIncrementItem.proposedSp <= autoIncrementItem.promoPrice:
|
| 12396 |
kshitij.so |
197 |
markReasonForItem(autoIncrementItem,'Proposed SP less than current SP',Decision.AUTO_INCREMENT_FAILED)
|
|
|
198 |
continue
|
| 12484 |
kshitij.so |
199 |
if autoIncrementItem.proposedSp >=10000 and autoIncrementItem.promoPrice<10000:
|
| 12396 |
kshitij.so |
200 |
markReasonForItem(autoIncrementItem,'Proposed SP is greater than 10,000 and current sp is less than 10,000',Decision.AUTO_INCREMENT_FAILED)
|
|
|
201 |
continue
|
|
|
202 |
|
| 12479 |
kshitij.so |
203 |
if autoIncrementItem.isPromotion and (math.ceil(autoIncrementItem.promoPrice+max(10,.01*autoIncrementItem.promoPrice)) > (amazonLongTermActivePromotions.get(sku)).promoPrice):
|
| 12447 |
kshitij.so |
204 |
markReasonForItem(autoIncrementItem,'Proposed SP cant be greater than promo price',Decision.AUTO_INCREMENT_FAILED)
|
|
|
205 |
continue
|
|
|
206 |
|
|
|
207 |
|
| 12396 |
kshitij.so |
208 |
if autoIncrementItem.avgSale==0:
|
|
|
209 |
markReasonForItem(autoIncrementItem,'Avg sale is 0',Decision.AUTO_INCREMENT_FAILED)
|
|
|
210 |
continue
|
|
|
211 |
|
|
|
212 |
daysOfStock = (float(autoIncrementItem.ourInventory))/autoIncrementItem.avgSale
|
|
|
213 |
if daysOfStock > 5:
|
|
|
214 |
markReasonForItem(autoIncrementItem,'Days of stock greater than 5',Decision.AUTO_INCREMENT_FAILED)
|
|
|
215 |
continue
|
| 12484 |
kshitij.so |
216 |
if autoIncrementItem.isPromotion:
|
|
|
217 |
antecedentPrice = session.query(AmazonScrapingHistory.promoPrice).filter(AmazonScrapingHistory.item_id==autoIncrementItem.item_id).filter(AmazonScrapingHistory.timestamp>time-timedelta(days=1)).order_by(asc(AmazonScrapingHistory.timestamp)).first()
|
| 12512 |
kshitij.so |
218 |
print "antecedentPrice ",antecedentPrice
|
| 12514 |
kshitij.so |
219 |
try:
|
|
|
220 |
if antecedentPrice[0] is not None:
|
|
|
221 |
if float(math.ceil(autoIncrementItem.promoPrice+max(10,.01*autoIncrementItem.promoPrice))-math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0])))/math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0]))>.02:
|
|
|
222 |
markReasonForItem(autoIncrementItem,'Maximum price increase in last 24 hours should be 2%',Decision.AUTO_INCREMENT_FAILED)
|
|
|
223 |
continue
|
|
|
224 |
except:
|
|
|
225 |
if antecedentPrice is not None:
|
|
|
226 |
if float(math.ceil(autoIncrementItem.promoPrice+max(10,.01*autoIncrementItem.promoPrice))-math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0])))/math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0]))>.02:
|
|
|
227 |
markReasonForItem(autoIncrementItem,'Maximum price increase in last 24 hours should be 2%',Decision.AUTO_INCREMENT_FAILED)
|
|
|
228 |
continue
|
| 12484 |
kshitij.so |
229 |
else:
|
|
|
230 |
antecedentPrice = session.query(AmazonScrapingHistory.ourSellingPrice).filter(AmazonScrapingHistory.item_id==autoIncrementItem.item_id).filter(AmazonScrapingHistory.timestamp>time-timedelta(days=1)).order_by(asc(AmazonScrapingHistory.timestamp)).first()
|
| 12512 |
kshitij.so |
231 |
print "antecedentPrice else ",antecedentPrice
|
| 12526 |
anikendra |
232 |
if antecedentPrice is not None and antecedentPrice[0] is not None:
|
| 12484 |
kshitij.so |
233 |
if float(math.ceil(autoIncrementItem.ourSellingPrice+max(10,.01*autoIncrementItem.ourSellingPrice))-math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0])))/math.ceil(antecedentPrice[0]+max(10,.01*antecedentPrice[0]))>.02:
|
|
|
234 |
markReasonForItem(autoIncrementItem,'Maximum price increase in last 24 hours should be 2%',Decision.AUTO_INCREMENT_FAILED)
|
|
|
235 |
continue
|
| 12396 |
kshitij.so |
236 |
fbaSaleSnapshot = transaction_client.getAmazonFbaSalesLatestSnapshotForItemLocationWise(autoIncrementItem.item_id,autoIncrementItem.warehouseLocation)
|
| 12480 |
kshitij.so |
237 |
if getLastDaySale(fbaSaleSnapshot)<=2:
|
| 12396 |
kshitij.so |
238 |
markReasonForItem(autoIncrementItem,'Last day sale is less than 3',Decision.AUTO_INCREMENT_FAILED)
|
|
|
239 |
continue
|
|
|
240 |
|
|
|
241 |
autoIncrementItem.ourEnoughStock = False
|
|
|
242 |
autoIncrementItem.decision = Decision.AUTO_INCREMENT_SUCCESS
|
|
|
243 |
autoIncrementItem.reason = 'All conditions for auto increment true'
|
|
|
244 |
successfulAutoIncrease.append(autoIncrementItem)
|
|
|
245 |
session.commit()
|
|
|
246 |
return successfulAutoIncrease
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
def markReasonForItem(amHistory,reason,decision):
|
|
|
250 |
amHistory.decision = decision
|
|
|
251 |
amHistory.reason = reason
|
|
|
252 |
|
| 12424 |
kshitij.so |
253 |
def calculateAverageSale(sku):
|
|
|
254 |
count,sale = 0,0
|
|
|
255 |
oosStatus = saleMap.get(sku)
|
|
|
256 |
for obj in oosStatus:
|
|
|
257 |
if not obj.isOutOfStock:
|
|
|
258 |
count+=1
|
|
|
259 |
sale = sale+obj.totalOrderCount
|
|
|
260 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
|
|
261 |
return round(avgSalePerDay,2)
|
|
|
262 |
|
|
|
263 |
|
| 12396 |
kshitij.so |
264 |
def getOosString(oosStatus):
|
|
|
265 |
lastNdaySale=""
|
|
|
266 |
for obj in oosStatus:
|
| 12423 |
kshitij.so |
267 |
if obj.isOutOfStock:
|
| 12396 |
kshitij.so |
268 |
lastNdaySale += "X-"
|
|
|
269 |
else:
|
| 12426 |
kshitij.so |
270 |
lastNdaySale += str(obj.totalOrderCount) + "-"
|
| 12396 |
kshitij.so |
271 |
return lastNdaySale[:-1]
|
|
|
272 |
|
|
|
273 |
def getLastDaySale(fbaSaleSnapshot):
|
|
|
274 |
if fbaSaleSnapshot.item_id==0:
|
|
|
275 |
return 0
|
|
|
276 |
else:
|
| 12423 |
kshitij.so |
277 |
return fbaSaleSnapshot.totalOrderCount
|
| 12597 |
kshitij.so |
278 |
|
|
|
279 |
def getNoOfDaysInStock(oosStatus):
|
|
|
280 |
inStockCount = 0
|
|
|
281 |
for obj in oosStatus:
|
|
|
282 |
if not obj.isOutOfStock:
|
|
|
283 |
inStockCount+=1
|
|
|
284 |
return inStockCount
|
|
|
285 |
|
|
|
286 |
def getCheapestMfnCount(timestamp,itemId):
|
|
|
287 |
query = session.query(func.count(AmazonScrapingHistory.cheapestMfnCount)).filter(AmazonScrapingHistory.item_id==itemId).filter(AmazonScrapingHistory.timestamp>=timestamp-timedelta(days=5))
|
|
|
288 |
cheapestCount = query.filter(AmazonScrapingHistory.cheapestMfnCount==True).scalar()
|
|
|
289 |
total = query.scalar()
|
|
|
290 |
if total==0:
|
|
|
291 |
return 0
|
|
|
292 |
return float(cheapestCount)/total
|
|
|
293 |
|
|
|
294 |
|
| 12396 |
kshitij.so |
295 |
|
| 12430 |
kshitij.so |
296 |
#def syncAsin():
|
|
|
297 |
## notListedOnAmazon = []
|
|
|
298 |
## diffAsins = []
|
|
|
299 |
## login_url = "https://sellercentral.amazon.in/gp/homepage.html"
|
|
|
300 |
## br = SellerCentralInventoryReport.login(login_url)
|
|
|
301 |
## report_url = "https://sellercentral.amazon.in/gp/upload-download-utils/requestReport.html?type=OpenListingReport&marketplaceID=44571&Request+Report="
|
|
|
302 |
## br = SellerCentralInventoryReport.requestReport(br,report_url)
|
|
|
303 |
## status_url="https://sellercentral.amazon.in/gp/upload-download-utils/reportStatusData.html"
|
|
|
304 |
## br, page = SellerCentralInventoryReport.checkStatus(br,status_url)
|
|
|
305 |
## br, batchId = SellerCentralInventoryReport.getReportBatchId(br,page)
|
|
|
306 |
## print "*********************************"
|
|
|
307 |
## print "Batch Id for request is ",batchId
|
|
|
308 |
## print "*********************************"
|
|
|
309 |
## ready = False
|
|
|
310 |
## retryCount = 0
|
|
|
311 |
## while not ready:
|
|
|
312 |
## if retryCount == 10:
|
|
|
313 |
## print "File not available for download after multiple retries"
|
|
|
314 |
## sys.exit(1)
|
|
|
315 |
## br, download_link = SellerCentralInventoryReport.downloadReport(br,batchId,status_url)
|
|
|
316 |
## if download_link is not None:
|
|
|
317 |
## ready= True
|
|
|
318 |
## continue
|
|
|
319 |
## print "File not ready for download yet.Will try again after 30 seconds."
|
|
|
320 |
## retryCount+=1
|
|
|
321 |
## time.sleep(30)
|
|
|
322 |
## fPath = SellerCentralInventoryReport.fetchFile(download_link['href'],br,batchId)
|
|
|
323 |
# fPath = "/tmp/9940651090.txt"
|
|
|
324 |
# global amazonAsinPrice
|
|
|
325 |
# for line in open(fPath):
|
|
|
326 |
# l = line.split('\t')
|
|
|
327 |
# if (str(l[0]).startswith('FBA') or str(l[0]).startswith('FBB')):
|
|
|
328 |
# obj = __AmazonAsinPrice(l[1],l[2])
|
|
|
329 |
# amazonAsinPrice[l[0]] = obj
|
|
|
330 |
##Can be used to sync asins, not doing due to multiple asins corresponding to one itemId
|
|
|
331 |
## systemAsins = session.query(Item,Amazonlisted).join((Amazonlisted,Item.id==Amazonlisted.itemId)).all()
|
|
|
332 |
## for systemAsin in systemAsins:
|
|
|
333 |
## item = systemAsin[0]
|
|
|
334 |
## amListed = systemAsin[1]
|
|
|
335 |
## if amazonAsinPrice.get('FBA'+str(item.id)) is None:
|
|
|
336 |
## temp=[]
|
|
|
337 |
## temp.append(item)
|
|
|
338 |
## temp.append(amListed)
|
|
|
339 |
## notListedOnAmazon.append(temp)
|
|
|
340 |
## continue
|
|
|
341 |
## else:
|
|
|
342 |
## temp=[]
|
|
|
343 |
## temp.append(item)
|
|
|
344 |
## temp.append(amListed)
|
|
|
345 |
## if item.asin!=((amazonAsinPrice.get('FBA'+str(item.id))).asin).strip():
|
|
|
346 |
## diffAsins.append(temp)
|
|
|
347 |
## continue
|
|
|
348 |
##
|
|
|
349 |
## for diffAsin in diffAsins:
|
|
|
350 |
## item = diffAsin[0]
|
|
|
351 |
## amListed = diffAsin[1]
|
|
|
352 |
## item.asin = ((amazonAsinPrice.get('FBA'+str(item.id))).asin).strip()
|
|
|
353 |
## amListed.asin = ((amazonAsinPrice.get('FBA'+str(item.id))).asin).strip()
|
|
|
354 |
## session.commit()
|
|
|
355 |
## session.close()
|
| 12363 |
kshitij.so |
356 |
|
|
|
357 |
def fetchFbaSale():
|
|
|
358 |
global saleMap
|
|
|
359 |
transaction_client = TransactionClient().get_client()
|
|
|
360 |
fbaSaleSnapshot = transaction_client.getAmazonFbaSalesSnapshotForDays(4)
|
|
|
361 |
for saleSnapshot in fbaSaleSnapshot:
|
|
|
362 |
if saleSnapshot.fcLocation == 0:
|
|
|
363 |
if saleMap.has_key('FBA'+str(saleSnapshot.item_id)):
|
|
|
364 |
temp = []
|
| 12367 |
kshitij.so |
365 |
val = saleMap.get('FBA'+str(saleSnapshot.item_id))
|
|
|
366 |
for l in val:
|
| 12363 |
kshitij.so |
367 |
temp.append(l)
|
|
|
368 |
temp.append(saleSnapshot)
|
| 12366 |
kshitij.so |
369 |
saleMap['FBA'+str(saleSnapshot.item_id)]=temp
|
| 12363 |
kshitij.so |
370 |
else:
|
| 12368 |
kshitij.so |
371 |
temp = []
|
|
|
372 |
temp.append(saleSnapshot)
|
|
|
373 |
saleMap['FBA'+str(saleSnapshot.item_id)] = temp
|
| 12363 |
kshitij.so |
374 |
else:
|
|
|
375 |
if saleMap.has_key('FBB'+str(saleSnapshot.item_id)):
|
|
|
376 |
temp = []
|
| 12367 |
kshitij.so |
377 |
val = saleMap.get('FBB'+str(saleSnapshot.item_id))
|
|
|
378 |
for l in val:
|
| 12363 |
kshitij.so |
379 |
temp.append(l)
|
| 12368 |
kshitij.so |
380 |
saleMap['FBB'+str(saleSnapshot.item_id)]=temp
|
| 12363 |
kshitij.so |
381 |
temp.append(saleSnapshot)
|
|
|
382 |
else:
|
| 12368 |
kshitij.so |
383 |
temp = []
|
|
|
384 |
temp.append(saleSnapshot)
|
|
|
385 |
saleMap['FBB'+str(saleSnapshot.item_id)] = temp
|
| 12363 |
kshitij.so |
386 |
|
| 12424 |
kshitij.so |
387 |
|
| 12363 |
kshitij.so |
388 |
def computeCourierCost(weight):
|
| 12378 |
kshitij.so |
389 |
try:
|
|
|
390 |
cCost = 10.0;
|
|
|
391 |
slabs = int((weight*1000)/500-.001)
|
|
|
392 |
for slab in range(0,slabs):
|
|
|
393 |
cCost = cCost + 10.0;
|
|
|
394 |
return cCost;
|
|
|
395 |
except:
|
|
|
396 |
return 10.0
|
| 12363 |
kshitij.so |
397 |
|
|
|
398 |
|
|
|
399 |
def populateStuff(time,runType):
|
|
|
400 |
global amazonLongTermActivePromotions
|
| 12396 |
kshitij.so |
401 |
global amazonShortTermActivePromotions
|
| 12363 |
kshitij.so |
402 |
itemInfo = []
|
|
|
403 |
inventory_client = InventoryClient().get_client()
|
|
|
404 |
fbaAvailableInventorySnapshot = inventory_client.getAllAvailableAmazonFbaItemInventory()
|
| 12489 |
kshitij.so |
405 |
if runType=='FAVOURITE':
|
|
|
406 |
favourites = session.query(Amazonlisted.itemId).filter(or_(Amazonlisted.autoFavourite==True, Amazonlisted.manualFavourite==True)).all()
|
| 12363 |
kshitij.so |
407 |
for fbaInventoryItem in fbaAvailableInventorySnapshot:
|
| 12489 |
kshitij.so |
408 |
if runType=='FAVOURITE':
|
|
|
409 |
if not (fbaInventoryItem.item_id in favourites):
|
|
|
410 |
continue
|
| 12363 |
kshitij.so |
411 |
d_amazon_listed = Amazonlisted.get_by(itemId=fbaInventoryItem.item_id)
|
|
|
412 |
if d_amazon_listed is None:
|
|
|
413 |
continue
|
|
|
414 |
if d_amazon_listed.overrrideWanlc:
|
|
|
415 |
wanlc = d_amazon_listed.exceptionalWanlc
|
| 12507 |
kshitij.so |
416 |
if wanlc is None:
|
|
|
417 |
wanlc = 0.0
|
| 12363 |
kshitij.so |
418 |
else:
|
|
|
419 |
wanlc = inventory_client.getWanNlcForSource(fbaInventoryItem.item_id,OrderSource.AMAZON)
|
|
|
420 |
it = Item.query.filter_by(id=fbaInventoryItem.item_id).one()
|
|
|
421 |
category = Category.query.filter_by(id=it.category).one()
|
|
|
422 |
parent_category = Category.query.filter_by(id=category.parent_category_id).first()
|
| 12489 |
kshitij.so |
423 |
sourcePercentage = None
|
|
|
424 |
sip = SourceItemPercentage.query.filter(SourceItemPercentage.item_id==it.id).filter(SourceItemPercentage.source==OrderSource.AMAZON).filter(SourceItemPercentage.startDate<=time).filter(SourceItemPercentage.expiryDate>=time).first()
|
|
|
425 |
if sip is not None:
|
|
|
426 |
sourcePercentage = sip
|
| 12363 |
kshitij.so |
427 |
else:
|
| 12489 |
kshitij.so |
428 |
scp = SourceCategoryPercentage.query.filter(SourceCategoryPercentage.category_id==it.category).filter(SourceCategoryPercentage.source==OrderSource.AMAZON).filter(SourceCategoryPercentage.startDate<=time).filter(SourceCategoryPercentage.expiryDate>=time).first()
|
|
|
429 |
if scp is not None:
|
|
|
430 |
sourcePercentage = scp
|
|
|
431 |
else:
|
|
|
432 |
spm = SourcePercentageMaster.get_by(source=OrderSource.AMAZON)
|
|
|
433 |
sourcePercentage = spm
|
| 12375 |
kshitij.so |
434 |
if fbaInventoryItem.location==0:
|
| 12377 |
kshitij.so |
435 |
sku = 'FBA'+str(fbaInventoryItem.item_id)
|
| 12363 |
kshitij.so |
436 |
state_id = 1
|
| 12375 |
kshitij.so |
437 |
elif fbaInventoryItem.location==1:
|
| 12377 |
kshitij.so |
438 |
sku = 'FBB'+str(fbaInventoryItem.item_id)
|
| 12363 |
kshitij.so |
439 |
state_id = 2
|
|
|
440 |
else:
|
|
|
441 |
continue
|
|
|
442 |
cc = computeCourierCost(it.weight)
|
| 12379 |
kshitij.so |
443 |
|
| 12447 |
kshitij.so |
444 |
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)
|
| 12363 |
kshitij.so |
445 |
itemInfo.append(amazonItemInfo)
|
| 12556 |
anikendra |
446 |
#amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
|
|
|
447 |
#.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
|
| 12363 |
kshitij.so |
448 |
amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.LONGTERM).filter(AmazonPromotion.promotionActive==True) \
|
| 12556 |
anikendra |
449 |
.order_by(desc(AmazonPromotion.addedOn)).all()
|
| 12363 |
kshitij.so |
450 |
for amPromotion in amPromotions:
|
| 12606 |
kshitij.so |
451 |
if amazonLongTermActivePromotions.has_key(amPromotion.sku):
|
|
|
452 |
continue
|
| 12433 |
kshitij.so |
453 |
amazonLongTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
|
| 12556 |
anikendra |
454 |
#amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.SHORTTERM).filter(AmazonPromotion.promotionActive==True) \
|
|
|
455 |
#.group_by(AmazonPromotion.sku).order_by(desc(AmazonPromotion.addedOn)).all()
|
| 12396 |
kshitij.so |
456 |
amPromotions = AmazonPromotion.query.filter(AmazonPromotion.startDate<=time).filter(AmazonPromotion.endDate>=time).filter(AmazonPromotion.promotionType==AmazonPromotionType.SHORTTERM).filter(AmazonPromotion.promotionActive==True) \
|
| 12556 |
anikendra |
457 |
.order_by(desc(AmazonPromotion.addedOn)).all()
|
| 12396 |
kshitij.so |
458 |
for amPromotion in amPromotions:
|
| 12606 |
kshitij.so |
459 |
if amazonShortTermActivePromotions.has_key(amPromotion.sku):
|
|
|
460 |
continue
|
| 12433 |
kshitij.so |
461 |
amazonShortTermActivePromotions[amPromotion.sku] = __Promotion(amPromotion.salePrice,amPromotion.subsidy,amPromotion.promotionType,amPromotion.endDate)
|
| 12363 |
kshitij.so |
462 |
session.close()
|
| 12450 |
kshitij.so |
463 |
print "No of items populated ",len(itemInfo)
|
| 12452 |
kshitij.so |
464 |
sleep(5)
|
| 12363 |
kshitij.so |
465 |
return itemInfo
|
|
|
466 |
|
| 12430 |
kshitij.so |
467 |
def getPriceAndAsin(itemInfo):
|
|
|
468 |
skus = []
|
|
|
469 |
for item in itemInfo:
|
|
|
470 |
skus.append(item.sku)
|
|
|
471 |
ourPricingForSku = amScraper.get_my_pricing_for_sku('A21TJRUUN4KGV', skus)
|
|
|
472 |
for item in itemInfo:
|
|
|
473 |
ourPricing = ourPricingForSku.get(item.sku)
|
| 12441 |
kshitij.so |
474 |
if ourPricing is None or len(ourPricing.keys())==0:
|
| 12430 |
kshitij.so |
475 |
item.ourSp = 0
|
|
|
476 |
item.promoPrice = 0
|
|
|
477 |
item.isPromotion = False
|
| 12473 |
kshitij.so |
478 |
item.asin = ''
|
| 12430 |
kshitij.so |
479 |
else:
|
|
|
480 |
item.ourSp = ourPricing.get('sellingPrice')
|
|
|
481 |
item.promoPrice = ourPricing.get('promoPrice')
|
|
|
482 |
item.isPromotion = ourPricing.get('promotion')
|
| 12473 |
kshitij.so |
483 |
item.asin = ourPricing.get('asin')
|
| 12450 |
kshitij.so |
484 |
|
| 12430 |
kshitij.so |
485 |
|
|
|
486 |
|
| 12597 |
kshitij.so |
487 |
def decideCategory(itemInfo,timestamp):
|
| 12363 |
kshitij.so |
488 |
exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete = [],[],[],[],[],[],[]
|
| 12430 |
kshitij.so |
489 |
skus = []
|
| 12363 |
kshitij.so |
490 |
for item in itemInfo:
|
| 12430 |
kshitij.so |
491 |
skus.append(item.sku)
|
| 12597 |
kshitij.so |
492 |
pricingResponse = amScraper.get_competitive_pricing_for_sku('A21TJRUUN4KGV', skus)
|
|
|
493 |
aggResponse = pricingResponse[0]
|
|
|
494 |
otherInfo = pricingResponse[1]
|
| 12430 |
kshitij.so |
495 |
ourPricingForSku = amScraper.get_my_pricing_for_sku('A21TJRUUN4KGV', skus)
|
| 12403 |
kshitij.so |
496 |
|
| 12363 |
kshitij.so |
497 |
for val in itemInfo:
|
| 12430 |
kshitij.so |
498 |
scrapInfo = aggResponse.get(val.sku)
|
| 12597 |
kshitij.so |
499 |
competitvePricingInfo = otherInfo.get(val.sku)
|
| 12443 |
kshitij.so |
500 |
if scrapInfo is None or len(scrapInfo)==0 or val.nlc==0 or len(ourPricingForSku.get(val.sku).keys())==0:
|
| 12363 |
kshitij.so |
501 |
temp = []
|
|
|
502 |
temp.append(val)
|
|
|
503 |
if val.nlc==0 or val.nlc is None:
|
| 12456 |
kshitij.so |
504 |
print "WANLC is 0"
|
| 12363 |
kshitij.so |
505 |
temp.append("WANLC is 0")
|
| 12657 |
kshitij.so |
506 |
elif ourPricingForSku.get(val.sku) is None or len(ourPricingForSku.get(val.sku).keys())==0:
|
| 12456 |
kshitij.so |
507 |
print "Unable to fetch our price"
|
| 12430 |
kshitij.so |
508 |
temp.append("Unable to fetch our price")
|
| 12363 |
kshitij.so |
509 |
else:
|
| 12639 |
kshitij.so |
510 |
print "No other seller or Unable to fetch competitive pricing"
|
|
|
511 |
temp.append("No other seller or Unable to fetch competitive pricing")
|
| 12363 |
kshitij.so |
512 |
exceptionList.append(temp)
|
|
|
513 |
continue
|
| 12430 |
kshitij.so |
514 |
val.ourSp = ourPricingForSku.get(val.sku).get('sellingPrice')
|
|
|
515 |
val.promoPrice = ourPricingForSku.get(val.sku).get('promoPrice')
|
|
|
516 |
val.isPromo = ourPricingForSku.get(val.sku).get('promotion')
|
| 12363 |
kshitij.so |
517 |
iterator = 0
|
|
|
518 |
sku, lowestSellerName,secondLowestSellerName, thirdLowestSellerName = ('',)*4
|
| 12432 |
kshitij.so |
519 |
ourSp, ourRank, lowestSellerSp, secondLowestSellerSp, thirdLowestSellerSp, lowestPossibleSp = (0,)*6
|
| 12430 |
kshitij.so |
520 |
lowestSellerShippingTime, lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , \
|
|
|
521 |
thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType = (0,)*9
|
|
|
522 |
isPromo = False
|
| 12363 |
kshitij.so |
523 |
sku = val.sku
|
|
|
524 |
multipleListings = False
|
| 12430 |
kshitij.so |
525 |
ourSkuDetails = ourPricingForSku.get(val.sku)
|
| 12475 |
kshitij.so |
526 |
if (ourSkuDetails.get('promotion')!=(amazonLongTermActivePromotions.has_key(val.sku) or amazonShortTermActivePromotions.has_key(val.sku))):
|
| 12432 |
kshitij.so |
527 |
temp = []
|
|
|
528 |
temp.append(val)
|
| 12456 |
kshitij.so |
529 |
print "promo misconfigured"
|
| 12432 |
kshitij.so |
530 |
temp.append("Promo misconfigured")
|
| 12457 |
kshitij.so |
531 |
exceptionList.append(temp)
|
| 12432 |
kshitij.so |
532 |
continue
|
| 12475 |
kshitij.so |
533 |
|
| 12430 |
kshitij.so |
534 |
scrapInfo.append(ourSkuDetails)
|
|
|
535 |
sortedScrapInfo = sorted(scrapInfo, key=itemgetter('promoPrice','notOurSku'))
|
|
|
536 |
for info in sortedScrapInfo:
|
| 12465 |
kshitij.so |
537 |
if not info['notOurSku']:
|
| 12442 |
kshitij.so |
538 |
ourSp = info['sellingPrice']
|
|
|
539 |
promoPrice = info['promoPrice']
|
|
|
540 |
isPromo = info['promotion']
|
| 12430 |
kshitij.so |
541 |
ourRank = iterator + 1
|
| 12363 |
kshitij.so |
542 |
|
|
|
543 |
if iterator == 0:
|
| 12430 |
kshitij.so |
544 |
lowestSellerSp = info['promoPrice']
|
|
|
545 |
lowestSellerShippingTime = info['shippingTime']
|
|
|
546 |
lowestSellerRating = info['rating']
|
|
|
547 |
lowestSellerType = info['fulfillmentChannel']
|
| 12363 |
kshitij.so |
548 |
|
|
|
549 |
if iterator == 1:
|
| 12430 |
kshitij.so |
550 |
secondLowestSellerSp = info['promoPrice']
|
|
|
551 |
secondLowestSellerShippingTime = info['shippingTime']
|
|
|
552 |
secondLowestSellerRating = info['rating']
|
|
|
553 |
secondLowestSellerType = info['fulfillmentChannel']
|
| 12363 |
kshitij.so |
554 |
|
|
|
555 |
if iterator == 2:
|
| 12430 |
kshitij.so |
556 |
thirdLowestSellerSp = info['promoPrice']
|
|
|
557 |
thirdLowestSellerShippingTime = info['shippingTime']
|
|
|
558 |
thirdLowestSellerRating = info['rating']
|
|
|
559 |
thirdLowestSellerType = info['fulfillmentChannel']
|
| 12363 |
kshitij.so |
560 |
|
|
|
561 |
iterator += 1
|
| 12401 |
kshitij.so |
562 |
print "terminating iterator"
|
| 12483 |
kshitij.so |
563 |
|
| 12408 |
kshitij.so |
564 |
print "Creating object am details",val.sku
|
| 12430 |
kshitij.so |
565 |
amDetails = __AmazonDetails(sku, float(ourSp), ourRank, lowestSellerName,float(lowestSellerSp),secondLowestSellerName, float(secondLowestSellerSp), thirdLowestSellerName, float(thirdLowestSellerSp),len(scrapInfo),multipleListings,promoPrice,isPromo, \
|
| 12597 |
kshitij.so |
566 |
lowestSellerShippingTime ,lowestSellerRating, secondLowestSellerShippingTime, secondLowestSellerRating, thirdLowestSellerShippingTime , thirdLowestSellerRating, lowestSellerType, secondLowestSellerType, thirdLowestSellerType, \
|
|
|
567 |
competitvePricingInfo['lowestMfnIgnored'],competitvePricingInfo['lowestMfn'],competitvePricingInfo['lowestFba'],competitvePricingInfo['isLowestMfnIgnored'],competitvePricingInfo['isLowestMfn'],competitvePricingInfo['isLowestFba'],None)
|
|
|
568 |
|
|
|
569 |
competitivePrice = decideCompetitvePricing(amDetails,val.ourInventory,timestamp)
|
|
|
570 |
amDetails.competitivePrice = competitivePrice
|
|
|
571 |
if amDetails.competitivePrice==0.0 and amDetails.ourRank > 1:
|
|
|
572 |
temp = []
|
|
|
573 |
temp.append(val)
|
|
|
574 |
temp.append("Unable to calculate competitive pricing")
|
|
|
575 |
exceptionList.append(temp)
|
|
|
576 |
continue
|
| 12363 |
kshitij.so |
577 |
try:
|
| 12414 |
kshitij.so |
578 |
print "inside val getter"
|
| 12418 |
kshitij.so |
579 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==int(val.sku[3:]), ItemVatMaster.stateId==val.state_id)).first()
|
|
|
580 |
if itemVatMaster is None:
|
| 12419 |
kshitij.so |
581 |
d_item = Item.query.filter_by(id=int(val.sku[3:])).first()
|
|
|
582 |
if d_item is None:
|
|
|
583 |
raise
|
|
|
584 |
else:
|
| 12430 |
kshitij.so |
585 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==d_item.category, CategoryVatMaster.minVal<=amDetails.promoPrice, CategoryVatMaster.maxVal>=amDetails.promoPrice, CategoryVatMaster.stateId == val.state_id)).first()
|
| 12419 |
kshitij.so |
586 |
if vatMaster is None:
|
| 12418 |
kshitij.so |
587 |
raise
|
| 12419 |
kshitij.so |
588 |
else:
|
|
|
589 |
val.vatRate = vatMaster.vatPercent
|
|
|
590 |
print "vat fetched"
|
| 12418 |
kshitij.so |
591 |
else:
|
|
|
592 |
val.vatRate = itemVatMaster.vatPercentage
|
| 12419 |
kshitij.so |
593 |
print "vat fetched"
|
| 12363 |
kshitij.so |
594 |
except:
|
| 12414 |
kshitij.so |
595 |
print "vat exception"
|
| 12363 |
kshitij.so |
596 |
temp = []
|
|
|
597 |
temp.append(val)
|
|
|
598 |
temp.append("Vat not available")
|
|
|
599 |
exceptionList.append(temp)
|
|
|
600 |
continue
|
|
|
601 |
|
|
|
602 |
lowestPossibleSp = getLowestPossibleSp(amDetails,val,val.sourcePercentage)
|
| 12408 |
kshitij.so |
603 |
print "Creating pricing obj"
|
| 12432 |
kshitij.so |
604 |
amPricing = __AmazonPricing(ourSp,lowestPossibleSp)
|
| 12483 |
kshitij.so |
605 |
print "sku ",val.sku
|
|
|
606 |
print "oursp ",ourSp
|
|
|
607 |
print "promoPrice ",promoPrice
|
|
|
608 |
print "lowestpossbile sp ",lowestPossibleSp
|
|
|
609 |
print "objlowestPossiblesp ",amPricing.lowestPossibleSp
|
| 12363 |
kshitij.so |
610 |
|
| 12467 |
kshitij.so |
611 |
if amDetails.promoPrice < amPricing.lowestPossibleSp:
|
| 12363 |
kshitij.so |
612 |
temp = []
|
|
|
613 |
temp.append(val)
|
|
|
614 |
temp.append(amDetails)
|
|
|
615 |
temp.append(amPricing)
|
|
|
616 |
negativeMargin.append(temp)
|
| 12483 |
kshitij.so |
617 |
print "val sku cat negative ",val.sku
|
| 12363 |
kshitij.so |
618 |
continue
|
|
|
619 |
|
|
|
620 |
if amDetails.ourRank==1:
|
|
|
621 |
temp = []
|
|
|
622 |
temp.append(val)
|
|
|
623 |
temp.append(amDetails)
|
|
|
624 |
temp.append(amPricing)
|
|
|
625 |
cheapest.append(temp)
|
| 12483 |
kshitij.so |
626 |
print "val sku cat cheapest ",val.sku
|
| 12363 |
kshitij.so |
627 |
continue
|
|
|
628 |
|
| 12597 |
kshitij.so |
629 |
if val.parent_category in [10006,10009,11001]:
|
|
|
630 |
if (amDetails.competitivePrice > amPricing.lowestPossibleSp) and ((((float(float(amDetails.promoPrice) - amDetails.competitivePrice))/float(amDetails.promoPrice))<=.0025) or ((float(amDetails.promoPrice) - amDetails.competitivePrice)<=25)):
|
|
|
631 |
temp = []
|
|
|
632 |
temp.append(val)
|
|
|
633 |
temp.append(amDetails)
|
|
|
634 |
temp.append(amPricing)
|
|
|
635 |
amongCheapestAndCanCompete.append(temp)
|
|
|
636 |
print "val sku cat amongCheapestAndCanCompete ",val.sku
|
|
|
637 |
continue
|
|
|
638 |
else:
|
|
|
639 |
if (amDetails.competitivePrice > amPricing.lowestPossibleSp) and ((((float(float(amDetails.promoPrice) - amDetails.competitivePrice))/float(amDetails.promoPrice))<=.01) or ((float(amDetails.promoPrice) - amDetails.competitivePrice)<=10)):
|
|
|
640 |
temp = []
|
|
|
641 |
temp.append(val)
|
|
|
642 |
temp.append(amDetails)
|
|
|
643 |
temp.append(amPricing)
|
|
|
644 |
amongCheapestAndCanCompete.append(temp)
|
|
|
645 |
print "val sku cat amongCheapestAndCanCompete ",val.sku
|
|
|
646 |
continue
|
| 12363 |
kshitij.so |
647 |
|
| 12597 |
kshitij.so |
648 |
if (amDetails.competitivePrice > amPricing.lowestPossibleSp):
|
| 12363 |
kshitij.so |
649 |
temp = []
|
|
|
650 |
temp.append(val)
|
|
|
651 |
temp.append(amDetails)
|
|
|
652 |
temp.append(amPricing)
|
|
|
653 |
canCompete.append(temp)
|
| 12483 |
kshitij.so |
654 |
print "val sku cat can compete ",val.sku
|
| 12363 |
kshitij.so |
655 |
continue
|
|
|
656 |
|
| 12597 |
kshitij.so |
657 |
if amDetails.competitivePrice*(1+.01) >= amPricing.lowestPossibleSp:
|
| 12396 |
kshitij.so |
658 |
temp = []
|
|
|
659 |
temp.append(val)
|
|
|
660 |
temp.append(amDetails)
|
|
|
661 |
temp.append(amPricing)
|
|
|
662 |
almostCompete.append(temp)
|
| 12483 |
kshitij.so |
663 |
print "val sku cat almost compete ",val.sku
|
| 12396 |
kshitij.so |
664 |
continue
|
|
|
665 |
|
| 12363 |
kshitij.so |
666 |
temp = []
|
|
|
667 |
temp.append(val)
|
|
|
668 |
temp.append(amDetails)
|
|
|
669 |
temp.append(amPricing)
|
| 12483 |
kshitij.so |
670 |
print "val sku cat cant compete ",val.sku
|
| 12363 |
kshitij.so |
671 |
cantCompete.append(temp)
|
| 12414 |
kshitij.so |
672 |
print "Created category..."
|
| 12363 |
kshitij.so |
673 |
|
|
|
674 |
return exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete
|
| 12396 |
kshitij.so |
675 |
|
| 12597 |
kshitij.so |
676 |
|
|
|
677 |
def decideCompetitvePricing(amDetails,ourInventory,timestamp):
|
|
|
678 |
'''
|
|
|
679 |
lowestMfnIgnoredOffer, lowestMfnOffer, lowestFbaOffer, isLowestMfnIgnored, isLowestMfn, isLowestFba
|
|
|
680 |
'''
|
|
|
681 |
|
|
|
682 |
if amDetails.ourRank==1:
|
|
|
683 |
return 0.0
|
|
|
684 |
else:
|
|
|
685 |
if amDetails.isLowestMfn and amDetails.isLowestFba:
|
|
|
686 |
if amDetails.lowestMfnOffer >= amDetails.lowestFbaOffer:
|
|
|
687 |
return amDetails.lowestFbaOffer
|
|
|
688 |
else:
|
|
|
689 |
#TODO Check last five days history.
|
|
|
690 |
ratio = getCheapestMfnCount(timestamp,amDetails.sku[3:])
|
|
|
691 |
daysInStock = getNoOfDaysInStock(saleMap.get(amDetails.sku))
|
|
|
692 |
try:
|
|
|
693 |
daysOfStock = (float(ourInventory))/calculateAverageSale(amDetails.sku)
|
|
|
694 |
except:
|
|
|
695 |
daysOfStock = float("inf")
|
|
|
696 |
if daysInStock >= 4 and daysOfStock > 20 and ratio >=.8:
|
|
|
697 |
return amDetails.lowestMfnOffer
|
|
|
698 |
else:
|
| 12659 |
kshitij.so |
699 |
print "Unable to calculate competitive pricing for %s in block 1"%(amDetails.sku)
|
|
|
700 |
return amDetails.lowestFbaOffer
|
| 12597 |
kshitij.so |
701 |
elif amDetails.isLowestFba:
|
|
|
702 |
return amDetails.lowestFbaOffer
|
|
|
703 |
elif amDetails.isLowestMfn:
|
|
|
704 |
#TODO Check last five days history
|
|
|
705 |
ratio = getCheapestMfnCount(timestamp,amDetails.sku[3:])
|
|
|
706 |
daysInStock = getNoOfDaysInStock(saleMap.get(amDetails.sku))
|
|
|
707 |
try:
|
|
|
708 |
daysOfStock = (float(ourInventory))/calculateAverageSale(amDetails.sku)
|
|
|
709 |
except:
|
|
|
710 |
daysOfStock = float("inf")
|
|
|
711 |
if daysInStock >= 4 and daysOfStock > 20 and ratio >.8:
|
|
|
712 |
return amDetails.lowestMfnOffer
|
|
|
713 |
else:
|
| 12659 |
kshitij.so |
714 |
print "Unable to calculate competitive pricing for %s in block 2"%(amDetails.sku)
|
|
|
715 |
return 0.0
|
| 12597 |
kshitij.so |
716 |
else:
|
|
|
717 |
return 0.0
|
|
|
718 |
|
| 12556 |
anikendra |
719 |
def getBreakevenPrice(item,val,spm):
|
|
|
720 |
breakEvenPrice = (val.nlc+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15.0+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));
|
|
|
721 |
return round(breakEvenPrice,2)
|
| 12363 |
kshitij.so |
722 |
|
|
|
723 |
def getLowestPossibleSp(amazonDetails,val,spm):
|
| 12432 |
kshitij.so |
724 |
if val.isPromo:
|
|
|
725 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
| 12466 |
kshitij.so |
726 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
| 12432 |
kshitij.so |
727 |
else:
|
| 12466 |
kshitij.so |
728 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
| 12597 |
kshitij.so |
729 |
else:
|
|
|
730 |
subsidy = 0.0
|
|
|
731 |
|
|
|
732 |
lowestPossibleSp = (val.nlc-subsidy+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15.0+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));
|
| 12556 |
anikendra |
733 |
|
|
|
734 |
#print (val.nlc-subsidy+(val.courierCost)*(1+(spm.serviceTax/100))*(1+(val.vatRate/100))+(15+val.otherCost)*(1+(val.vatRate)/100))
|
|
|
735 |
#print (1-(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))*(1+(val.vatRate)/100)-(spm.returnProvision/100)*(1+(val.vatRate)/100))
|
| 12363 |
kshitij.so |
736 |
return round(lowestPossibleSp,2)
|
|
|
737 |
|
| 12489 |
kshitij.so |
738 |
def getNewLowestPossibleSp(item,serviceTax,newVatRate):
|
|
|
739 |
lowestPossibleSp = (item.wanlc+(item.courierCost)*(1+(serviceTax/100))*(1+(newVatRate/100))+(15+item.otherCost)*(1+(newVatRate)/100))/(1-(item.commission/100)*(1+(serviceTax/100))*(1+(newVatRate)/100)-(item.returnProvision/100)*(1+(newVatRate)/100));
|
|
|
740 |
if item.isPromotion:
|
|
|
741 |
sku = ''
|
|
|
742 |
if item.warehouseLocation==1:
|
|
|
743 |
sku='FBA'+str(item.item_id)
|
|
|
744 |
else:
|
|
|
745 |
sku='FBB'+str(item.item_id)
|
|
|
746 |
if amazonLongTermActivePromotions.has_key(sku):
|
|
|
747 |
subsidy = (amazonLongTermActivePromotions.get(sku)).subsidy
|
|
|
748 |
else:
|
|
|
749 |
subsidy = (amazonShortTermActivePromotions.get(sku)).subsidy
|
| 12556 |
anikendra |
750 |
print "subsidy ",subsidy
|
|
|
751 |
lowestPossibleSp = (item.wanlc-subsidy+(item.courierCost)*(1+(serviceTax/100))*(1+(newVatRate/100))+(15+item.otherCost)*(1+(newVatRate)/100))/(1-(item.commission/100)*(1+(serviceTax/100))*(1+(newVatRate)/100)-(item.returnProvision/100)*(1+(newVatRate)/100));
|
| 12489 |
kshitij.so |
752 |
return round(lowestPossibleSp,2)
|
|
|
753 |
|
| 12363 |
kshitij.so |
754 |
def getTargetTp(targetSp,spm,val):
|
| 12424 |
kshitij.so |
755 |
targetTp = targetSp- targetSp*(spm.commission/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost)*(1+(spm.serviceTax/100))
|
| 12363 |
kshitij.so |
756 |
return round(targetTp,2)
|
|
|
757 |
|
|
|
758 |
def commitExceptionList(exceptionList,timestamp,runType):
|
|
|
759 |
for exceptionItem in exceptionList:
|
|
|
760 |
val = exceptionItem[0]
|
|
|
761 |
reason = exceptionItem[1]
|
|
|
762 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
763 |
amazonScrapingHistory.item_id = val.sku[3:]
|
|
|
764 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
765 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12639 |
kshitij.so |
766 |
amazonScrapingHistory.ourSellingPrice = val.ourSp
|
|
|
767 |
amazonScrapingHistory.promoPrice = val.promoPrice
|
| 12363 |
kshitij.so |
768 |
amazonScrapingHistory.reason = reason
|
|
|
769 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
770 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.EXCEPTION
|
|
|
771 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
772 |
session.commit()
|
|
|
773 |
|
|
|
774 |
def commitNegativeMargin(negativeMargin,timestamp,runType):
|
|
|
775 |
for negativeMarginItem in negativeMargin:
|
|
|
776 |
val = negativeMarginItem[0]
|
|
|
777 |
amDetails = negativeMarginItem[1]
|
|
|
778 |
amPricing = negativeMarginItem[2]
|
|
|
779 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
780 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
781 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
782 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
783 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
784 |
else:
|
|
|
785 |
subsidy = 0
|
| 12363 |
kshitij.so |
786 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
787 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
788 |
amazonScrapingHistory.asin = val.asin
|
| 12363 |
kshitij.so |
789 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
790 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12363 |
kshitij.so |
791 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
792 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
793 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
794 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12363 |
kshitij.so |
795 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
796 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
797 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
798 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12468 |
kshitij.so |
799 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
800 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
801 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12363 |
kshitij.so |
802 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
803 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
804 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
805 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12363 |
kshitij.so |
806 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
807 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
808 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
809 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
810 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
|
|
811 |
amazonScrapingHistory.cheapestMfnCount = True
|
|
|
812 |
else:
|
|
|
813 |
amazonScrapingHistory.cheapestMfnCount = False
|
| 12363 |
kshitij.so |
814 |
amazonScrapingHistory.wanlc = val.nlc
|
| 12447 |
kshitij.so |
815 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12363 |
kshitij.so |
816 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
817 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12363 |
kshitij.so |
818 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
819 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
820 |
amazonScrapingHistory.risky = val.risky
|
|
|
821 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
822 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
823 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
|
|
|
824 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
825 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
826 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
827 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12363 |
kshitij.so |
828 |
session.commit()
|
|
|
829 |
|
|
|
830 |
|
|
|
831 |
def commitCheapest(cheapest,timestamp,runType):
|
|
|
832 |
for cheapestItem in cheapest:
|
|
|
833 |
val = cheapestItem[0]
|
|
|
834 |
amDetails = cheapestItem[1]
|
|
|
835 |
amPricing = cheapestItem[2]
|
|
|
836 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
837 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
838 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
839 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
840 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
841 |
else:
|
|
|
842 |
subsidy = 0
|
| 12363 |
kshitij.so |
843 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
844 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
845 |
amazonScrapingHistory.asin = val.asin
|
| 12363 |
kshitij.so |
846 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
847 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12363 |
kshitij.so |
848 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
849 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
850 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
851 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12363 |
kshitij.so |
852 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
853 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
854 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
855 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12430 |
kshitij.so |
856 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
857 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
858 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12363 |
kshitij.so |
859 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
860 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
861 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
862 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12363 |
kshitij.so |
863 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
864 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
865 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
866 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
867 |
amazonScrapingHistory.cheapestMfnCount = False
|
| 12447 |
kshitij.so |
868 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12363 |
kshitij.so |
869 |
amazonScrapingHistory.wanlc = val.nlc
|
|
|
870 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
871 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12363 |
kshitij.so |
872 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
873 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
874 |
amazonScrapingHistory.risky = val.risky
|
|
|
875 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
876 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
877 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.BUY_BOX
|
|
|
878 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
879 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| 12597 |
kshitij.so |
880 |
proposed_sp = max(amDetails.secondLowestSellerSp - 1, amPricing.lowestPossibleSp)
|
| 12433 |
kshitij.so |
881 |
if amazonScrapingHistory.isPromotion:
|
|
|
882 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
| 12466 |
kshitij.so |
883 |
proposed_sp = min(proposed_sp,(amazonLongTermActivePromotions.get(val.sku)).salePrice)
|
| 12433 |
kshitij.so |
884 |
else:
|
| 12466 |
kshitij.so |
885 |
proposed_sp = min(proposed_sp,(amazonShortTermActivePromotions.get(val.sku)).salePrice)
|
| 12468 |
kshitij.so |
886 |
#proposed_tp = getTargetTp(proposed_sp,spm,val)
|
| 12363 |
kshitij.so |
887 |
amazonScrapingHistory.proposedSp = proposed_sp
|
| 12468 |
kshitij.so |
888 |
#amazonScrapingHistory.proposedTp = proposed_tp
|
|
|
889 |
#amazonScrapingHistory.marginIncreasedPotential = proposed_tp - amPricing.ourTp
|
| 12363 |
kshitij.so |
890 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
891 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
892 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12363 |
kshitij.so |
893 |
session.commit()
|
|
|
894 |
|
|
|
895 |
|
|
|
896 |
|
|
|
897 |
def commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,runType):
|
|
|
898 |
for amongCheapestAndCanCompeteItem in amongCheapestAndCanCompete:
|
|
|
899 |
val = amongCheapestAndCanCompeteItem[0]
|
|
|
900 |
amDetails = amongCheapestAndCanCompeteItem[1]
|
|
|
901 |
amPricing = amongCheapestAndCanCompeteItem[2]
|
|
|
902 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
903 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
904 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
905 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
906 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
907 |
else:
|
|
|
908 |
subsidy = 0
|
| 12363 |
kshitij.so |
909 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
910 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
911 |
amazonScrapingHistory.asin = val.asin
|
| 12363 |
kshitij.so |
912 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
913 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12363 |
kshitij.so |
914 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
915 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
916 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
917 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12363 |
kshitij.so |
918 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
919 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
920 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
921 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12430 |
kshitij.so |
922 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
923 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
924 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12363 |
kshitij.so |
925 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
926 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
927 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
928 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12470 |
kshitij.so |
929 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
930 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
931 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
932 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
933 |
amazonScrapingHistory.isLowestMfnIgnored = amDetails.isLowestMfnIgnored
|
|
|
934 |
amazonScrapingHistory.isLowestMfn = amDetails.isLowestMfn
|
|
|
935 |
amazonScrapingHistory.isLowestFba = amDetails.isLowestFba
|
|
|
936 |
amazonScrapingHistory.lowestMfnIgnoredOffer =amDetails.lowestMfnIgnoredOffer
|
|
|
937 |
amazonScrapingHistory.lowestMfnOffer = amDetails.lowestMfnOffer
|
|
|
938 |
amazonScrapingHistory.lowestFbaOffer = amDetails.lowestFbaOffer
|
|
|
939 |
amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
|
|
|
940 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
|
|
941 |
amazonScrapingHistory.cheapestMfnCount = True
|
|
|
942 |
else:
|
|
|
943 |
amazonScrapingHistory.cheapestMfnCount = False
|
| 12447 |
kshitij.so |
944 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12363 |
kshitij.so |
945 |
amazonScrapingHistory.wanlc = val.nlc
|
|
|
946 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
947 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12363 |
kshitij.so |
948 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
949 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
950 |
amazonScrapingHistory.risky = val.risky
|
|
|
951 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
952 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
953 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE
|
|
|
954 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
955 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| 12597 |
kshitij.so |
956 |
proposed_sp = max(amDetails.competitivePrice - 1, amPricing.lowestPossibleSp)
|
| 12468 |
kshitij.so |
957 |
#proposed_tp = getTargetTp(proposed_sp,spm,val)
|
| 12363 |
kshitij.so |
958 |
amazonScrapingHistory.proposedSp = proposed_sp
|
| 12468 |
kshitij.so |
959 |
#amazonScrapingHistory.proposedTp = proposed_tp
|
| 12363 |
kshitij.so |
960 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
961 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
962 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12363 |
kshitij.so |
963 |
session.commit()
|
|
|
964 |
|
|
|
965 |
def commitCanCompete(canCompete,timestamp,runType):
|
|
|
966 |
for canCompeteItem in canCompete:
|
|
|
967 |
val = canCompeteItem[0]
|
|
|
968 |
amDetails = canCompeteItem[1]
|
|
|
969 |
amPricing = canCompeteItem[2]
|
|
|
970 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
971 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
972 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
973 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
974 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
975 |
else:
|
|
|
976 |
subsidy = 0
|
| 12363 |
kshitij.so |
977 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
978 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
979 |
amazonScrapingHistory.asin = val.asin
|
| 12363 |
kshitij.so |
980 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
981 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12363 |
kshitij.so |
982 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
983 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
984 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
985 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12363 |
kshitij.so |
986 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
987 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
988 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
989 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12430 |
kshitij.so |
990 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
991 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
992 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12363 |
kshitij.so |
993 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
994 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
995 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
996 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12363 |
kshitij.so |
997 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
998 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
999 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
1000 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
1001 |
amazonScrapingHistory.isLowestMfnIgnored = amDetails.isLowestMfnIgnored
|
|
|
1002 |
amazonScrapingHistory.isLowestMfn = amDetails.isLowestMfn
|
|
|
1003 |
amazonScrapingHistory.isLowestFba = amDetails.isLowestFba
|
|
|
1004 |
amazonScrapingHistory.lowestMfnIgnoredOffer =amDetails.lowestMfnIgnoredOffer
|
|
|
1005 |
amazonScrapingHistory.lowestMfnOffer = amDetails.lowestMfnOffer
|
|
|
1006 |
amazonScrapingHistory.lowestFbaOffer = amDetails.lowestFbaOffer
|
|
|
1007 |
amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
|
|
|
1008 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
|
|
1009 |
amazonScrapingHistory.cheapestMfnCount = True
|
|
|
1010 |
else:
|
|
|
1011 |
amazonScrapingHistory.cheapestMfnCount = False
|
| 12447 |
kshitij.so |
1012 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12363 |
kshitij.so |
1013 |
amazonScrapingHistory.wanlc = val.nlc
|
|
|
1014 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
1015 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12363 |
kshitij.so |
1016 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
1017 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
1018 |
amazonScrapingHistory.risky = val.risky
|
|
|
1019 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
1020 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
1021 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.COMPETITIVE
|
|
|
1022 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
1023 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| 12597 |
kshitij.so |
1024 |
proposed_sp = max(amDetails.competitivePrice - 1, amPricing.lowestPossibleSp)
|
| 12468 |
kshitij.so |
1025 |
#proposed_tp = getTargetTp(proposed_sp,spm,val)
|
| 12363 |
kshitij.so |
1026 |
amazonScrapingHistory.proposedSp = proposed_sp
|
| 12468 |
kshitij.so |
1027 |
#amazonScrapingHistory.proposedTp = proposed_tp
|
| 12363 |
kshitij.so |
1028 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
1029 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
1030 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12363 |
kshitij.so |
1031 |
session.commit()
|
|
|
1032 |
|
| 12383 |
kshitij.so |
1033 |
def commitAlmostCompete(almostCompete,timestamp,runType):
|
| 12396 |
kshitij.so |
1034 |
for almostCompeteItem in almostCompete:
|
|
|
1035 |
val = almostCompeteItem[0]
|
|
|
1036 |
amDetails = almostCompeteItem[1]
|
|
|
1037 |
amPricing = almostCompeteItem[2]
|
|
|
1038 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
1039 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
1040 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
1041 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
1042 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
1043 |
else:
|
|
|
1044 |
subsidy = 0
|
| 12396 |
kshitij.so |
1045 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
1046 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
1047 |
amazonScrapingHistory.asin = val.asin
|
| 12396 |
kshitij.so |
1048 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
|
|
1049 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
|
|
1050 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
1051 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
1052 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
1053 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12396 |
kshitij.so |
1054 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
1055 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
1056 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
1057 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12430 |
kshitij.so |
1058 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
1059 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
1060 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12396 |
kshitij.so |
1061 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
1062 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
1063 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
1064 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12396 |
kshitij.so |
1065 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
1066 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
1067 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
1068 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
1069 |
amazonScrapingHistory.isLowestMfnIgnored = amDetails.isLowestMfnIgnored
|
|
|
1070 |
amazonScrapingHistory.isLowestMfn = amDetails.isLowestMfn
|
|
|
1071 |
amazonScrapingHistory.isLowestFba = amDetails.isLowestFba
|
|
|
1072 |
amazonScrapingHistory.lowestMfnIgnoredOffer =amDetails.lowestMfnIgnoredOffer
|
|
|
1073 |
amazonScrapingHistory.lowestMfnOffer = amDetails.lowestMfnOffer
|
|
|
1074 |
amazonScrapingHistory.lowestFbaOffer = amDetails.lowestFbaOffer
|
|
|
1075 |
amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
|
|
|
1076 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
|
|
1077 |
amazonScrapingHistory.cheapestMfnCount = True
|
|
|
1078 |
else:
|
|
|
1079 |
amazonScrapingHistory.cheapestMfnCount = False
|
| 12447 |
kshitij.so |
1080 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12396 |
kshitij.so |
1081 |
amazonScrapingHistory.wanlc = val.nlc
|
|
|
1082 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
1083 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12396 |
kshitij.so |
1084 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
1085 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
1086 |
amazonScrapingHistory.risky = val.risky
|
|
|
1087 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
1088 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
1089 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.ALMOST_COMPETE
|
|
|
1090 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
1091 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| 12597 |
kshitij.so |
1092 |
proposed_sp = min(amDetails.competitivePrice*(1+.01),amPricing.lowestPossibleSp)
|
| 12468 |
kshitij.so |
1093 |
#proposed_tp = getTargetTp(proposed_sp,spm,val)
|
|
|
1094 |
#target_nlc = proposed_tp - amPricing.lowestPossibleTp + val.nlc
|
| 12396 |
kshitij.so |
1095 |
amazonScrapingHistory.proposedSp = proposed_sp
|
| 12468 |
kshitij.so |
1096 |
#amazonScrapingHistory.proposedTp = proposed_tp
|
|
|
1097 |
#amazonScrapingHistory.targetNlc = target_nlc
|
| 12396 |
kshitij.so |
1098 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
1099 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
1100 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12396 |
kshitij.so |
1101 |
session.commit()
|
| 12363 |
kshitij.so |
1102 |
|
| 12396 |
kshitij.so |
1103 |
|
| 12363 |
kshitij.so |
1104 |
def commitCantCompete(cantCompete, timestamp,runType):
|
|
|
1105 |
for cantCompeteItem in cantCompete:
|
|
|
1106 |
val = cantCompeteItem[0]
|
|
|
1107 |
amDetails = cantCompeteItem[1]
|
|
|
1108 |
amPricing = cantCompeteItem[2]
|
|
|
1109 |
spm = val.sourcePercentage
|
| 12510 |
kshitij.so |
1110 |
if amazonLongTermActivePromotions.has_key(val.sku):
|
|
|
1111 |
subsidy = (amazonLongTermActivePromotions.get(val.sku)).subsidy
|
|
|
1112 |
elif amazonShortTermActivePromotions.has_key(val.sku):
|
|
|
1113 |
subsidy = (amazonShortTermActivePromotions.get(val.sku)).subsidy
|
|
|
1114 |
else:
|
|
|
1115 |
subsidy = 0
|
| 12363 |
kshitij.so |
1116 |
amazonScrapingHistory = AmazonScrapingHistory()
|
|
|
1117 |
amazonScrapingHistory.item_id = val.sku[3:]
|
| 12471 |
kshitij.so |
1118 |
amazonScrapingHistory.asin = val.asin
|
| 12363 |
kshitij.so |
1119 |
amazonScrapingHistory.warehouseLocation = val.state_id
|
| 12396 |
kshitij.so |
1120 |
amazonScrapingHistory.parentCategoryId = val.parent_category
|
| 12363 |
kshitij.so |
1121 |
amazonScrapingHistory.ourSellingPrice = amDetails.ourSp
|
| 12432 |
kshitij.so |
1122 |
amazonScrapingHistory.promoPrice = amDetails.promoPrice
|
| 12510 |
kshitij.so |
1123 |
amazonScrapingHistory.subsidy = subsidy
|
|
|
1124 |
amazonScrapingHistory.vatRate = val.vatRate
|
| 12363 |
kshitij.so |
1125 |
amazonScrapingHistory.lowestPossibleSp = amPricing.lowestPossibleSp
|
|
|
1126 |
amazonScrapingHistory.ourRank = amDetails.ourRank
|
|
|
1127 |
amazonScrapingHistory.ourInventory = val.ourInventory
|
|
|
1128 |
amazonScrapingHistory.lowestSellerSp = amDetails.lowestSellerSp
|
| 12430 |
kshitij.so |
1129 |
amazonScrapingHistory.lowestSellerShippingTime = amDetails.lowestSellerShippingTime
|
|
|
1130 |
amazonScrapingHistory.lowestSellerRating = amDetails.lowestSellerRating
|
|
|
1131 |
amazonScrapingHistory.lowestSellerType = amDetails.lowestSellerType
|
| 12363 |
kshitij.so |
1132 |
amazonScrapingHistory.secondLowestSellerSp = amDetails.secondLowestSellerSp
|
| 12468 |
kshitij.so |
1133 |
amazonScrapingHistory.secondLowestSellerShippingTime = amDetails.secondLowestSellerShippingTime
|
|
|
1134 |
amazonScrapingHistory.secondLowestSellerRating = amDetails.secondLowestSellerRating
|
|
|
1135 |
amazonScrapingHistory.secondLowestSellerType = amDetails.secondLowestSellerType
|
| 12363 |
kshitij.so |
1136 |
amazonScrapingHistory.thirdLowestSellerSp = amDetails.thirdLowestSellerSp
|
| 12468 |
kshitij.so |
1137 |
amazonScrapingHistory.thirdLowestSellerShippingTime = amDetails.thirdLowestSellerShippingTime
|
|
|
1138 |
amazonScrapingHistory.thirdLowestSellerRating = amDetails.thirdLowestSellerRating
|
|
|
1139 |
amazonScrapingHistory.thirdLowestSellerType = amDetails.thirdLowestSellerType
|
| 12597 |
kshitij.so |
1140 |
amazonScrapingHistory.isLowestMfnIgnored = amDetails.isLowestMfnIgnored
|
|
|
1141 |
amazonScrapingHistory.isLowestMfn = amDetails.isLowestMfn
|
|
|
1142 |
amazonScrapingHistory.isLowestFba = amDetails.isLowestFba
|
|
|
1143 |
amazonScrapingHistory.lowestMfnIgnoredOffer =amDetails.lowestMfnIgnoredOffer
|
|
|
1144 |
amazonScrapingHistory.lowestMfnOffer = amDetails.lowestMfnOffer
|
|
|
1145 |
amazonScrapingHistory.lowestFbaOffer = amDetails.lowestFbaOffer
|
|
|
1146 |
if (amDetails.lowestMfnOffer < amDetails.lowestFbaOffer or amDetails.lowestMfnOffer < amazonScrapingHistory.promoPrice) and amDetails.isLowestMfn:
|
|
|
1147 |
amazonScrapingHistory.cheapestMfnCount = True
|
|
|
1148 |
else:
|
|
|
1149 |
amazonScrapingHistory.cheapestMfnCount = False
|
|
|
1150 |
amazonScrapingHistory.competitivePrice = amDetails.competitivePrice
|
| 12447 |
kshitij.so |
1151 |
amazonScrapingHistory.otherCost = val.otherCost
|
| 12363 |
kshitij.so |
1152 |
amazonScrapingHistory.wanlc = val.nlc
|
|
|
1153 |
amazonScrapingHistory.commission = spm.commission
|
| 12422 |
kshitij.so |
1154 |
amazonScrapingHistory.competitorCommission = spm.competitorCommissionOther
|
| 12363 |
kshitij.so |
1155 |
amazonScrapingHistory.returnProvision = spm.returnProvision
|
|
|
1156 |
amazonScrapingHistory.courierCost = val.courierCost
|
|
|
1157 |
amazonScrapingHistory.risky = val.risky
|
|
|
1158 |
amazonScrapingHistory.runType = RunType._NAMES_TO_VALUES.get(runType)
|
|
|
1159 |
amazonScrapingHistory.totalSeller = amDetails.totalSeller
|
|
|
1160 |
amazonScrapingHistory.competitiveCategory = CompetitionCategory.CANT_COMPETE
|
|
|
1161 |
amazonScrapingHistory.timestamp = timestamp
|
|
|
1162 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
| 12597 |
kshitij.so |
1163 |
proposed_sp = amDetails.competitivePrice - max(5, amDetails.competitivePrice*0.001)
|
| 12468 |
kshitij.so |
1164 |
#proposed_tp = getTargetTp(proposed_sp,spm,val)
|
|
|
1165 |
#target_nlc = proposed_tp - amPricing.lowestPossibleTp + val.nlc
|
| 12363 |
kshitij.so |
1166 |
amazonScrapingHistory.proposedSp = proposed_sp
|
| 12468 |
kshitij.so |
1167 |
#amazonScrapingHistory.proposedTp = proposed_tp
|
|
|
1168 |
#amazonScrapingHistory.targetNlc = target_nlc
|
| 12363 |
kshitij.so |
1169 |
amazonScrapingHistory.multipleListings = amDetails.multipleListings
|
|
|
1170 |
amazonScrapingHistory.avgSale = calculateAverageSale(val.sku) #Last five days
|
| 12432 |
kshitij.so |
1171 |
amazonScrapingHistory.isPromotion = val.isPromo
|
| 12363 |
kshitij.so |
1172 |
session.commit()
|
|
|
1173 |
|
| 12396 |
kshitij.so |
1174 |
def markAutoFavourites(time):
|
|
|
1175 |
nowAutoFav = []
|
|
|
1176 |
previouslyAutoFav = []
|
|
|
1177 |
stockList = []
|
|
|
1178 |
saleList = []
|
|
|
1179 |
items = session.query(func.sum(AmazonScrapingHistory.ourInventory),AmazonScrapingHistory.item_id).group_by(AmazonScrapingHistory.item_id).all()
|
|
|
1180 |
allItems = session.query(Amazonlisted).all()
|
|
|
1181 |
for item in items:
|
|
|
1182 |
reason = ""
|
|
|
1183 |
if item[0]>=5:
|
|
|
1184 |
stockList.append(item[1])
|
|
|
1185 |
|
|
|
1186 |
for sku, val in saleMap.iteritems():
|
|
|
1187 |
totalSale = 0
|
|
|
1188 |
item_id = sku.replace('FBA','').replace('FBB','')
|
|
|
1189 |
val =saleMap.get('FBA'+str(item_id))
|
|
|
1190 |
if val is not None:
|
|
|
1191 |
for sale in val:
|
|
|
1192 |
totalSale += sale.totalOrderCount
|
|
|
1193 |
val =saleMap.get('FBB'+str(item_id))
|
|
|
1194 |
if val is not None:
|
|
|
1195 |
for sale in val:
|
|
|
1196 |
totalSale += sale.totalOrderCount
|
|
|
1197 |
if totalSale > 0:
|
|
|
1198 |
saleList.append(item_id)
|
|
|
1199 |
|
|
|
1200 |
for aItem in allItems:
|
|
|
1201 |
reason = ""
|
|
|
1202 |
toMark = False
|
|
|
1203 |
if aItem.itemId in saleList:
|
|
|
1204 |
toMark = True
|
|
|
1205 |
reason+="Total FC sale is greater than 1 for last five days.."
|
|
|
1206 |
if aItem.itemId in stockList:
|
|
|
1207 |
toMark = True
|
| 12660 |
kshitij.so |
1208 |
reason+="Fulfillable Stock in FC is >=5"
|
| 12396 |
kshitij.so |
1209 |
if not aItem.autoFavourite:
|
|
|
1210 |
print "Item is not under auto favourite"
|
|
|
1211 |
if toMark:
|
|
|
1212 |
temp=[]
|
|
|
1213 |
temp.append(aItem.itemId)
|
|
|
1214 |
temp.append(reason)
|
|
|
1215 |
nowAutoFav.append(temp)
|
|
|
1216 |
if (not toMark) and aItem.autoFavourite:
|
|
|
1217 |
previouslyAutoFav.append(aItem.itemId)
|
|
|
1218 |
aItem.autoFavourite = toMark
|
|
|
1219 |
session.commit()
|
|
|
1220 |
return previouslyAutoFav, nowAutoFav
|
|
|
1221 |
|
| 12526 |
anikendra |
1222 |
#Write the excel sheet headers for identical sheets
|
|
|
1223 |
def writeheaders(sheet,heading_xf):
|
|
|
1224 |
sheet.write(0, 0, "Item Id", heading_xf)
|
|
|
1225 |
sheet.write(0, 1, "Amazon Sku", heading_xf)
|
|
|
1226 |
sheet.write(0, 2, "Asin", heading_xf)
|
|
|
1227 |
sheet.write(0, 3, "Location", heading_xf)
|
|
|
1228 |
sheet.write(0, 4, "Brand", heading_xf)
|
|
|
1229 |
sheet.write(0, 5, "Category", heading_xf)
|
|
|
1230 |
sheet.write(0, 6, "Product Name", heading_xf)
|
|
|
1231 |
sheet.write(0, 7, "Weight", heading_xf)
|
|
|
1232 |
sheet.write(0, 8, "Courier Cost", heading_xf)
|
|
|
1233 |
sheet.write(0, 9, "Our SP", heading_xf)
|
|
|
1234 |
sheet.write(0, 10, "Promo Price", heading_xf)
|
|
|
1235 |
sheet.write(0, 11, "Is Promotion", heading_xf)
|
|
|
1236 |
sheet.write(0, 12, "Lowest Possible SP", heading_xf)
|
|
|
1237 |
sheet.write(0, 13, "Rank", heading_xf)
|
| 12639 |
kshitij.so |
1238 |
sheet.write(0, 14, "Competitive Category", heading_xf)
|
|
|
1239 |
sheet.write(0, 15, "Our Inventory", heading_xf)
|
|
|
1240 |
sheet.write(0, 16, "Lowest Seller SP", heading_xf)
|
|
|
1241 |
sheet.write(0, 17, "Lowest Seller Rating", heading_xf)
|
|
|
1242 |
sheet.write(0, 18, "Lowest Seller Shipping Time", heading_xf)
|
|
|
1243 |
sheet.write(0, 19, "Second Lowest Seller SP", heading_xf)
|
|
|
1244 |
sheet.write(0, 20, "Second Lowest Seller Rating", heading_xf)
|
|
|
1245 |
sheet.write(0, 21, "Second Lowest Seller Shipping Time", heading_xf)
|
|
|
1246 |
sheet.write(0, 22, "Third Lowest Seller SP", heading_xf)
|
|
|
1247 |
sheet.write(0, 23, "Third Lowest Seller Rating", heading_xf)
|
|
|
1248 |
sheet.write(0, 24, "Third Lowest Seller Shipping Time", heading_xf)
|
|
|
1249 |
sheet.write(0, 25, "Lowest MFN Ignored", heading_xf)
|
|
|
1250 |
sheet.write(0, 26, "Lowest MFN", heading_xf)
|
|
|
1251 |
sheet.write(0, 27, "Lowest FBA", heading_xf)
|
|
|
1252 |
sheet.write(0, 28, "Competitive Price", heading_xf)
|
|
|
1253 |
sheet.write(0, 29, "Other Cost", heading_xf)
|
|
|
1254 |
sheet.write(0, 30, "WANLC", heading_xf)
|
|
|
1255 |
sheet.write(0, 31, "Subsidy", heading_xf)
|
|
|
1256 |
sheet.write(0, 32, "Commission", heading_xf)
|
|
|
1257 |
sheet.write(0, 33, "Competitor Commission", heading_xf)
|
|
|
1258 |
sheet.write(0, 34, "Return Provision", heading_xf)
|
|
|
1259 |
sheet.write(0, 35, "Vat Rate", heading_xf)
|
|
|
1260 |
sheet.write(0, 36, "Margin", heading_xf)
|
|
|
1261 |
sheet.write(0, 37, "Proposed Sp", heading_xf)
|
|
|
1262 |
sheet.write(0, 38, "Avg Sale", heading_xf)
|
|
|
1263 |
sheet.write(0, 39, "NOD", heading_xf)
|
|
|
1264 |
sheet.write(0, 40, "Sales History", heading_xf)
|
|
|
1265 |
sheet.write(0, 41, "Decision", heading_xf)
|
|
|
1266 |
sheet.write(0, 42, "Reason", heading_xf)
|
|
|
1267 |
sheet.write(0, 43, "Updated Price", heading_xf)
|
|
|
1268 |
sheet.write(0, 44, "Proposed Margin", heading_xf)
|
|
|
1269 |
sheet.write(0, 45, "Inventory Movement Status")
|
| 12526 |
anikendra |
1270 |
|
|
|
1271 |
def getPackagingCost(data):
|
|
|
1272 |
#TODO : Get packagingCost from marketplaceitems table
|
|
|
1273 |
return 15
|
|
|
1274 |
|
|
|
1275 |
def getReturnCost(data):
|
|
|
1276 |
return round(data.returnProvision * data.promoPrice/100)
|
|
|
1277 |
|
|
|
1278 |
def getServiceTax(data):
|
|
|
1279 |
#TODO : Get service tax from marketplaceitems table
|
|
|
1280 |
return 12.36
|
|
|
1281 |
|
|
|
1282 |
def getClosingFee(data):
|
|
|
1283 |
myClosingFee = 0
|
| 12556 |
anikendra |
1284 |
return myClosingFee*(1+getServiceTax(data)/100)
|
| 12526 |
anikendra |
1285 |
|
|
|
1286 |
def getCommission(data):
|
| 12556 |
anikendra |
1287 |
return (data.commission * data.promoPrice/100)*(1+getServiceTax(data)/100)
|
| 12526 |
anikendra |
1288 |
|
|
|
1289 |
def getCourierCost(data):
|
| 12556 |
anikendra |
1290 |
return data.courierCost*(1+getServiceTax(data)/100)
|
| 12526 |
anikendra |
1291 |
|
| 12556 |
anikendra |
1292 |
def getCostToAmazon(data):
|
|
|
1293 |
myCostToAmazon = round(data.promoPrice*data.commission/100*(1+getServiceTax(data)/100)+getCourierCost(data)*(1+getServiceTax(data)/100))
|
|
|
1294 |
return myCostToAmazon
|
|
|
1295 |
|
| 12639 |
kshitij.so |
1296 |
def getInventoryMovementStatus(amScraping):
|
|
|
1297 |
try:
|
| 12659 |
kshitij.so |
1298 |
nodStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
| 12643 |
kshitij.so |
1299 |
except Exception as e:
|
|
|
1300 |
print "exception in nod stock"
|
|
|
1301 |
print e
|
|
|
1302 |
nodStock = float("inf")
|
| 12639 |
kshitij.so |
1303 |
try:
|
|
|
1304 |
if amScraping.avgSale==0:
|
|
|
1305 |
return "Not Moving"
|
| 12659 |
kshitij.so |
1306 |
elif nodStock > 20:
|
| 12639 |
kshitij.so |
1307 |
return "Slow Moving"
|
|
|
1308 |
else:
|
| 12659 |
kshitij.so |
1309 |
return "Moving"
|
| 12643 |
kshitij.so |
1310 |
except Exception as e:
|
|
|
1311 |
print e
|
|
|
1312 |
print "exception in ims"
|
| 12639 |
kshitij.so |
1313 |
return ""
|
|
|
1314 |
|
| 12526 |
anikendra |
1315 |
def getMargin(amScraping):
|
|
|
1316 |
#sheet.write(sheet_iterator, 30, round(amScraping.promoPrice - amScraping.lowestPossibleSp))
|
|
|
1317 |
#Promo Price minus costs plus subsidy
|
|
|
1318 |
#costs = WANLC (actual or overrrde whichever is applicable) + Courier cost + Closing fee + Commission + Packaging + VAT + Returns Cost + other cost.
|
| 12556 |
anikendra |
1319 |
'''
|
| 12526 |
anikendra |
1320 |
if(amScraping.ourSellingPrice >= amScraping.promoPrice):
|
|
|
1321 |
mySubsidy = amScraping.subsidy
|
|
|
1322 |
else:
|
|
|
1323 |
mySubsidy = 0
|
| 12556 |
anikendra |
1324 |
'''
|
| 12526 |
anikendra |
1325 |
print 'promo price ',amScraping.promoPrice
|
| 12556 |
anikendra |
1326 |
#print 'mySubsidy ',mySubsidy
|
| 12526 |
anikendra |
1327 |
print 'wanlc ',amScraping.wanlc
|
|
|
1328 |
print 'courier cost ',getCourierCost(amScraping)
|
|
|
1329 |
print 'closing fee ',getClosingFee(amScraping)
|
|
|
1330 |
print 'commission ',getCommission(amScraping)
|
|
|
1331 |
print 'packaging ',getPackagingCost(amScraping)
|
|
|
1332 |
print 'vat ',getVat(amScraping)
|
|
|
1333 |
print 'return cost ',getReturnCost(amScraping)
|
|
|
1334 |
print 'other cost ',amScraping.otherCost
|
| 12556 |
anikendra |
1335 |
print 'cost to amazon ',getCostToAmazon(amScraping)
|
| 12526 |
anikendra |
1336 |
myCosts = amScraping.wanlc + getCourierCost(amScraping) + getClosingFee(amScraping) + getCommission(amScraping) + getPackagingCost(amScraping) + getVat(amScraping) + getReturnCost(amScraping) + amScraping.otherCost
|
| 12556 |
anikendra |
1337 |
margin = amScraping.promoPrice - myCosts + amScraping.subsidy
|
|
|
1338 |
print 'margin for ',amScraping.item_id,' is ',margin
|
| 12526 |
anikendra |
1339 |
return round(margin)
|
|
|
1340 |
|
|
|
1341 |
def getVat(data):
|
|
|
1342 |
#VAT amount = Promo Price/(1+Vat Rate)*VAT Rate minus NLC/(1+VAT Rate)*VAT Rate
|
|
|
1343 |
myVatPercentage = data.vatRate/100
|
|
|
1344 |
myVat = myVatPercentage*(data.promoPrice/(1+myVatPercentage) - data.wanlc/(1+myVatPercentage))
|
|
|
1345 |
if(myVat<0):
|
|
|
1346 |
return 0
|
|
|
1347 |
else:
|
|
|
1348 |
return round(myVat)
|
|
|
1349 |
|
|
|
1350 |
def getCategory(data):
|
|
|
1351 |
return categoryMap[data.category]
|
|
|
1352 |
|
| 12444 |
kshitij.so |
1353 |
def writeReport(timestamp,autoDecreaseItems,autoIncreaseItems,previousAutoFav,nowAutoFav,runType):
|
| 12396 |
kshitij.so |
1354 |
wbk = xlwt.Workbook()
|
|
|
1355 |
sheet = wbk.add_sheet('Can\'t Compete')
|
|
|
1356 |
xstr = lambda s: s or ""
|
|
|
1357 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
1358 |
|
|
|
1359 |
excel_integer_format = '0'
|
|
|
1360 |
integer_style = xlwt.XFStyle()
|
|
|
1361 |
integer_style.num_format_str = excel_integer_format
|
| 12526 |
anikendra |
1362 |
writeheaders(sheet,heading_xf)
|
|
|
1363 |
'''
|
| 12396 |
kshitij.so |
1364 |
sheet.write(0, 0, "Item Id", heading_xf)
|
|
|
1365 |
sheet.write(0, 1, "Amazon Sku", heading_xf)
|
|
|
1366 |
sheet.write(0, 2, "Asin", heading_xf)
|
|
|
1367 |
sheet.write(0, 3, "Location", heading_xf)
|
|
|
1368 |
sheet.write(0, 4, "Brand", heading_xf)
|
|
|
1369 |
sheet.write(0, 5, "Product Name", heading_xf)
|
|
|
1370 |
sheet.write(0, 6, "Weight", heading_xf)
|
|
|
1371 |
sheet.write(0, 7, "Courier Cost", heading_xf)
|
|
|
1372 |
sheet.write(0, 8, "Our SP", heading_xf)
|
| 12432 |
kshitij.so |
1373 |
sheet.write(0, 9, "Promo Price", heading_xf)
|
|
|
1374 |
sheet.write(0, 10, "Is Promotion", heading_xf)
|
|
|
1375 |
sheet.write(0, 11, "Lowest Possible SP", heading_xf)
|
| 12396 |
kshitij.so |
1376 |
sheet.write(0, 12, "Rank", heading_xf)
|
|
|
1377 |
sheet.write(0, 13, "Our Inventory", heading_xf)
|
| 12432 |
kshitij.so |
1378 |
sheet.write(0, 14, "Lowest Seller SP", heading_xf)
|
|
|
1379 |
sheet.write(0, 15, "Lowest Seller Rating", heading_xf)
|
|
|
1380 |
sheet.write(0, 16, "Lowest Seller Shipping Time", heading_xf)
|
| 12396 |
kshitij.so |
1381 |
sheet.write(0, 17, "Second Lowest Seller SP", heading_xf)
|
| 12432 |
kshitij.so |
1382 |
sheet.write(0, 18, "Second Lowest Seller Rating", heading_xf)
|
|
|
1383 |
sheet.write(0, 19, "Second Lowest Seller Shipping Time", heading_xf)
|
|
|
1384 |
sheet.write(0, 20, "Third Lowest Seller SP", heading_xf)
|
|
|
1385 |
sheet.write(0, 21, "Third Lowest Seller Rating", heading_xf)
|
|
|
1386 |
sheet.write(0, 22, "Third Lowest Seller Shipping Time", heading_xf)
|
| 12447 |
kshitij.so |
1387 |
sheet.write(0, 23, "Other Cost", heading_xf)
|
|
|
1388 |
sheet.write(0, 24, "WANLC", heading_xf)
|
| 12526 |
anikendra |
1389 |
sheet.write(0, 25, "Subsidy", heading_xf)
|
|
|
1390 |
sheet.write(0, 26, "Commission", heading_xf)
|
|
|
1391 |
sheet.write(0, 27, "Competitor Commission", heading_xf)
|
|
|
1392 |
sheet.write(0, 28, "Return Provision", heading_xf)
|
|
|
1393 |
sheet.write(0, 29, "Vat Rate", heading_xf)
|
|
|
1394 |
sheet.write(0, 30, "Margin", heading_xf)
|
|
|
1395 |
sheet.write(0, 31, "Risky", heading_xf)
|
|
|
1396 |
sheet.write(0, 32, "Proposed Sp", heading_xf)
|
|
|
1397 |
sheet.write(0, 33, "Avg Sale", heading_xf)
|
|
|
1398 |
sheet.write(0, 34, "Sales History", heading_xf)
|
|
|
1399 |
'''
|
| 12396 |
kshitij.so |
1400 |
sheet_iterator = 1
|
| 12476 |
kshitij.so |
1401 |
cantCompeteItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1402 |
for cantCompeteItem in cantCompeteItems:
|
|
|
1403 |
amScraping = cantCompeteItem[0]
|
|
|
1404 |
item = cantCompeteItem[1]
|
| 12556 |
anikendra |
1405 |
print "Item = ",item
|
| 12396 |
kshitij.so |
1406 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1407 |
if amScraping.warehouseLocation == 1:
|
|
|
1408 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1409 |
loc = 'MUMBAI'
|
|
|
1410 |
else:
|
|
|
1411 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1412 |
loc = 'BANGLORE'
|
|
|
1413 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1414 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1415 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1416 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1417 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1418 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1419 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1420 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1421 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1422 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1423 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1424 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1425 |
else:
|
| 12526 |
anikendra |
1426 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1427 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1428 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1429 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1430 |
else:
|
| 12526 |
anikendra |
1431 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1432 |
sheet.write(sheet_iterator, 14, 'Cant Compete')
|
|
|
1433 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1434 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1435 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1436 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1437 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1438 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1439 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1440 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1441 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1442 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1443 |
sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
|
|
|
1444 |
sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
|
|
|
1445 |
sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
|
|
|
1446 |
sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
|
|
|
1447 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1448 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1449 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1450 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1451 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1452 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1453 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1454 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1455 |
sheet.write(sheet_iterator, 37, amScraping.proposedSp)
|
|
|
1456 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1457 |
try:
|
|
|
1458 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1459 |
except:
|
|
|
1460 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1461 |
if str(daysOfStock)=='inf':
|
|
|
1462 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1463 |
else:
|
|
|
1464 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1465 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
| 12643 |
kshitij.so |
1466 |
#sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
| 12639 |
kshitij.so |
1467 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1468 |
sheet_iterator+=1
|
| 12597 |
kshitij.so |
1469 |
#TODO : Take excell sheet generation code inside a function
|
| 12476 |
kshitij.so |
1470 |
competitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.COMPETITIVE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1471 |
for competitiveItem in competitiveItems:
|
|
|
1472 |
amScraping = competitiveItem[0]
|
|
|
1473 |
item = competitiveItem[1]
|
|
|
1474 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1475 |
if amScraping.warehouseLocation == 1:
|
|
|
1476 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1477 |
loc = 'MUMBAI'
|
|
|
1478 |
else:
|
|
|
1479 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1480 |
loc = 'BANGLORE'
|
|
|
1481 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1482 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1483 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1484 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1485 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1486 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1487 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1488 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1489 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1490 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1491 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1492 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1493 |
else:
|
| 12526 |
anikendra |
1494 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1495 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1496 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1497 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1498 |
else:
|
| 12526 |
anikendra |
1499 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1500 |
sheet.write(sheet_iterator, 14, 'Competitive')
|
|
|
1501 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1502 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1503 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1504 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1505 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1506 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1507 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1508 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1509 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1510 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1511 |
sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
|
|
|
1512 |
sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
|
|
|
1513 |
sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
|
|
|
1514 |
sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
|
|
|
1515 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1516 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1517 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1518 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1519 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1520 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1521 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1522 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1523 |
sheet.write(sheet_iterator, 37, amScraping.proposedSp)
|
|
|
1524 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1525 |
try:
|
|
|
1526 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1527 |
except:
|
|
|
1528 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1529 |
if str(daysOfStock)=='inf':
|
|
|
1530 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1531 |
else:
|
|
|
1532 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1533 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
| 12444 |
kshitij.so |
1534 |
if amScraping.decision is None:
|
| 12639 |
kshitij.so |
1535 |
sheet.write(sheet_iterator, 41, 'Auto Pricing Inactive')
|
| 12652 |
kshitij.so |
1536 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1537 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12444 |
kshitij.so |
1538 |
sheet_iterator+=1
|
|
|
1539 |
continue
|
| 12639 |
kshitij.so |
1540 |
sheet.write(sheet_iterator, 41, Decision._VALUES_TO_NAMES.get(amScraping.decision))
|
|
|
1541 |
sheet.write(sheet_iterator, 42, amScraping.reason)
|
| 12444 |
kshitij.so |
1542 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1543 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.proposedSp))
|
| 12444 |
kshitij.so |
1544 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1545 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
|
|
1546 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1547 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1548 |
sheet_iterator+=1
|
|
|
1549 |
|
| 12476 |
kshitij.so |
1550 |
almostCompetitiveItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.ALMOST_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1551 |
for almostCompetitiveItem in almostCompetitiveItems:
|
|
|
1552 |
amScraping = almostCompetitiveItem[0]
|
|
|
1553 |
item = almostCompetitiveItem[1]
|
|
|
1554 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1555 |
if amScraping.warehouseLocation == 1:
|
|
|
1556 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1557 |
loc = 'MUMBAI'
|
|
|
1558 |
else:
|
|
|
1559 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1560 |
loc = 'BANGLORE'
|
|
|
1561 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1562 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1563 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1564 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1565 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1566 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1567 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1568 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1569 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1570 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1571 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1572 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1573 |
else:
|
| 12526 |
anikendra |
1574 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1575 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1576 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1577 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1578 |
else:
|
| 12526 |
anikendra |
1579 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1580 |
sheet.write(sheet_iterator, 14, 'Almost Competitive')
|
|
|
1581 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1582 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1583 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1584 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1585 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1586 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1587 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1588 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1589 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1590 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1591 |
sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
|
|
|
1592 |
sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
|
|
|
1593 |
sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
|
|
|
1594 |
sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
|
|
|
1595 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1596 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1597 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1598 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1599 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1600 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1601 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1602 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1603 |
sheet.write(sheet_iterator, 37, amScraping.proposedSp)
|
|
|
1604 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1605 |
try:
|
|
|
1606 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1607 |
except:
|
|
|
1608 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1609 |
if str(daysOfStock)=='inf':
|
|
|
1610 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1611 |
else:
|
|
|
1612 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1613 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
| 12444 |
kshitij.so |
1614 |
if amScraping.decision is None:
|
| 12639 |
kshitij.so |
1615 |
sheet.write(sheet_iterator, 41, 'Auto Pricing Inactive')
|
| 12652 |
kshitij.so |
1616 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1617 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12444 |
kshitij.so |
1618 |
sheet_iterator+=1
|
|
|
1619 |
continue
|
| 12639 |
kshitij.so |
1620 |
sheet.write(sheet_iterator, 41, Decision._VALUES_TO_NAMES.get(amScraping.decision))
|
|
|
1621 |
sheet.write(sheet_iterator, 42, amScraping.reason)
|
| 12444 |
kshitij.so |
1622 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1623 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.proposedSp))
|
| 12444 |
kshitij.so |
1624 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1625 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
|
|
1626 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1627 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1628 |
sheet_iterator+=1
|
|
|
1629 |
|
| 12476 |
kshitij.so |
1630 |
amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.AMONG_CHEAPEST_CAN_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1631 |
for amongCheapestItem in amongCheapestItems:
|
|
|
1632 |
amScraping = amongCheapestItem[0]
|
|
|
1633 |
item = amongCheapestItem[1]
|
|
|
1634 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1635 |
if amScraping.warehouseLocation == 1:
|
|
|
1636 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1637 |
loc = 'MUMBAI'
|
|
|
1638 |
else:
|
|
|
1639 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1640 |
loc = 'BANGLORE'
|
|
|
1641 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1642 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1643 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1644 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1645 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1646 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1647 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1648 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1649 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1650 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1651 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1652 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1653 |
else:
|
| 12526 |
anikendra |
1654 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1655 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1656 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1657 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1658 |
else:
|
| 12526 |
anikendra |
1659 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1660 |
sheet.write(sheet_iterator, 14, 'Among Cheapest')
|
|
|
1661 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1662 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1663 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1664 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1665 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1666 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1667 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1668 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1669 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1670 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1671 |
sheet.write(sheet_iterator, 25, amScraping.lowestMfnIgnoredOffer)
|
|
|
1672 |
sheet.write(sheet_iterator, 26, amScraping.lowestMfnOffer)
|
|
|
1673 |
sheet.write(sheet_iterator, 27, amScraping.lowestFbaOffer)
|
|
|
1674 |
sheet.write(sheet_iterator, 28, amScraping.competitivePrice)
|
|
|
1675 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1676 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1677 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1678 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1679 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1680 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1681 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1682 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1683 |
sheet.write(sheet_iterator, 37, amScraping.proposedSp)
|
|
|
1684 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1685 |
try:
|
|
|
1686 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1687 |
except:
|
|
|
1688 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1689 |
if str(daysOfStock)=='inf':
|
|
|
1690 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1691 |
else:
|
|
|
1692 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1693 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
| 12444 |
kshitij.so |
1694 |
if amScraping.decision is None:
|
| 12639 |
kshitij.so |
1695 |
sheet.write(sheet_iterator, 41, 'Auto Pricing Inactive')
|
| 12652 |
kshitij.so |
1696 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1697 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12444 |
kshitij.so |
1698 |
sheet_iterator+=1
|
|
|
1699 |
continue
|
| 12639 |
kshitij.so |
1700 |
sheet.write(sheet_iterator, 41, Decision._VALUES_TO_NAMES.get(amScraping.decision))
|
|
|
1701 |
sheet.write(sheet_iterator, 42, amScraping.reason)
|
| 12444 |
kshitij.so |
1702 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1703 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.proposedSp))
|
| 12444 |
kshitij.so |
1704 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1705 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
|
|
1706 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1707 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1708 |
sheet_iterator+=1
|
|
|
1709 |
|
| 12639 |
kshitij.so |
1710 |
# sheet = wbk.add_sheet('Cheapest')
|
|
|
1711 |
# xstr = lambda s: s or ""
|
|
|
1712 |
# heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
1713 |
#
|
|
|
1714 |
# excel_integer_format = '0'
|
|
|
1715 |
# integer_style = xlwt.XFStyle()
|
|
|
1716 |
# integer_style.num_format_str = excel_integer_format
|
|
|
1717 |
# sheet.write(0, 0, "Item Id", heading_xf)
|
|
|
1718 |
# sheet.write(0, 1, "Amazon Sku", heading_xf)
|
|
|
1719 |
# sheet.write(0, 2, "Asin", heading_xf)
|
|
|
1720 |
# sheet.write(0, 3, "Location", heading_xf)
|
|
|
1721 |
# sheet.write(0, 4, "Brand", heading_xf)
|
|
|
1722 |
# sheet.write(0, 5, "Category", heading_xf)
|
|
|
1723 |
# sheet.write(0, 6, "Product Name", heading_xf)
|
|
|
1724 |
# sheet.write(0, 7, "Weight", heading_xf)
|
|
|
1725 |
# sheet.write(0, 8, "Courier Cost", heading_xf)
|
|
|
1726 |
# sheet.write(0, 9, "Our SP", heading_xf)
|
|
|
1727 |
# sheet.write(0, 10, "Promo Price", heading_xf)
|
|
|
1728 |
# sheet.write(0, 11, "Is Promotion", heading_xf)
|
|
|
1729 |
# sheet.write(0, 12, "Lowest Possible SP", heading_xf)
|
|
|
1730 |
# sheet.write(0, 13, "Rank", heading_xf)
|
|
|
1731 |
# sheet.write(0, 14, "Our Inventory", heading_xf)
|
|
|
1732 |
# sheet.write(0, 15, "Lowest Seller SP", heading_xf)
|
|
|
1733 |
# sheet.write(0, 16, "Lowest Seller Rating", heading_xf)
|
|
|
1734 |
# sheet.write(0, 17, "Lowest Seller Shipping Time", heading_xf)
|
|
|
1735 |
# sheet.write(0, 18, "Second Lowest Seller SP", heading_xf)
|
|
|
1736 |
# sheet.write(0, 19, "Second Lowest Seller Rating", heading_xf)
|
|
|
1737 |
# sheet.write(0, 20, "Second Lowest Seller Shipping Time", heading_xf)
|
|
|
1738 |
# sheet.write(0, 21, "Third Lowest Seller SP", heading_xf)
|
|
|
1739 |
# sheet.write(0, 22, "Third Lowest Seller Rating", heading_xf)
|
|
|
1740 |
# sheet.write(0, 23, "Third Lowest Seller Shipping Time", heading_xf)
|
|
|
1741 |
# sheet.write(0, 24, "Other Cost", heading_xf)
|
|
|
1742 |
# sheet.write(0, 25, "WANLC", heading_xf)
|
|
|
1743 |
# sheet.write(0, 26, "Subsidy", heading_xf)
|
|
|
1744 |
# sheet.write(0, 27, "Commission", heading_xf)
|
|
|
1745 |
# sheet.write(0, 28, "Competitor Commission", heading_xf)
|
|
|
1746 |
# sheet.write(0, 29, "Return Provision", heading_xf)
|
|
|
1747 |
# sheet.write(0, 30, "Vat Rate", heading_xf)
|
|
|
1748 |
# sheet.write(0, 31, "Margin", heading_xf)
|
|
|
1749 |
# sheet.write(0, 32, "Proposed Sp", heading_xf)
|
|
|
1750 |
# sheet.write(0, 33, "Avg Sale", heading_xf)
|
|
|
1751 |
# sheet.write(0, 34, "Sales History", heading_xf)
|
|
|
1752 |
# sheet.write(0, 35, "Decision", heading_xf)
|
|
|
1753 |
# sheet.write(0, 36, "Reason", heading_xf)
|
|
|
1754 |
# sheet.write(0, 37, "Updated Price", heading_xf)
|
|
|
1755 |
# sheet_iterator = 1
|
| 12476 |
kshitij.so |
1756 |
cheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.BUY_BOX).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1757 |
for cheapestItem in cheapestItems:
|
|
|
1758 |
amScraping = cheapestItem[0]
|
|
|
1759 |
item = cheapestItem[1]
|
|
|
1760 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1761 |
if amScraping.warehouseLocation == 1:
|
|
|
1762 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1763 |
loc = 'MUMBAI'
|
|
|
1764 |
else:
|
|
|
1765 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1766 |
loc = 'BANGLORE'
|
|
|
1767 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1768 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1769 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1770 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1771 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1772 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1773 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1774 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1775 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1776 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1777 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1778 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1779 |
else:
|
| 12526 |
anikendra |
1780 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1781 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1782 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1783 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1784 |
else:
|
| 12526 |
anikendra |
1785 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1786 |
sheet.write(sheet_iterator, 14, 'Cheapest')
|
|
|
1787 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1788 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1789 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1790 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1791 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1792 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1793 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1794 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1795 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1796 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1797 |
sheet.write(sheet_iterator, 25, '')
|
|
|
1798 |
sheet.write(sheet_iterator, 26, '')
|
|
|
1799 |
sheet.write(sheet_iterator, 27, '')
|
|
|
1800 |
sheet.write(sheet_iterator, 28, '')
|
|
|
1801 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1802 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1803 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1804 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1805 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1806 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1807 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1808 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1809 |
sheet.write(sheet_iterator, 37, amScraping.proposedSp)
|
|
|
1810 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1811 |
try:
|
|
|
1812 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1813 |
except:
|
|
|
1814 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1815 |
if str(daysOfStock)=='inf':
|
|
|
1816 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1817 |
else:
|
|
|
1818 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1819 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
| 12444 |
kshitij.so |
1820 |
if amScraping.decision is None:
|
| 12639 |
kshitij.so |
1821 |
sheet.write(sheet_iterator, 41, 'Auto Pricing Inactive')
|
| 12652 |
kshitij.so |
1822 |
sheet.write(sheet_iterator, 44, round(amScraping.proposedSp - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,amScraping.proposedSp))))
|
|
|
1823 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12444 |
kshitij.so |
1824 |
sheet_iterator+=1
|
|
|
1825 |
continue
|
| 12639 |
kshitij.so |
1826 |
sheet.write(sheet_iterator, 41, Decision._VALUES_TO_NAMES.get(amScraping.decision))
|
|
|
1827 |
sheet.write(sheet_iterator, 42, amScraping.reason)
|
| 12444 |
kshitij.so |
1828 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_DECREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1829 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.proposedSp))
|
| 12444 |
kshitij.so |
1830 |
if Decision._VALUES_TO_NAMES.get(amScraping.decision) == "AUTO_INCREMENT_SUCCESS":
|
| 12639 |
kshitij.so |
1831 |
sheet.write(sheet_iterator, 43, math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)))
|
|
|
1832 |
sheet.write(sheet_iterator, 44, round(math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice)) - getNewLowestPossibleSp(amScraping,12.36,getNewVatRate(amScraping.item_id,amScraping.warehouseLocation,math.ceil(amScraping.promoPrice+max(10,.01*amScraping.promoPrice))))))
|
|
|
1833 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1834 |
sheet_iterator+=1
|
|
|
1835 |
|
| 12639 |
kshitij.so |
1836 |
# sheet = wbk.add_sheet('Negative Margin')
|
|
|
1837 |
# xstr = lambda s: s or ""
|
|
|
1838 |
# heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
1839 |
#
|
|
|
1840 |
# excel_integer_format = '0'
|
|
|
1841 |
# integer_style = xlwt.XFStyle()
|
|
|
1842 |
# integer_style.num_format_str = excel_integer_format
|
|
|
1843 |
# sheet.write(0, 0, "Item Id", heading_xf)
|
|
|
1844 |
# sheet.write(0, 1, "Amazon Sku", heading_xf)
|
|
|
1845 |
# sheet.write(0, 2, "Asin", heading_xf)
|
|
|
1846 |
# sheet.write(0, 3, "Location", heading_xf)
|
|
|
1847 |
# sheet.write(0, 4, "Brand", heading_xf)
|
|
|
1848 |
# sheet.write(0, 5, "Category", heading_xf)
|
|
|
1849 |
# sheet.write(0, 6, "Product Name", heading_xf)
|
|
|
1850 |
# sheet.write(0, 7, "Weight", heading_xf)
|
|
|
1851 |
# sheet.write(0, 8, "Courier Cost", heading_xf)
|
|
|
1852 |
# sheet.write(0, 9, "Our SP", heading_xf)
|
|
|
1853 |
# sheet.write(0, 10, "Promo Price", heading_xf)
|
|
|
1854 |
# sheet.write(0, 11, "Is Promotion", heading_xf)
|
|
|
1855 |
# sheet.write(0, 12, "Lowest Possible SP", heading_xf)
|
|
|
1856 |
# sheet.write(0, 13, "Rank", heading_xf)
|
|
|
1857 |
# sheet.write(0, 14, "Our Inventory", heading_xf)
|
|
|
1858 |
# sheet.write(0, 15, "Lowest Seller SP", heading_xf)
|
|
|
1859 |
# sheet.write(0, 16, "Lowest Seller Rating", heading_xf)
|
|
|
1860 |
# sheet.write(0, 17, "Lowest Seller Shipping Time", heading_xf)
|
|
|
1861 |
# sheet.write(0, 18, "Second Lowest Seller SP", heading_xf)
|
|
|
1862 |
# sheet.write(0, 19, "Second Lowest Seller Rating", heading_xf)
|
|
|
1863 |
# sheet.write(0, 20, "Second Lowest Seller Shipping Time", heading_xf)
|
|
|
1864 |
# sheet.write(0, 21, "Third Lowest Seller SP", heading_xf)
|
|
|
1865 |
# sheet.write(0, 22, "Third Lowest Seller Rating", heading_xf)
|
|
|
1866 |
# sheet.write(0, 23, "Third Lowest Seller Shipping Time", heading_xf)
|
|
|
1867 |
# sheet.write(0, 24, "Other Cost", heading_xf)
|
|
|
1868 |
# sheet.write(0, 25, "WANLC", heading_xf)
|
|
|
1869 |
# sheet.write(0, 26, "Subsidy", heading_xf)
|
|
|
1870 |
# sheet.write(0, 27, "Commission", heading_xf)
|
|
|
1871 |
# sheet.write(0, 28, "Competitor Commission", heading_xf)
|
|
|
1872 |
# sheet.write(0, 29, "Return Provision", heading_xf)
|
|
|
1873 |
# sheet.write(0, 30, "Vat Rate", heading_xf)
|
|
|
1874 |
# sheet.write(0, 31, "Margin", heading_xf)
|
|
|
1875 |
# sheet.write(0, 32, "Avg Sale", heading_xf)
|
|
|
1876 |
# sheet.write(0, 33, "Sales History", heading_xf)
|
|
|
1877 |
#
|
|
|
1878 |
# sheet_iterator = 1
|
|
|
1879 |
negativeMargins = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.NEGATIVE_MARGIN).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
|
|
1880 |
for negativeMarginItem in negativeMargins:
|
|
|
1881 |
amScraping = negativeMarginItem[0]
|
|
|
1882 |
item = negativeMarginItem[1]
|
| 12396 |
kshitij.so |
1883 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1884 |
if amScraping.warehouseLocation == 1:
|
|
|
1885 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1886 |
loc = 'MUMBAI'
|
|
|
1887 |
else:
|
|
|
1888 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1889 |
loc = 'BANGLORE'
|
|
|
1890 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1891 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1892 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1893 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1894 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1895 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
|
|
1896 |
sheet.write(sheet_iterator, 7, item.weight)
|
|
|
1897 |
sheet.write(sheet_iterator, 8, amScraping.courierCost)
|
|
|
1898 |
sheet.write(sheet_iterator, 9, amScraping.ourSellingPrice)
|
|
|
1899 |
sheet.write(sheet_iterator, 10, amScraping.promoPrice)
|
| 12432 |
kshitij.so |
1900 |
if amScraping.isPromotion:
|
| 12526 |
anikendra |
1901 |
sheet.write(sheet_iterator, 11, "Yes")
|
| 12432 |
kshitij.so |
1902 |
else:
|
| 12526 |
anikendra |
1903 |
sheet.write(sheet_iterator, 11, "No")
|
|
|
1904 |
sheet.write(sheet_iterator, 12, amScraping.lowestPossibleSp)
|
| 12396 |
kshitij.so |
1905 |
if amScraping.ourRank > 3:
|
| 12526 |
anikendra |
1906 |
sheet.write(sheet_iterator, 13, 'Greater than 3')
|
| 12396 |
kshitij.so |
1907 |
else:
|
| 12526 |
anikendra |
1908 |
sheet.write(sheet_iterator, 13, amScraping.ourRank)
|
| 12639 |
kshitij.so |
1909 |
sheet.write(sheet_iterator, 14, 'Negative Margin')
|
|
|
1910 |
sheet.write(sheet_iterator, 15, amScraping.ourInventory)
|
|
|
1911 |
sheet.write(sheet_iterator, 16, amScraping.lowestSellerSp)
|
|
|
1912 |
sheet.write(sheet_iterator, 17, amScraping.lowestSellerRating)
|
|
|
1913 |
sheet.write(sheet_iterator, 18, amScraping.lowestSellerShippingTime)
|
|
|
1914 |
sheet.write(sheet_iterator, 19, amScraping.secondLowestSellerSp)
|
|
|
1915 |
sheet.write(sheet_iterator, 20, amScraping.secondLowestSellerRating)
|
|
|
1916 |
sheet.write(sheet_iterator, 21, amScraping.secondLowestSellerShippingTime)
|
|
|
1917 |
sheet.write(sheet_iterator, 22, amScraping.thirdLowestSellerSp)
|
|
|
1918 |
sheet.write(sheet_iterator, 23, amScraping.thirdLowestSellerRating)
|
|
|
1919 |
sheet.write(sheet_iterator, 24, amScraping.thirdLowestSellerShippingTime)
|
|
|
1920 |
sheet.write(sheet_iterator, 25, '')
|
|
|
1921 |
sheet.write(sheet_iterator, 26, '')
|
|
|
1922 |
sheet.write(sheet_iterator, 27, '')
|
|
|
1923 |
sheet.write(sheet_iterator, 28, '')
|
|
|
1924 |
sheet.write(sheet_iterator, 29, amScraping.otherCost)
|
|
|
1925 |
sheet.write(sheet_iterator, 30, amScraping.wanlc)
|
|
|
1926 |
sheet.write(sheet_iterator, 31, amScraping.subsidy)
|
|
|
1927 |
sheet.write(sheet_iterator, 32, amScraping.commission)
|
|
|
1928 |
sheet.write(sheet_iterator, 33, amScraping.competitorCommission)
|
|
|
1929 |
sheet.write(sheet_iterator, 34, amScraping.returnProvision)
|
|
|
1930 |
sheet.write(sheet_iterator, 35, amScraping.vatRate)
|
|
|
1931 |
sheet.write(sheet_iterator, 36, getMargin(amScraping))
|
|
|
1932 |
sheet.write(sheet_iterator, 38, amScraping.avgSale)
|
|
|
1933 |
try:
|
|
|
1934 |
daysOfStock = (float(amScraping.ourInventory))/amScraping.avgSale
|
|
|
1935 |
except:
|
|
|
1936 |
daysOfStock = float("inf")
|
| 12652 |
kshitij.so |
1937 |
if str(daysOfStock)=='inf':
|
|
|
1938 |
sheet.write(sheet_iterator, 39, str(daysOfStock))
|
|
|
1939 |
else:
|
|
|
1940 |
sheet.write(sheet_iterator, 39, str(round(daysOfStock,1)))
|
| 12639 |
kshitij.so |
1941 |
sheet.write(sheet_iterator, 40, getOosString(saleMap.get(sku)))
|
|
|
1942 |
sheet.write(sheet_iterator, 45, getInventoryMovementStatus(amScraping))
|
| 12396 |
kshitij.so |
1943 |
sheet_iterator+=1
|
|
|
1944 |
|
|
|
1945 |
sheet = wbk.add_sheet('Exception List')
|
|
|
1946 |
xstr = lambda s: s or ""
|
|
|
1947 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
1948 |
|
|
|
1949 |
excel_integer_format = '0'
|
|
|
1950 |
integer_style = xlwt.XFStyle()
|
|
|
1951 |
integer_style.num_format_str = excel_integer_format
|
|
|
1952 |
|
|
|
1953 |
sheet.write(0, 0, "Item Id", heading_xf)
|
|
|
1954 |
sheet.write(0, 1, "Amazon Sku", heading_xf)
|
|
|
1955 |
sheet.write(0, 2, "Asin", heading_xf)
|
|
|
1956 |
sheet.write(0, 3, "Location", heading_xf)
|
|
|
1957 |
sheet.write(0, 4, "Brand", heading_xf)
|
| 12526 |
anikendra |
1958 |
sheet.write(0, 5, "Category", heading_xf)
|
|
|
1959 |
sheet.write(0, 6, "Product Name", heading_xf)
|
| 12639 |
kshitij.so |
1960 |
sheet.write(0, 7, "Selling Price", heading_xf)
|
|
|
1961 |
sheet.write(0, 8, "Promo Price", heading_xf)
|
|
|
1962 |
sheet.write(0, 9, "Reason", heading_xf)
|
| 12396 |
kshitij.so |
1963 |
|
|
|
1964 |
sheet_iterator = 1
|
| 12476 |
kshitij.so |
1965 |
amongCheapestItems = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.EXCEPTION).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12396 |
kshitij.so |
1966 |
for amongCheapestItem in amongCheapestItems:
|
|
|
1967 |
amScraping = amongCheapestItem[0]
|
|
|
1968 |
item = amongCheapestItem[1]
|
|
|
1969 |
sheet.write(sheet_iterator, 0, amScraping.item_id)
|
|
|
1970 |
if amScraping.warehouseLocation == 1:
|
|
|
1971 |
sku = 'FBA'+str(amScraping.item_id)
|
|
|
1972 |
loc = 'MUMBAI'
|
|
|
1973 |
else:
|
|
|
1974 |
sku = 'FBB'+str(amScraping.item_id)
|
|
|
1975 |
loc = 'BANGLORE'
|
|
|
1976 |
sheet.write(sheet_iterator, 1, sku)
|
| 12471 |
kshitij.so |
1977 |
sheet.write(sheet_iterator, 2, amScraping.asin)
|
| 12396 |
kshitij.so |
1978 |
sheet.write(sheet_iterator, 3, loc)
|
|
|
1979 |
sheet.write(sheet_iterator, 4, item.brand)
|
| 12526 |
anikendra |
1980 |
sheet.write(sheet_iterator, 5, getCategory(item))
|
|
|
1981 |
sheet.write(sheet_iterator, 6, xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color))
|
| 12639 |
kshitij.so |
1982 |
sheet.write(sheet_iterator, 7, amScraping.ourSellingPrice)
|
|
|
1983 |
sheet.write(sheet_iterator, 8, amScraping.promoPrice)
|
|
|
1984 |
sheet.write(sheet_iterator, 9, amScraping.reason)
|
| 12396 |
kshitij.so |
1985 |
sheet_iterator+=1
|
|
|
1986 |
|
| 12444 |
kshitij.so |
1987 |
|
| 12639 |
kshitij.so |
1988 |
if (runType in ('FULL','FULL-OTHER')):
|
| 12444 |
kshitij.so |
1989 |
sheet = wbk.add_sheet('Auto Favorites')
|
|
|
1990 |
|
|
|
1991 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
1992 |
|
|
|
1993 |
excel_integer_format = '0'
|
|
|
1994 |
integer_style = xlwt.XFStyle()
|
|
|
1995 |
integer_style.num_format_str = excel_integer_format
|
|
|
1996 |
xstr = lambda s: s or ""
|
|
|
1997 |
|
|
|
1998 |
sheet.write(0, 0, "Item ID", heading_xf)
|
|
|
1999 |
sheet.write(0, 1, "Brand", heading_xf)
|
|
|
2000 |
sheet.write(0, 2, "Product Name", heading_xf)
|
|
|
2001 |
sheet.write(0, 3, "Auto Favourite", heading_xf)
|
|
|
2002 |
sheet.write(0, 4, "Reason", heading_xf)
|
|
|
2003 |
|
|
|
2004 |
sheet_iterator=1
|
|
|
2005 |
for autoFav in nowAutoFav:
|
|
|
2006 |
itemId = autoFav[0]
|
|
|
2007 |
reason = autoFav[1]
|
|
|
2008 |
it = Item.query.filter_by(id=itemId).one()
|
|
|
2009 |
sheet.write(sheet_iterator, 0, itemId)
|
|
|
2010 |
sheet.write(sheet_iterator, 1, it.brand)
|
|
|
2011 |
sheet.write(sheet_iterator, 2, xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color))
|
|
|
2012 |
sheet.write(sheet_iterator, 3, "True")
|
|
|
2013 |
sheet.write(sheet_iterator, 4, reason)
|
|
|
2014 |
sheet_iterator+=1
|
|
|
2015 |
for prevFav in previousAutoFav:
|
|
|
2016 |
it = Item.query.filter_by(id=prevFav).one()
|
|
|
2017 |
sheet.write(sheet_iterator, 0, prevFav)
|
|
|
2018 |
sheet.write(sheet_iterator, 1, it.brand)
|
|
|
2019 |
sheet.write(sheet_iterator, 2, xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color))
|
|
|
2020 |
sheet.write(sheet_iterator, 3, "False")
|
|
|
2021 |
sheet_iterator+=1
|
|
|
2022 |
|
| 12478 |
kshitij.so |
2023 |
filename = "/tmp/amazon-report-"+runType+" " + str(timestamp) + ".xls"
|
| 12396 |
kshitij.so |
2024 |
wbk.save(filename)
|
| 12489 |
kshitij.so |
2025 |
try:
|
| 12639 |
kshitij.so |
2026 |
EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@saholic.com"], " Amazon Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], [""], [])
|
|
|
2027 |
#EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["chandan.kumar@saholic.com","manoj.kumar@saholic.com","yukti.jain@saholic.com","ankush.dhingra@saholic.com","manoj.pal@saholic.com"], " Amazon Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], ["rajneesh.arora@saholic.com","anikendra.das@saholic.com","amit.gupta@saholic.com","kshitij.sood@saholic.com","chaitnaya.vats@saholic.com","khushal.bhatia@saholic.com"], [])
|
| 12489 |
kshitij.so |
2028 |
except Exception as e:
|
|
|
2029 |
print e
|
|
|
2030 |
print "Unable to send report.Trying with local SMTP"
|
|
|
2031 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
2032 |
smtpServer.set_debuglevel(1)
|
|
|
2033 |
sender = 'build@shop2020.in'
|
| 12639 |
kshitij.so |
2034 |
recipients = ["kshitij.sood@saholic.com"]
|
| 12489 |
kshitij.so |
2035 |
msg = MIMEMultipart()
|
|
|
2036 |
msg['Subject'] = "Amazon Auto Pricing" + ' '+runType+' - ' + str(datetime.now())
|
|
|
2037 |
msg['From'] = sender
|
| 12639 |
kshitij.so |
2038 |
#recipients = ['rajneesh.arora@saholic.com','anikendra.das@saholic.com','amit.gupta@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
|
| 12489 |
kshitij.so |
2039 |
msg['To'] = ",".join(recipients)
|
|
|
2040 |
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
|
|
|
2041 |
fileMsg.set_payload(file(filename).read())
|
|
|
2042 |
email.encoders.encode_base64(fileMsg)
|
|
|
2043 |
fileMsg.add_header('Content-Disposition','attachment;filename=amazon-auto-pricing.xls')
|
|
|
2044 |
msg.attach(fileMsg)
|
|
|
2045 |
try:
|
|
|
2046 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
|
|
2047 |
print "Successfully sent email"
|
|
|
2048 |
except:
|
|
|
2049 |
print "Error: unable to send email."
|
|
|
2050 |
|
|
|
2051 |
def getNewVatRate(item_id,state,price):
|
|
|
2052 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==item_id, ItemVatMaster.stateId==state)).first()
|
|
|
2053 |
if itemVatMaster is None:
|
|
|
2054 |
d_item = Item.query.filter_by(id=item_id).first()
|
|
|
2055 |
if d_item is None:
|
|
|
2056 |
raise
|
|
|
2057 |
else:
|
|
|
2058 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==d_item.category, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price, CategoryVatMaster.stateId == state)).first()
|
|
|
2059 |
if vatMaster is None:
|
|
|
2060 |
raise
|
|
|
2061 |
else:
|
|
|
2062 |
vatRate = vatMaster.vatPercent
|
|
|
2063 |
else:
|
|
|
2064 |
vatRate = itemVatMaster.vatPercentage
|
|
|
2065 |
return vatRate
|
|
|
2066 |
|
|
|
2067 |
def sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease):
|
|
|
2068 |
if len(successfulAutoDecrease)==0 and len(successfulAutoIncrease)==0 :
|
|
|
2069 |
return
|
|
|
2070 |
xstr = lambda s: s or ""
|
|
|
2071 |
message="""<html>
|
| 12502 |
kshitij.so |
2072 |
<h3 style="color:red;">Test Run.Please validate with costing sheet before taking any decision</h3>
|
| 12489 |
kshitij.so |
2073 |
<body>
|
|
|
2074 |
<h3>Auto Decrease Items</h3>
|
|
|
2075 |
<table border="1" style="width:100%;">
|
|
|
2076 |
<thead>
|
|
|
2077 |
<tr><th>Item Id</th>
|
|
|
2078 |
<th>Amazon SKU</th>
|
|
|
2079 |
<th>Product Name</th>
|
|
|
2080 |
<th>Old Price</th>
|
|
|
2081 |
<th>New Price</th>
|
|
|
2082 |
<th>Subsidy</th>
|
|
|
2083 |
<th>Old Margin</th>
|
|
|
2084 |
<th>New Margin</th>
|
|
|
2085 |
<th>Commission %</th>
|
|
|
2086 |
<th>Return Provision %</th>
|
|
|
2087 |
<th>Inventory</th>
|
|
|
2088 |
<th>Sales History</th>
|
|
|
2089 |
<th>Category</th>
|
|
|
2090 |
</tr></thead>
|
|
|
2091 |
<tbody>"""
|
|
|
2092 |
for item in successfulAutoDecrease:
|
|
|
2093 |
it = Item.query.filter_by(id=item.item_id).one()
|
|
|
2094 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,item.proposedSp)
|
| 12556 |
anikendra |
2095 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
|
|
2096 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
| 12489 |
kshitij.so |
2097 |
newMargin = round(item.proposedSp - getNewLowestPossibleSp(item,12.36,vatRate))
|
|
|
2098 |
sku = ''
|
|
|
2099 |
if item.warehouseLocation==1:
|
|
|
2100 |
sku='FBA'+str(item.item_id)
|
|
|
2101 |
else:
|
|
|
2102 |
sku='FBB'+str(item.item_id)
|
|
|
2103 |
if amazonLongTermActivePromotions.has_key(sku):
|
|
|
2104 |
subsidy = (amazonLongTermActivePromotions.get(sku)).subsidy
|
|
|
2105 |
elif amazonShortTermActivePromotions.has_key(sku):
|
|
|
2106 |
subsidy = (amazonShortTermActivePromotions.get(sku)).subsidy
|
|
|
2107 |
else:
|
|
|
2108 |
subsidy = 0
|
|
|
2109 |
message+="""<tr>
|
|
|
2110 |
<td style="text-align:center">"""+str(item.item_id)+"""</td>
|
|
|
2111 |
<td style="text-align:center">"""+sku+"""</td>
|
|
|
2112 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
| 12556 |
anikendra |
2113 |
<td style="text-align:center">"""+str(item.promoPrice)+"""</td>
|
| 12489 |
kshitij.so |
2114 |
<td style="text-align:center">"""+str(math.ceil(item.proposedSp))+"""</td>
|
|
|
2115 |
<td style="text-align:center">"""+str(round(subsidy))+"""</td>
|
|
|
2116 |
<td style="text-align:center">"""+str(round(oldMargin))+" ("+str(round((oldMargin/item.ourSellingPrice)*100,1))+"%)"+"""</td>
|
| 12501 |
kshitij.so |
2117 |
<td style="text-align:center">"""+str(newMargin)+" ("+str(round((newMargin/item.proposedSp)*100,1))+"%)"+"""</td>
|
| 12489 |
kshitij.so |
2118 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
|
|
2119 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
|
|
2120 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
|
|
2121 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
|
|
2122 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
|
|
2123 |
</tr>"""
|
|
|
2124 |
message+="""</tbody></table><h3>Auto Increase Items</h3><table border="1" style="width:100%;">
|
|
|
2125 |
<thead>
|
|
|
2126 |
<tr><th>Item Id</th>
|
|
|
2127 |
<th>Amazon SKU</th>
|
|
|
2128 |
<th>Product Name</th>
|
|
|
2129 |
<th>Old Price</th>
|
|
|
2130 |
<th>New Price</th>
|
|
|
2131 |
<th>Subsidy</th>
|
|
|
2132 |
<th>Old Margin</th>
|
|
|
2133 |
<th>New Margin</th>
|
|
|
2134 |
<th>Commission %</th>
|
|
|
2135 |
<th>Return Provision %</th>
|
|
|
2136 |
<th>Inventory</th>
|
|
|
2137 |
<th>Sales History</th>
|
|
|
2138 |
<th>Category</th>
|
|
|
2139 |
</tr></thead>
|
|
|
2140 |
<tbody>"""
|
|
|
2141 |
for item in successfulAutoIncrease:
|
|
|
2142 |
it = Item.query.filter_by(id=item.item_id).one()
|
|
|
2143 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))
|
| 12556 |
anikendra |
2144 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
|
|
2145 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
| 12489 |
kshitij.so |
2146 |
newMargin = round(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)) - getNewLowestPossibleSp(item,12.36,vatRate))
|
|
|
2147 |
sku = ''
|
|
|
2148 |
if item.warehouseLocation==1:
|
|
|
2149 |
sku='FBA'+str(item.item_id)
|
|
|
2150 |
else:
|
|
|
2151 |
sku='FBB'+str(item.item_id)
|
|
|
2152 |
if amazonLongTermActivePromotions.has_key(sku):
|
|
|
2153 |
subsidy = (amazonLongTermActivePromotions.get(sku)).subsidy
|
|
|
2154 |
elif amazonShortTermActivePromotions.has_key(sku):
|
|
|
2155 |
subsidy = (amazonShortTermActivePromotions.get(sku)).subsidy
|
|
|
2156 |
else:
|
|
|
2157 |
subsidy = 0
|
|
|
2158 |
message+="""<tr>
|
|
|
2159 |
<td style="text-align:center">"""+str(item.item_id)+"""</td>
|
|
|
2160 |
<td style="text-align:center">"""+sku+"""</td>
|
|
|
2161 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
| 12556 |
anikendra |
2162 |
<td style="text-align:center">"""+str(item.promoPrice)+"""</td>
|
| 12489 |
kshitij.so |
2163 |
<td style="text-align:center">"""+str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))+"""</td>
|
|
|
2164 |
<td style="text-align:center">"""+str(round(subsidy))+"""</td>
|
|
|
2165 |
<td style="text-align:center">"""+str(round((oldMargin),1))+" ("+str(round((oldMargin/item.ourSellingPrice)*100,1))+"%)"+"""</td>
|
|
|
2166 |
<td style="text-align:center">"""+str(newMargin)+" ("+str(round((newMargin/(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))*100,1))+"%)"+"""</td>
|
|
|
2167 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
|
|
2168 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
|
|
2169 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
|
|
2170 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
|
|
2171 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
|
|
2172 |
</tr>"""
|
|
|
2173 |
message+="""</tbody></table></body></html>"""
|
|
|
2174 |
print message
|
|
|
2175 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
|
|
2176 |
mailServer.ehlo()
|
|
|
2177 |
mailServer.starttls()
|
|
|
2178 |
mailServer.ehlo()
|
|
|
2179 |
|
| 12639 |
kshitij.so |
2180 |
recipients = ['kshitij.sood@saholic.com']
|
|
|
2181 |
#recipients = ['rajneesh.arora@saholic.com','anikendra.das@saholic.com','vikram.raghav@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
|
| 12489 |
kshitij.so |
2182 |
msg = MIMEMultipart()
|
|
|
2183 |
msg['Subject'] = "Amazon Auto Pricing" + ' - ' + str(datetime.now())
|
|
|
2184 |
msg['From'] = ""
|
|
|
2185 |
msg['To'] = ",".join(recipients)
|
|
|
2186 |
msg.preamble = "Amazon Auto Pricing" + ' - ' + str(datetime.now())
|
|
|
2187 |
html_msg = MIMEText(message, 'html')
|
|
|
2188 |
msg.attach(html_msg)
|
|
|
2189 |
try:
|
|
|
2190 |
mailServer.login("build@shop2020.in", "cafe@nes")
|
|
|
2191 |
#mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
|
|
|
2192 |
mailServer.sendmail("cafe@nes", recipients, msg.as_string())
|
|
|
2193 |
except Exception as e:
|
|
|
2194 |
print e
|
|
|
2195 |
print "Unable to send pricing mail.Lets try with local SMTP."
|
|
|
2196 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
2197 |
smtpServer.set_debuglevel(1)
|
|
|
2198 |
sender = 'build@shop2020.in'
|
|
|
2199 |
try:
|
|
|
2200 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
|
|
2201 |
print "Successfully sent email"
|
|
|
2202 |
except:
|
|
|
2203 |
print "Error: unable to send email."
|
|
|
2204 |
|
| 12526 |
anikendra |
2205 |
def generateCategoryMap():
|
|
|
2206 |
global categoryMap
|
|
|
2207 |
result = session.query(Category.id,Category.display_name).all()
|
|
|
2208 |
for cat in result:
|
| 12597 |
kshitij.so |
2209 |
categoryMap[cat.id] = cat.display_name
|
| 12526 |
anikendra |
2210 |
|
| 12639 |
kshitij.so |
2211 |
def sendAlertForNegativeMargins(timestamp):
|
|
|
2212 |
negativeMargins = session.query(AmazonScrapingHistory,Item).join((Item,AmazonScrapingHistory.item_id==Item.id)).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.NEGATIVE_MARGIN).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
|
|
2213 |
if negativeMargins[0] is None or len(negativeMargins[0])==0:
|
|
|
2214 |
return
|
|
|
2215 |
xstr = lambda s: s or ""
|
|
|
2216 |
message="""<html>
|
|
|
2217 |
<body>
|
|
|
2218 |
<h3 style="color:red;">Amazon FC Negative Margins</h3>
|
|
|
2219 |
<table border="1" style="width:100%;">
|
|
|
2220 |
<thead>
|
|
|
2221 |
<tr><th>Item Id</th>
|
|
|
2222 |
<th>Amazon SKU</th>
|
|
|
2223 |
<th>Product Name</th>
|
|
|
2224 |
<th>Selling Price</th>
|
|
|
2225 |
<th>Promo Price</th>
|
|
|
2226 |
<th>Subsidy</th>
|
|
|
2227 |
<th>Lowest Possible SP</th>
|
| 12647 |
kshitij.so |
2228 |
<th>WANLC</th>
|
| 12639 |
kshitij.so |
2229 |
<th>Margin</th>
|
|
|
2230 |
<th>Commission %</th>
|
|
|
2231 |
<th>Return Provision %</th>
|
|
|
2232 |
<th>Inventory</th>
|
|
|
2233 |
<th>Sales History</th>
|
|
|
2234 |
</tr></thead>
|
|
|
2235 |
<tbody>"""
|
|
|
2236 |
for negativeMarginItems in negativeMargins:
|
|
|
2237 |
amScraping = negativeMarginItems[0]
|
|
|
2238 |
item = negativeMarginItems[1]
|
|
|
2239 |
if amScraping.warehouseLocation==1:
|
| 12642 |
kshitij.so |
2240 |
sku='FBA'+str(amScraping.item_id)
|
| 12639 |
kshitij.so |
2241 |
else:
|
| 12642 |
kshitij.so |
2242 |
sku='FBB'+str(amScraping.item_id)
|
| 12644 |
kshitij.so |
2243 |
if amazonLongTermActivePromotions.has_key(sku):
|
|
|
2244 |
subsidy = (amazonLongTermActivePromotions.get(sku)).subsidy
|
|
|
2245 |
elif amazonShortTermActivePromotions.has_key(sku):
|
| 12639 |
kshitij.so |
2246 |
subsidy = (amazonShortTermActivePromotions.get(sku)).subsidy
|
|
|
2247 |
else:
|
|
|
2248 |
subsidy = 0
|
|
|
2249 |
message+="""<tr>
|
|
|
2250 |
<td style="text-align:center">"""+str(amScraping.item_id)+"""</td>
|
| 12644 |
kshitij.so |
2251 |
<td style="text-align:center">"""+sku+"""</td>
|
| 12639 |
kshitij.so |
2252 |
<td style="text-align:center">"""+xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color)+"""</td>
|
|
|
2253 |
<td style="text-align:center">"""+str(amScraping.ourSellingPrice)+"""</td>
|
|
|
2254 |
<td style="text-align:center">"""+str(amScraping.promoPrice)+"""</td>
|
|
|
2255 |
<td style="text-align:center">"""+str(subsidy)+"""</td>
|
|
|
2256 |
<td style="text-align:center">"""+str(amScraping.lowestPossibleSp)+"""</td>
|
|
|
2257 |
<td style="text-align:center">"""+str(amScraping.wanlc)+"""</td>
|
|
|
2258 |
<td style="text-align:center">"""+str(round(getMargin(amScraping)))+" ("+str(round((getMargin(amScraping)/amScraping.ourSellingPrice)*100,1))+"%)"+"""</td>
|
|
|
2259 |
<td style="text-align:center">"""+str(amScraping.commission)+" %"+"""</td>
|
|
|
2260 |
<td style="text-align:center">"""+str(amScraping.returnProvision)+" %"+"""</td>
|
|
|
2261 |
<td style="text-align:center">"""+str(amScraping.ourInventory)+"""</td>
|
| 12645 |
kshitij.so |
2262 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
| 12639 |
kshitij.so |
2263 |
</tr>"""
|
|
|
2264 |
message+="""</tbody></table></body></html>"""
|
|
|
2265 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
|
|
2266 |
mailServer.ehlo()
|
|
|
2267 |
mailServer.starttls()
|
|
|
2268 |
mailServer.ehlo()
|
|
|
2269 |
|
|
|
2270 |
recipients = ['kshitij.sood@saholic.com']
|
|
|
2271 |
#recipients = ['rajneesh.arora@saholic.com','anikendra.das@saholic.com','vikram.raghav@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
|
|
|
2272 |
msg = MIMEMultipart()
|
|
|
2273 |
msg['Subject'] = "Amazon Negative Margin" + ' - ' + str(datetime.now())
|
|
|
2274 |
msg['From'] = ""
|
|
|
2275 |
msg['To'] = ",".join(recipients)
|
|
|
2276 |
msg.preamble = "Amazon Negative Margin" + ' - ' + str(datetime.now())
|
|
|
2277 |
html_msg = MIMEText(message, 'html')
|
|
|
2278 |
msg.attach(html_msg)
|
|
|
2279 |
try:
|
|
|
2280 |
mailServer.login("build@shop2020.in", "cafe@nes")
|
|
|
2281 |
#mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
|
|
|
2282 |
mailServer.sendmail("cafe@nes", recipients, msg.as_string())
|
|
|
2283 |
except Exception as e:
|
|
|
2284 |
print e
|
|
|
2285 |
print "Unable to send Amazon Negative margin mail.Lets try local SMTP"
|
|
|
2286 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
2287 |
smtpServer.set_debuglevel(1)
|
|
|
2288 |
sender = 'build@shop2020.in'
|
|
|
2289 |
try:
|
|
|
2290 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
|
|
2291 |
print "Successfully sent email"
|
|
|
2292 |
except:
|
|
|
2293 |
print "Error: unable to send email."
|
|
|
2294 |
|
|
|
2295 |
def sendAlertForCantCompete(timestamp):
|
|
|
2296 |
cantCompeteItemsList = session.query(AmazonScrapingHistory).filter(AmazonScrapingHistory.competitiveCategory==CompetitionCategory.CANT_COMPETE).filter(AmazonScrapingHistory.timestamp==timestamp).all()
|
| 12649 |
kshitij.so |
2297 |
print cantCompeteItemsList
|
| 12639 |
kshitij.so |
2298 |
if cantCompeteItemsList is None or len(cantCompeteItemsList)==0:
|
|
|
2299 |
return
|
|
|
2300 |
xstr = lambda s: s or ""
|
|
|
2301 |
message="""<html>
|
|
|
2302 |
<body>
|
|
|
2303 |
<h3 style="color:red;">Amazon FC Cant Compete Items</h3>
|
|
|
2304 |
<table border="1" style="width:100%;">
|
|
|
2305 |
<thead>
|
|
|
2306 |
<tr><th>Item Id</th>
|
|
|
2307 |
<th>Amazon SKU</th>
|
|
|
2308 |
<th>Product Name</th>
|
|
|
2309 |
<th>Selling Price</th>
|
|
|
2310 |
<th>Promo Price</th>
|
|
|
2311 |
<th>Subsidy</th>
|
|
|
2312 |
<th>Lowest Possible SP</th>
|
|
|
2313 |
<th>WANLC</th>
|
|
|
2314 |
<th>Margin</th>
|
|
|
2315 |
<th>Commission %</th>
|
|
|
2316 |
<th>Return Provision %</th>
|
|
|
2317 |
<th>Competitive Price</th>
|
| 12651 |
kshitij.so |
2318 |
<th>Proposed SP</th>
|
| 12639 |
kshitij.so |
2319 |
<th>Inventory</th>
|
|
|
2320 |
<th>Sales History</th>
|
|
|
2321 |
</tr></thead>
|
|
|
2322 |
<tbody>"""
|
| 12649 |
kshitij.so |
2323 |
cantCompeteItems = sorted(list(cantCompeteItemsList), key=lambda x: x.ourInventory, reverse=True)
|
| 12639 |
kshitij.so |
2324 |
for cantCompeteItem in cantCompeteItems:
|
|
|
2325 |
amScraping = cantCompeteItem
|
|
|
2326 |
item = Item.query.filter_by(id=amScraping.item_id).one()
|
|
|
2327 |
if amScraping.warehouseLocation==1:
|
| 12642 |
kshitij.so |
2328 |
sku='FBA'+str(amScraping.item_id)
|
| 12639 |
kshitij.so |
2329 |
else:
|
| 12642 |
kshitij.so |
2330 |
sku='FBB'+str(amScraping.item_id)
|
| 12644 |
kshitij.so |
2331 |
if amazonLongTermActivePromotions.has_key(sku):
|
|
|
2332 |
subsidy = (amazonLongTermActivePromotions.get(sku)).subsidy
|
|
|
2333 |
elif amazonShortTermActivePromotions.has_key(sku):
|
| 12639 |
kshitij.so |
2334 |
subsidy = (amazonShortTermActivePromotions.get(sku)).subsidy
|
|
|
2335 |
else:
|
|
|
2336 |
subsidy = 0
|
|
|
2337 |
message+="""<tr>
|
|
|
2338 |
<td style="text-align:center">"""+str(amScraping.item_id)+"""</td>
|
| 12644 |
kshitij.so |
2339 |
<td style="text-align:center">"""+sku+"""</td>
|
| 12639 |
kshitij.so |
2340 |
<td style="text-align:center">"""+xstr(item.brand)+" "+xstr(item.model_name)+" "+xstr(item.model_number)+" "+xstr(item.color)+"""</td>
|
|
|
2341 |
<td style="text-align:center">"""+str(amScraping.ourSellingPrice)+"""</td>
|
|
|
2342 |
<td style="text-align:center">"""+str(amScraping.promoPrice)+"""</td>
|
|
|
2343 |
<td style="text-align:center">"""+str(subsidy)+"""</td>
|
|
|
2344 |
<td style="text-align:center">"""+str(amScraping.lowestPossibleSp)+"""</td>
|
|
|
2345 |
<td style="text-align:center">"""+str(amScraping.wanlc)+"""</td>
|
|
|
2346 |
<td style="text-align:center">"""+str(round(getMargin(amScraping)))+" ("+str(round((getMargin(amScraping)/amScraping.ourSellingPrice)*100,1))+"%)"+"""</td>
|
|
|
2347 |
<td style="text-align:center">"""+str(amScraping.commission)+" %"+"""</td>
|
|
|
2348 |
<td style="text-align:center">"""+str(amScraping.returnProvision)+" %"+"""</td>
|
|
|
2349 |
<td style="text-align:center">"""+str(amScraping.competitivePrice)+" %"+"""</td>
|
|
|
2350 |
<td style="text-align:center">"""+str(amScraping.proposedSp)+" %"+"""</td>
|
|
|
2351 |
<td style="text-align:center">"""+str(amScraping.ourInventory)+"""</td>
|
| 12645 |
kshitij.so |
2352 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
| 12639 |
kshitij.so |
2353 |
</tr>"""
|
|
|
2354 |
message+="""</tbody></table></body></html>"""
|
|
|
2355 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
|
|
2356 |
mailServer.ehlo()
|
|
|
2357 |
mailServer.starttls()
|
|
|
2358 |
mailServer.ehlo()
|
|
|
2359 |
|
|
|
2360 |
recipients = ['kshitij.sood@saholic.com']
|
|
|
2361 |
#recipients = ['rajneesh.arora@saholic.com','anikendra.das@saholic.com','vikram.raghav@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
|
|
|
2362 |
msg = MIMEMultipart()
|
|
|
2363 |
msg['Subject'] = "Amazon Cant Compete Items" + ' - ' + str(datetime.now())
|
|
|
2364 |
msg['From'] = ""
|
|
|
2365 |
msg['To'] = ",".join(recipients)
|
|
|
2366 |
msg.preamble = "Amazon Cant Compete Items" + ' - ' + str(datetime.now())
|
|
|
2367 |
html_msg = MIMEText(message, 'html')
|
|
|
2368 |
msg.attach(html_msg)
|
|
|
2369 |
try:
|
|
|
2370 |
mailServer.login("build@shop2020.in", "cafe@nes")
|
|
|
2371 |
#mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
|
|
|
2372 |
mailServer.sendmail("cafe@nes", recipients, msg.as_string())
|
|
|
2373 |
except Exception as e:
|
|
|
2374 |
print e
|
|
|
2375 |
print "Unable to send Amazon Cant Compete Items mail.Lets try local SMTP"
|
|
|
2376 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
2377 |
smtpServer.set_debuglevel(1)
|
|
|
2378 |
sender = 'build@shop2020.in'
|
|
|
2379 |
try:
|
|
|
2380 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
|
|
2381 |
print "Successfully sent email"
|
|
|
2382 |
except:
|
|
|
2383 |
print "Error: unable to send email."
|
|
|
2384 |
|
| 12363 |
kshitij.so |
2385 |
def main():
|
|
|
2386 |
parser = optparse.OptionParser()
|
|
|
2387 |
parser.add_option("-t", "--type", dest="runType",
|
|
|
2388 |
default="FULL", type="string",
|
| 12639 |
kshitij.so |
2389 |
help="Run type FULL or FAVOURITE or FULL-OTHER")
|
| 12363 |
kshitij.so |
2390 |
(options, args) = parser.parse_args()
|
| 12639 |
kshitij.so |
2391 |
if options.runType not in ('FULL','FAVOURITE','FULL-OTHER'):
|
| 12363 |
kshitij.so |
2392 |
print "Run type argument illegal."
|
|
|
2393 |
sys.exit(1)
|
| 12597 |
kshitij.so |
2394 |
time.sleep(5)
|
| 12363 |
kshitij.so |
2395 |
timestamp = datetime.now()
|
| 12526 |
anikendra |
2396 |
generateCategoryMap()
|
| 12363 |
kshitij.so |
2397 |
fetchFbaSale()
|
|
|
2398 |
itemInfo = populateStuff(timestamp,options.runType)
|
|
|
2399 |
itemsToPopulate = 0
|
| 12430 |
kshitij.so |
2400 |
toSync = 0
|
|
|
2401 |
lenItems = len(itemInfo)
|
|
|
2402 |
while(toSync < lenItems):
|
|
|
2403 |
oldSync = toSync
|
|
|
2404 |
if lenItems >= 20:
|
|
|
2405 |
toSync = 20
|
|
|
2406 |
else:
|
|
|
2407 |
toSync = lenItems - oldSync
|
|
|
2408 |
getPriceAndAsin(itemInfo[oldSync:toSync+oldSync])
|
|
|
2409 |
toSync = oldSync + toSync
|
|
|
2410 |
|
| 12363 |
kshitij.so |
2411 |
while (len(itemInfo)>0):
|
| 12430 |
kshitij.so |
2412 |
if len(itemInfo) >= 20:
|
|
|
2413 |
itemsToPopulate = 20
|
| 12363 |
kshitij.so |
2414 |
else:
|
|
|
2415 |
itemsToPopulate = len(itemInfo)
|
| 12456 |
kshitij.so |
2416 |
print "items to popluate"
|
| 12370 |
kshitij.so |
2417 |
print itemsToPopulate
|
| 12597 |
kshitij.so |
2418 |
exceptionList, negativeMargin, cheapest, amongCheapestAndCanCompete, canCompete, almostCompete, cantCompete = decideCategory(itemInfo[0:itemsToPopulate],timestamp)
|
| 12363 |
kshitij.so |
2419 |
itemInfo[0:itemsToPopulate] = []
|
|
|
2420 |
commitExceptionList(exceptionList,timestamp,options.runType)
|
|
|
2421 |
commitNegativeMargin(negativeMargin,timestamp,options.runType)
|
|
|
2422 |
commitCheapest(cheapest,timestamp,options.runType)
|
|
|
2423 |
commitAmongCheapestAndCanCompete(amongCheapestAndCanCompete,timestamp,options.runType)
|
|
|
2424 |
commitCanCompete(canCompete,timestamp,options.runType)
|
|
|
2425 |
commitAlmostCompete(almostCompete,timestamp,options.runType)
|
|
|
2426 |
commitCantCompete(cantCompete, timestamp,options.runType)
|
| 12396 |
kshitij.so |
2427 |
exceptionList[:], negativeMargin[:], cheapest[:], amongCheapestAndCanCompete[:], canCompete[:], almostCompete[:], cantCompete[:] =[],[],[],[],[],[],[]
|
|
|
2428 |
autoDecreaseItems = fetchItemsForAutoDecrease(timestamp)
|
|
|
2429 |
autoIncreaseItems = fetchItemsForAutoIncrease(timestamp)
|
|
|
2430 |
previousAutoFav, nowAutoFav = markAutoFavourites(timestamp)
|
| 12444 |
kshitij.so |
2431 |
writeReport(timestamp,autoDecreaseItems,autoIncreaseItems,previousAutoFav,nowAutoFav,options.runType)
|
| 12494 |
kshitij.so |
2432 |
print "send auto pricing email"
|
| 12491 |
kshitij.so |
2433 |
sendAutoPricingMail(autoDecreaseItems,autoIncreaseItems)
|
| 12639 |
kshitij.so |
2434 |
if options.runType == 'FULL-OTHER':
|
|
|
2435 |
sendAlertForNegativeMargins(timestamp)
|
|
|
2436 |
sendAlertForCantCompete(timestamp)
|
| 12363 |
kshitij.so |
2437 |
if __name__=='__main__':
|
| 12526 |
anikendra |
2438 |
main()
|