| Line 35... |
Line 35... |
| 35 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
35 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
| 36 |
|
36 |
|
| 37 |
amazonAsinPrice={}
|
37 |
amazonAsinPrice={}
|
| 38 |
amazonLongTermActivePromotions = {}
|
38 |
amazonLongTermActivePromotions = {}
|
| 39 |
amazonShortTermActivePromotions = {}
|
39 |
amazonShortTermActivePromotions = {}
|
| - |
|
40 |
notListed = []
|
| 40 |
saleMap = {}
|
41 |
saleMap = {}
|
| 41 |
categoryMap = {}
|
42 |
categoryMap = {}
|
| 42 |
DataService.initialize(db_hostname=host)
|
43 |
DataService.initialize(db_hostname=host)
|
| 43 |
|
44 |
|
| 44 |
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
45 |
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
| Line 408... |
Line 409... |
| 408 |
if runType=='FAVOURITE':
|
409 |
if runType=='FAVOURITE':
|
| 409 |
if not (fbaInventoryItem.item_id in favourites):
|
410 |
if not (fbaInventoryItem.item_id in favourites):
|
| 410 |
continue
|
411 |
continue
|
| 411 |
d_amazon_listed = Amazonlisted.get_by(itemId=fbaInventoryItem.item_id)
|
412 |
d_amazon_listed = Amazonlisted.get_by(itemId=fbaInventoryItem.item_id)
|
| 412 |
if d_amazon_listed is None:
|
413 |
if d_amazon_listed is None:
|
| - |
|
414 |
if fbaInventoryItem.location==0:
|
| - |
|
415 |
sku = 'FBA'+str(fbaInventoryItem.item_id)
|
| - |
|
416 |
notListed.append(sku)
|
| - |
|
417 |
elif fbaInventoryItem.location==1:
|
| - |
|
418 |
sku = 'FBB'+str(fbaInventoryItem.item_id)
|
| - |
|
419 |
notListed.append(sku)
|
| - |
|
420 |
else:
|
| - |
|
421 |
pass
|
| 413 |
continue
|
422 |
continue
|
| 414 |
if d_amazon_listed.overrrideWanlc:
|
423 |
if d_amazon_listed.overrrideWanlc:
|
| 415 |
wanlc = d_amazon_listed.exceptionalWanlc
|
424 |
wanlc = d_amazon_listed.exceptionalWanlc
|
| 416 |
if wanlc is None:
|
425 |
if wanlc is None:
|
| 417 |
wanlc = 0.0
|
426 |
wanlc = 0.0
|
| Line 2126... |
Line 2135... |
| 2126 |
<th>Commission %</th>
|
2135 |
<th>Commission %</th>
|
| 2127 |
<th>Return Provision %</th>
|
2136 |
<th>Return Provision %</th>
|
| 2128 |
<th>Inventory</th>
|
2137 |
<th>Inventory</th>
|
| 2129 |
<th>Sales History</th>
|
2138 |
<th>Sales History</th>
|
| 2130 |
<th>Category</th>
|
2139 |
<th>Category</th>
|
| - |
|
2140 |
<th>isListed</th>
|
| - |
|
2141 |
<th>Price Feed Suppressed</th>
|
| 2131 |
</tr></thead>
|
2142 |
</tr></thead>
|
| 2132 |
<tbody>"""
|
2143 |
<tbody>"""
|
| 2133 |
for item in successfulAutoDecrease:
|
2144 |
for item in successfulAutoDecrease:
|
| 2134 |
it = Item.query.filter_by(id=item.item_id).one()
|
2145 |
it = Item.query.filter_by(id=item.item_id).one()
|
| - |
|
2146 |
amItem = Amazonlisted.get_by(itemId=item.item_id)
|
| - |
|
2147 |
isListed =""
|
| - |
|
2148 |
priceSuppress =""
|
| - |
|
2149 |
if item.warehouseLocation==1:
|
| - |
|
2150 |
if amItem.isFba:
|
| - |
|
2151 |
isListed = "Yes"
|
| - |
|
2152 |
else:
|
| - |
|
2153 |
isListed = "No"
|
| - |
|
2154 |
if amItem.suppressFbaPriceUpdate:
|
| - |
|
2155 |
priceSuppress = "Yes"
|
| - |
|
2156 |
else:
|
| - |
|
2157 |
priceSuppress = "No"
|
| 2135 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,item.proposedSp)
|
2158 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,item.proposedSp)
|
| 2136 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
2159 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
| 2137 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
2160 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
| 2138 |
newMargin = round(item.proposedSp - getNewLowestPossibleSp(item,12.36,vatRate))
|
2161 |
newMargin = round(item.proposedSp - getNewLowestPossibleSp(item,12.36,vatRate))
|
| 2139 |
sku = ''
|
2162 |
sku = ''
|
| Line 2159... |
Line 2182... |
| 2159 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
2182 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
| 2160 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
2183 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
| 2161 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
2184 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
| 2162 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
2185 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
| 2163 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
2186 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
| - |
|
2187 |
<td style="text-align:center">"""+isListed+"""</td>
|
| - |
|
2188 |
<td style="text-align:center">"""+priceSuppress+"""</td>
|
| 2164 |
</tr>"""
|
2189 |
</tr>"""
|
| 2165 |
message+="""</tbody></table><h3>Auto Increase Items</h3><table border="1" style="width:100%;">
|
2190 |
message+="""</tbody></table><h3>Auto Increase Items</h3><table border="1" style="width:100%;">
|
| 2166 |
<thead>
|
2191 |
<thead>
|
| 2167 |
<tr><th>Item Id</th>
|
2192 |
<tr><th>Item Id</th>
|
| 2168 |
<th>Amazon SKU</th>
|
2193 |
<th>Amazon SKU</th>
|
| Line 2175... |
Line 2200... |
| 2175 |
<th>Commission %</th>
|
2200 |
<th>Commission %</th>
|
| 2176 |
<th>Return Provision %</th>
|
2201 |
<th>Return Provision %</th>
|
| 2177 |
<th>Inventory</th>
|
2202 |
<th>Inventory</th>
|
| 2178 |
<th>Sales History</th>
|
2203 |
<th>Sales History</th>
|
| 2179 |
<th>Category</th>
|
2204 |
<th>Category</th>
|
| - |
|
2205 |
<th>isListed</th>
|
| - |
|
2206 |
<th>Price Feed Suppressed</th>
|
| 2180 |
</tr></thead>
|
2207 |
</tr></thead>
|
| 2181 |
<tbody>"""
|
2208 |
<tbody>"""
|
| 2182 |
for item in successfulAutoIncrease:
|
2209 |
for item in successfulAutoIncrease:
|
| 2183 |
it = Item.query.filter_by(id=item.item_id).one()
|
2210 |
it = Item.query.filter_by(id=item.item_id).one()
|
| - |
|
2211 |
amItem = Amazonlisted.get_by(itemId=item.item_id)
|
| - |
|
2212 |
isListed =""
|
| - |
|
2213 |
priceSuppress =""
|
| - |
|
2214 |
if item.warehouseLocation==1:
|
| - |
|
2215 |
if amItem.isFba:
|
| - |
|
2216 |
isListed = "Yes"
|
| - |
|
2217 |
else:
|
| - |
|
2218 |
isListed = "No"
|
| - |
|
2219 |
if amItem.suppressFbaPriceUpdate:
|
| - |
|
2220 |
priceSuppress = "Yes"
|
| - |
|
2221 |
else:
|
| - |
|
2222 |
priceSuppress = "No"
|
| 2184 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))
|
2223 |
vatRate = getNewVatRate(item.item_id,item.warehouseLocation,math.ceil(item.promoPrice+max(10,.01*item.promoPrice)))
|
| 2185 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
2224 |
#oldMargin = item.ourSellingPrice - item.lowestPossibleSp
|
| 2186 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
2225 |
oldMargin = item.promoPrice - item.lowestPossibleSp
|
| 2187 |
newMargin = round(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)) - getNewLowestPossibleSp(item,12.36,vatRate))
|
2226 |
newMargin = round(math.ceil(item.promoPrice+max(10,.01*item.promoPrice)) - getNewLowestPossibleSp(item,12.36,vatRate))
|
| 2188 |
sku = ''
|
2227 |
sku = ''
|
| 2189 |
if item.warehouseLocation==1:
|
2228 |
if item.warehouseLocation==1:
|
| 2190 |
sku='FBA'+str(item.item_id)
|
2229 |
sku='FBA'+str(item.item_id)
|
| 2191 |
else:
|
2230 |
else:
|
| 2192 |
sku='FBB'+str(item.item_id)
|
2231 |
sku='FBB'+str(item.item_id)
|
| Line 2199... |
Line 2238... |
| 2199 |
message+="""<tr>
|
2238 |
message+="""<tr>
|
| 2200 |
<td style="text-align:center">"""+str(item.item_id)+"""</td>
|
2239 |
<td style="text-align:center">"""+str(item.item_id)+"""</td>
|
| 2201 |
<td style="text-align:center">"""+sku+"""</td>
|
2240 |
<td style="text-align:center">"""+sku+"""</td>
|
| 2202 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
2241 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
| 2203 |
<td style="text-align:center">"""+str(item.promoPrice)+"""</td>
|
2242 |
<td style="text-align:center">"""+str(item.promoPrice)+"""</td>
|
| 2204 |
<td style="text-align:center">"""+str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))+"""</td>
|
2243 |
<td style="text-align:center">"""+str(math.ceil(item.promoPrice+max(10,.01*item.promoPrice)))+"""</td>
|
| 2205 |
<td style="text-align:center">"""+str(round(subsidy))+"""</td>
|
2244 |
<td style="text-align:center">"""+str(round(subsidy))+"""</td>
|
| 2206 |
<td style="text-align:center">"""+str(round((oldMargin),1))+" ("+str(round((oldMargin/item.ourSellingPrice)*100,1))+"%)"+"""</td>
|
2245 |
<td style="text-align:center">"""+str(round((oldMargin),1))+" ("+str(round((oldMargin/item.promoPrice)*100,1))+"%)"+"""</td>
|
| 2207 |
<td style="text-align:center">"""+str(newMargin)+" ("+str(round((newMargin/(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))*100,1))+"%)"+"""</td>
|
2246 |
<td style="text-align:center">"""+str(newMargin)+" ("+str(round((newMargin/(item.promoPrice+max(10,.01*item.promoPrice)))*100,1))+"%)"+"""</td>
|
| 2208 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
2247 |
<td style="text-align:center">"""+str(item.commission)+" %"+"""</td>
|
| 2209 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
2248 |
<td style="text-align:center">"""+str(item.returnProvision)+" %"+"""</td>
|
| 2210 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
2249 |
<td style="text-align:center">"""+str(item.ourInventory)+"""</td>
|
| 2211 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
2250 |
<td style="text-align:center">"""+getOosString(saleMap.get(sku))+"""</td>
|
| 2212 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
2251 |
<td style="text-align:center">"""+str(CompetitionCategory._VALUES_TO_NAMES.get(item.competitiveCategory))+"""</td>
|
| - |
|
2252 |
<td style="text-align:center">"""+isListed+"""</td>
|
| - |
|
2253 |
<td style="text-align:center">"""+priceSuppress+"""</td>
|
| 2213 |
</tr>"""
|
2254 |
</tr>"""
|
| - |
|
2255 |
message+="""</tbody></table><h3>Create Listing On Our Dashboard - Stock is present in FC</h3><table border="1" style="width:100%;">
|
| - |
|
2256 |
<thead>
|
| - |
|
2257 |
<tr><th>Item Id</th>
|
| - |
|
2258 |
<th>Amazon SKU</th>
|
| - |
|
2259 |
<th>Product Name</th></tr></thead>
|
| - |
|
2260 |
<tbody>
|
| - |
|
2261 |
"""
|
| - |
|
2262 |
for sku in notListed:
|
| - |
|
2263 |
it = Item.query.filter_by(id=int(sku[3:])).one()
|
| - |
|
2264 |
message+="""<tr>
|
| - |
|
2265 |
<td style="text-align:center">"""+sku[3:]+"""</td>
|
| - |
|
2266 |
<td style="text-align:center">"""+sku+"""</td>
|
| - |
|
2267 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
| - |
|
2268 |
</tr>"""
|
| 2214 |
message+="""</tbody></table></body></html>"""
|
2269 |
message+="""</tbody></table></body></html>"""
|
| 2215 |
print message
|
2270 |
print message
|
| 2216 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
2271 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
| 2217 |
mailServer.ehlo()
|
2272 |
mailServer.ehlo()
|
| 2218 |
mailServer.starttls()
|
2273 |
mailServer.starttls()
|
| Line 2419... |
Line 2474... |
| 2419 |
sender = 'build@shop2020.in'
|
2474 |
sender = 'build@shop2020.in'
|
| 2420 |
try:
|
2475 |
try:
|
| 2421 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
2476 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| 2422 |
print "Successfully sent email"
|
2477 |
print "Successfully sent email"
|
| 2423 |
except:
|
2478 |
except:
|
| 2424 |
print "Error: unable to send email."
|
2479 |
print "Error: unable to send email."
|
| - |
|
2480 |
|
| - |
|
2481 |
def commitPricing(successfulAutoDecrease,successfulAutoIncrease):
|
| - |
|
2482 |
print "inside commit pricing"
|
| - |
|
2483 |
if len(successfulAutoDecrease)==0 and len(successfulAutoIncrease)==0 :
|
| - |
|
2484 |
return
|
| - |
|
2485 |
for item in successfulAutoDecrease:
|
| - |
|
2486 |
amItem = Amazonlisted.get_by(itemId=item.item_id)
|
| - |
|
2487 |
if item.warehouseLocation==1:
|
| - |
|
2488 |
if item.isPromotion:
|
| - |
|
2489 |
amItem.fbaPromoPrice = math.ceil(item.proposedSp)
|
| - |
|
2490 |
else:
|
| - |
|
2491 |
amItem.fbaPrice = math.ceil(item.proposedSp)
|
| - |
|
2492 |
amItem.fbaPriceLastUpdatedOn = datetime.now()
|
| - |
|
2493 |
elif item.warehouseLocation==2:
|
| - |
|
2494 |
if item.isPromotion:
|
| - |
|
2495 |
amItem.fbbPromoPrice = math.ceil(item.proposedSp)
|
| - |
|
2496 |
else:
|
| - |
|
2497 |
amItem.fbbPrice = math.ceil(item.proposedSp)
|
| - |
|
2498 |
amItem.fbaPriceLastUpdatedOn = datetime.now()
|
| - |
|
2499 |
for item in successfulAutoIncrease:
|
| - |
|
2500 |
amItem = Amazonlisted.get_by(itemId=item.item_id)
|
| - |
|
2501 |
if item.warehouseLocation==1:
|
| - |
|
2502 |
if item.isPromotion:
|
| - |
|
2503 |
amItem.fbaPromoPrice = math.ceil(item.promoPrice+max(10,.01*item.promoPrice))
|
| - |
|
2504 |
else:
|
| - |
|
2505 |
amItem.fbaPrice = math.ceil(item.promoPrice+max(10,.01*item.promoPrice))
|
| - |
|
2506 |
amItem.fbaPriceLastUpdatedOn = datetime.now()
|
| - |
|
2507 |
elif item.warehouseLocation==2:
|
| - |
|
2508 |
if item.isPromotion:
|
| - |
|
2509 |
amItem.fbbPromoPrice = math.ceil(item.promoPrice+max(10,.01*item.promoPrice))
|
| - |
|
2510 |
else:
|
| - |
|
2511 |
amItem.fbbPrice = math.ceil(item.promoPrice+max(10,.01*item.promoPrice))
|
| - |
|
2512 |
amItem.fbbPriceLastUpdatedOn = datetime.now()
|
| 2425 |
|
2513 |
|
| 2426 |
def main():
|
2514 |
def main():
|
| 2427 |
parser = optparse.OptionParser()
|
2515 |
parser = optparse.OptionParser()
|
| 2428 |
parser.add_option("-t", "--type", dest="runType",
|
2516 |
parser.add_option("-t", "--type", dest="runType",
|
| 2429 |
default="FULL", type="string",
|
2517 |
default="FULL", type="string",
|
| Line 2469... |
Line 2557... |
| 2469 |
autoDecreaseItems = fetchItemsForAutoDecrease(timestamp)
|
2557 |
autoDecreaseItems = fetchItemsForAutoDecrease(timestamp)
|
| 2470 |
autoIncreaseItems = fetchItemsForAutoIncrease(timestamp)
|
2558 |
autoIncreaseItems = fetchItemsForAutoIncrease(timestamp)
|
| 2471 |
previousAutoFav, nowAutoFav = markAutoFavourites(timestamp)
|
2559 |
previousAutoFav, nowAutoFav = markAutoFavourites(timestamp)
|
| 2472 |
writeReport(timestamp,autoDecreaseItems,autoIncreaseItems,previousAutoFav,nowAutoFav,options.runType)
|
2560 |
writeReport(timestamp,autoDecreaseItems,autoIncreaseItems,previousAutoFav,nowAutoFav,options.runType)
|
| 2473 |
print "send auto pricing email"
|
2561 |
print "send auto pricing email"
|
| - |
|
2562 |
commitPricing(autoDecreaseItems,autoIncreaseItems)
|
| 2474 |
sendAutoPricingMail(autoDecreaseItems,autoIncreaseItems)
|
2563 |
sendAutoPricingMail(autoDecreaseItems,autoIncreaseItems)
|
| 2475 |
if options.runType == 'FULL-OTHER':
|
2564 |
if options.runType == 'FULL-OTHER':
|
| 2476 |
sendAlertForNegativeMargins(timestamp)
|
2565 |
sendAlertForNegativeMargins(timestamp)
|
| 2477 |
sendAlertForCantCompete(timestamp)
|
2566 |
sendAlertForCantCompete(timestamp)
|
| 2478 |
if __name__=='__main__':
|
2567 |
if __name__=='__main__':
|