| Line 1... |
Line 1... |
| 1 |
from elixir import *
|
1 |
from elixir import *
|
| 2 |
from shop2020.config.client.ConfigClient import ConfigClient
|
2 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 3 |
from shop2020.model.v1.catalog.impl import DataService
|
3 |
from shop2020.model.v1.catalog.impl import DataService
|
| 4 |
from shop2020.model.v1.catalog.impl.DataService import SnapdealItem, MarketplaceItems, Item, Category
|
4 |
from shop2020.model.v1.catalog.impl.DataService import SnapdealItem, MarketplaceItems, Item, Category, \
|
| - |
|
5 |
MarketPlaceUpdateHistory
|
| 5 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
6 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
| 6 |
import mechanize
|
7 |
import mechanize
|
| 7 |
import sys
|
8 |
import sys
|
| 8 |
import cookielib
|
9 |
import cookielib
|
| 9 |
from time import sleep
|
10 |
from time import sleep
|
| Line 15... |
Line 16... |
| 15 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
16 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
| 16 |
from email.mime.text import MIMEText
|
17 |
from email.mime.text import MIMEText
|
| 17 |
import email
|
18 |
import email
|
| 18 |
from email.mime.multipart import MIMEMultipart
|
19 |
from email.mime.multipart import MIMEMultipart
|
| 19 |
import email.encoders
|
20 |
import email.encoders
|
| - |
|
21 |
import copy
|
| 20 |
|
22 |
|
| 21 |
config_client = ConfigClient()
|
23 |
config_client = ConfigClient()
|
| 22 |
host = config_client.get_property('staging_hostname')
|
24 |
host = config_client.get_property('staging_hostname')
|
| 23 |
DataService.initialize(db_hostname=host)
|
25 |
DataService.initialize(db_hostname=host)
|
| 24 |
|
26 |
|
| - |
|
27 |
courierCostToSync = []
|
| - |
|
28 |
oldPricing = []
|
| - |
|
29 |
|
| 25 |
class __SnapdealInfo:
|
30 |
class __SnapdealInfo:
|
| 26 |
def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, \
|
31 |
def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, \
|
| 27 |
fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId, parentCategory, productGroup ,brand, modelName, modelNumber, \
|
32 |
fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId, parentCategory, productGroup ,brand, modelName, modelNumber, \
|
| 28 |
color,reason):
|
33 |
color,reason,woodenPackagingCost):
|
| 29 |
|
34 |
|
| 30 |
self.sellingPrice = sellingPrice
|
35 |
self.sellingPrice = sellingPrice
|
| 31 |
self.weight = weight
|
36 |
self.weight = weight
|
| 32 |
self.transferPrice = transferPrice
|
37 |
self.transferPrice = transferPrice
|
| 33 |
self.commission = commission
|
38 |
self.commission = commission
|
| Line 47... |
Line 52... |
| 47 |
self.brand = brand
|
52 |
self.brand = brand
|
| 48 |
self.modelName = modelName
|
53 |
self.modelName = modelName
|
| 49 |
self.modelNumber = modelNumber
|
54 |
self.modelNumber = modelNumber
|
| 50 |
self.color = color
|
55 |
self.color = color
|
| 51 |
self.reason = reason
|
56 |
self.reason = reason
|
| - |
|
57 |
self.woodenPackagingCost = woodenPackagingCost
|
| 52 |
|
58 |
|
| 53 |
|
59 |
|
| 54 |
def getBrowserObject():
|
60 |
def getBrowserObject():
|
| 55 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
61 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
| 56 |
cj = cookielib.LWPCookieJar()
|
62 |
cj = cookielib.LWPCookieJar()
|
| Line 85... |
Line 91... |
| 85 |
|
91 |
|
| 86 |
def populateStuff(br):
|
92 |
def populateStuff(br):
|
| 87 |
exceptionList = []
|
93 |
exceptionList = []
|
| 88 |
fetchedItems = []
|
94 |
fetchedItems = []
|
| 89 |
items = session.query(SnapdealItem,MarketplaceItems,Item).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).join((Item,SnapdealItem.item_id==Item.id)).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
95 |
items = session.query(SnapdealItem,MarketplaceItems,Item).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).join((Item,SnapdealItem.item_id==Item.id)).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
| - |
|
96 |
#items = session.query(SnapdealItem,MarketplaceItems,Item).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).join((Item,SnapdealItem.item_id==Item.id)).filter(SnapdealItem.item_id==12613).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
| 90 |
for item in items:
|
97 |
for item in items:
|
| 91 |
snapdealItem = item[0]
|
98 |
snapdealItem = item[0]
|
| 92 |
marketplaceItem = item[1]
|
99 |
marketplaceItem = item[1]
|
| 93 |
ds_item = item[2]
|
100 |
ds_item = item[2]
|
| 94 |
category = Category.query.filter_by(id=ds_item.category).one()
|
101 |
category = Category.query.filter_by(id=ds_item.category).one()
|
| Line 114... |
Line 121... |
| 114 |
snapdealInfo.weight = ds_item.weight
|
121 |
snapdealInfo.weight = ds_item.weight
|
| 115 |
fetchedItems.append(snapdealInfo)
|
122 |
fetchedItems.append(snapdealInfo)
|
| 116 |
return exceptionList, fetchedItems
|
123 |
return exceptionList, fetchedItems
|
| 117 |
|
124 |
|
| 118 |
def fetchData(br,supc):
|
125 |
def fetchData(br,supc):
|
| - |
|
126 |
print "Fetching data for ",supc
|
| 119 |
url="http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue=%s&gridType=normal&_search=false&nd=1396007375971&rows=30&page=1&sidx=&sord=asc"%(supc)
|
127 |
url="http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue=%s&gridType=normal&_search=false&nd=1396007375971&rows=30&page=1&sidx=&sord=asc"%(supc)
|
| 120 |
sleep(1)
|
128 |
sleep(1)
|
| 121 |
response = br.open(url)
|
129 |
response = br.open(url)
|
| 122 |
dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
|
130 |
dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
|
| 123 |
struct = json.loads(dataform)
|
131 |
struct = json.loads(dataform)
|
| 124 |
sdObj = struct['rows'][0]
|
132 |
sdObj = struct['rows'][0]
|
| 125 |
print sdObj
|
133 |
print sdObj
|
| 126 |
snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None, \
|
134 |
snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None, \
|
| 127 |
None, None, None, None, None, None, None)
|
135 |
None, None, None, None, None, None, None,sdObj['woodenPackagingCost'])
|
| 128 |
return snapdealInfo
|
136 |
return snapdealInfo
|
| 129 |
|
137 |
|
| 130 |
def filterData(fetchedItems):
|
138 |
def filterData(fetchedItems):
|
| 131 |
filterList = []
|
139 |
filterList = []
|
| 132 |
for data in fetchedItems:
|
140 |
for data in fetchedItems:
|
| 133 |
if ( data.transferPrice - data.transferPriceSnapdeal >= -3 ) and (data.transferPrice - data.transferPriceSnapdeal <= 3):
|
141 |
if ( data.transferPrice - data.transferPriceSnapdeal >= -3 ) and (data.transferPrice - data.transferPriceSnapdeal <= 3):
|
| - |
|
142 |
print "continue for",data.itemId
|
| 134 |
continue
|
143 |
continue
|
| 135 |
filterList.append(data)
|
144 |
filterList.append(data)
|
| 136 |
return filterList
|
145 |
return filterList
|
| 137 |
|
146 |
|
| 138 |
def sendMail(filteredData,exceptionList):
|
147 |
def sendMail(filteredData,exceptionList):
|
| Line 173... |
Line 182... |
| 173 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
182 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
| 174 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
183 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
| 175 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
184 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
| 176 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
185 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
| 177 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
186 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
| 178 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
|
187 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2)+round(data.woodenPackagingCost,2))+"""</td>
|
| 179 |
<td style="text-align:center">"""+getReason(data)+"""</td>
|
188 |
<td style="text-align:center">"""+getReason(data)+"""</td>
|
| 180 |
</tr>"""
|
189 |
</tr>"""
|
| 181 |
message+="""</tbody></table>"""
|
190 |
message+="""</tbody></table>"""
|
| 182 |
message+="""
|
191 |
message+="""
|
| 183 |
<h3>High TP On Snapdeal</h3>
|
192 |
<h3>High TP On Snapdeal</h3>
|
| Line 214... |
Line 223... |
| 214 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
223 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
| 215 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
224 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
| 216 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
225 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
| 217 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
226 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
| 218 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
227 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
| 219 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
|
228 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2)+round(data.woodenPackagingCost,2))+"""</td>
|
| 220 |
<td style="text-align:center">"""+getReason(data)+"""</td>
|
229 |
<td style="text-align:center">"""+getReason(data)+"""</td>
|
| 221 |
</tr>"""
|
230 |
</tr>"""
|
| 222 |
message+="""</tbody></table>"""
|
231 |
message+="""</tbody></table>"""
|
| 223 |
message+="""
|
232 |
message+="""
|
| 224 |
<h3>Unable To Fetch Items</h3>
|
233 |
<h3>Unable To Fetch Items</h3>
|
| Line 328... |
Line 337... |
| 328 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
337 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
| 329 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
338 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
| 330 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
339 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
| 331 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
340 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
| 332 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
341 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
| 333 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
|
342 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2)+round(data.woodenPackagingCost,2))
|
| 334 |
sheet.write(sheet_iterator, 18, getReason(data))
|
343 |
sheet.write(sheet_iterator, 18, getReasonSheet(data))
|
| 335 |
sheet_iterator+=1
|
344 |
sheet_iterator+=1
|
| 336 |
|
345 |
|
| 337 |
sheet = wbk.add_sheet('High TP SD')
|
346 |
sheet = wbk.add_sheet('High TP SD')
|
| 338 |
|
347 |
|
| 339 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
348 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| Line 381... |
Line 390... |
| 381 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
390 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
| 382 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
391 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
| 383 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
392 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
| 384 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
393 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
| 385 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
394 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
| 386 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
|
395 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2)+round(data.woodenPackagingCost,2))
|
| 387 |
sheet.write(sheet_iterator, 18, getReason(data))
|
396 |
sheet.write(sheet_iterator, 18, getReasonSheet(data))
|
| 388 |
sheet_iterator+=1
|
397 |
sheet_iterator+=1
|
| 389 |
|
398 |
|
| 390 |
sheet = wbk.add_sheet('Exceptions')
|
399 |
sheet = wbk.add_sheet('Exceptions')
|
| 391 |
|
400 |
|
| 392 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
401 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| Line 434... |
Line 443... |
| 434 |
print e
|
443 |
print e
|
| 435 |
print "Unable to send report.Trying with local SMTP"
|
444 |
print "Unable to send report.Trying with local SMTP"
|
| 436 |
smtpServer = smtplib.SMTP('localhost')
|
445 |
smtpServer = smtplib.SMTP('localhost')
|
| 437 |
smtpServer.set_debuglevel(1)
|
446 |
smtpServer.set_debuglevel(1)
|
| 438 |
sender = 'support@shop2020.in'
|
447 |
sender = 'support@shop2020.in'
|
| 439 |
#recipients = ['kshitij.sood@saholic.com']
|
448 |
recipients = ['kshitij.sood@saholic.com']
|
| 440 |
msg = MIMEMultipart()
|
449 |
msg = MIMEMultipart()
|
| 441 |
msg['Subject'] = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
|
450 |
msg['Subject'] = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
|
| 442 |
msg['From'] = sender
|
451 |
msg['From'] = sender
|
| 443 |
recipients = ['rajneesh.arora@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','sandeep.sachdeva@saholic.com']
|
452 |
#recipients = ['rajneesh.arora@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','sandeep.sachdeva@saholic.com']
|
| 444 |
msg['To'] = ",".join(recipients)
|
453 |
msg['To'] = ",".join(recipients)
|
| 445 |
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
|
454 |
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
|
| 446 |
fileMsg.set_payload(file(filename).read())
|
455 |
fileMsg.set_payload(file(filename).read())
|
| 447 |
email.encoders.encode_base64(fileMsg)
|
456 |
email.encoders.encode_base64(fileMsg)
|
| 448 |
fileMsg.add_header('Content-Disposition','attachment;filename=snapdeal_tp_recon.xls')
|
457 |
fileMsg.add_header('Content-Disposition','attachment;filename=snapdeal_tp_recon.xls')
|
| Line 452... |
Line 461... |
| 452 |
print "Successfully sent email"
|
461 |
print "Successfully sent email"
|
| 453 |
except:
|
462 |
except:
|
| 454 |
print "Error: unable to send email."
|
463 |
print "Error: unable to send email."
|
| 455 |
|
464 |
|
| 456 |
def getReason(data):
|
465 |
def getReason(data):
|
| - |
|
466 |
global courierCostToSync
|
| 457 |
reason=""
|
467 |
reason=""
|
| 458 |
if data.sellingPrice!=data.sellingPriceSnapdeal:
|
468 |
if data.sellingPrice!=data.sellingPriceSnapdeal:
|
| 459 |
reason+="Selling Price is different."
|
469 |
reason+="Selling Price is different."
|
| 460 |
if data.commissionPercentage!= round(float(data.fixedMarginPercentage)/1.1236,2):
|
470 |
if data.commissionPercentage!= round(float(data.fixedMarginPercentage)/1.1236,2):
|
| 461 |
reason+="Commission is different."
|
471 |
reason+="Commission is different."
|
| 462 |
if round(data.courierCost*1.1236)!=round(data.logisticCostSnapdeal):
|
472 |
if round(data.courierCost*1.1236)!=round(data.logisticCostSnapdeal+data.woodenPackagingCost):
|
| 463 |
reason+="Courier Cost is different-Check Weight."
|
473 |
reason+="Courier Cost is different-Check Weight."
|
| - |
|
474 |
courierCostToSync.append(data)
|
| 464 |
return reason
|
475 |
return reason
|
| - |
|
476 |
|
| - |
|
477 |
def getReasonSheet(data):
|
| - |
|
478 |
reason=""
|
| - |
|
479 |
if data.sellingPrice!=data.sellingPriceSnapdeal:
|
| - |
|
480 |
reason+="Selling Price is different."
|
| - |
|
481 |
if data.commissionPercentage!= round(float(data.fixedMarginPercentage)/1.1236,2):
|
| - |
|
482 |
reason+="Commission is different."
|
| - |
|
483 |
if round(data.courierCost*1.1236)!=round(data.logisticCostSnapdeal+data.woodenPackagingCost):
|
| - |
|
484 |
reason+="Courier Cost is different-Check Weight."
|
| - |
|
485 |
return reason
|
| - |
|
486 |
|
| - |
|
487 |
def syncCourierCost(courierCostToSync):
|
| - |
|
488 |
global oldPricing
|
| - |
|
489 |
for item in courierCostToSync:
|
| - |
|
490 |
sdItem = SnapdealItem.get_by(item_id=item.itemId)
|
| - |
|
491 |
mpItem = MarketplaceItems.get_by(itemId=item.itemId, source=OrderSource.SNAPDEAL)
|
| - |
|
492 |
oldMpItem = copy.deepcopy(mpItem)
|
| - |
|
493 |
temp = []
|
| - |
|
494 |
temp.append(item)
|
| - |
|
495 |
temp.append(oldMpItem)
|
| - |
|
496 |
addHistory(sdItem)
|
| - |
|
497 |
sdItem.courierCostMarketplace = round((item.logisticCostSnapdeal+item.woodenPackagingCost)/1.1236)
|
| - |
|
498 |
sdItem.transferPrice = getNewTp(mpItem,item)
|
| - |
|
499 |
sdItem.serviceTax = getNewServiceTax(mpItem,sdItem,item)
|
| - |
|
500 |
mpItem.courierCostMarketplace = round((item.logisticCostSnapdeal+item.woodenPackagingCost)/1.1236)
|
| - |
|
501 |
mpItem.currentTp = getNewTp(mpItem,item)
|
| - |
|
502 |
mpItem.minimumPossibleSp = getNewLowestPossibleSp(mpItem,sdItem,item)
|
| - |
|
503 |
temp.append(mpItem)
|
| - |
|
504 |
oldPricing.append(temp)
|
| - |
|
505 |
session.commit()
|
| - |
|
506 |
|
| - |
|
507 |
def addHistory(item):
|
| - |
|
508 |
itemHistory = MarketPlaceUpdateHistory()
|
| - |
|
509 |
itemHistory.item_id = item.item_id
|
| - |
|
510 |
itemHistory.source = OrderSource.SNAPDEAL
|
| - |
|
511 |
itemHistory.exceptionPrice = item.exceptionPrice
|
| - |
|
512 |
itemHistory.warehouseId = item.warehouseId
|
| - |
|
513 |
itemHistory.isListedOnSource = item.isListedOnSnapdeal
|
| - |
|
514 |
itemHistory.transferPrice = item.transferPrice
|
| - |
|
515 |
itemHistory.sellingPrice = item.sellingPrice
|
| - |
|
516 |
itemHistory.courierCost = item.courierCost
|
| - |
|
517 |
itemHistory.commission = item.commission
|
| - |
|
518 |
itemHistory.serviceTax = item.serviceTax
|
| - |
|
519 |
itemHistory.suppressPriceFeed = item.suppressPriceFeed
|
| - |
|
520 |
itemHistory.suppressInventoryFeed = item.suppressInventoryFeed
|
| - |
|
521 |
itemHistory.updatedOn = item.updatedOn
|
| - |
|
522 |
itemHistory.maxNlc = item.maxNlc
|
| - |
|
523 |
itemHistory.skuAtSource = item.skuAtSnapdeal
|
| - |
|
524 |
itemHistory.marketPlaceSerialNumber = item.supc
|
| - |
|
525 |
itemHistory.priceUpdatedBy = item.priceUpdatedBy
|
| - |
|
526 |
itemHistory.courierCostMarketplace = item.courierCostMarketplace
|
| 465 |
|
527 |
|
| 466 |
|
528 |
|
| - |
|
529 |
|
| - |
|
530 |
def getNewTp(mpItem,data):
|
| - |
|
531 |
ourTp = mpItem.currentSp- mpItem.currentSp*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-((data.logisticCostSnapdeal+data.woodenPackagingCost)/1.1236+mpItem.closingFee)*(1+(mpItem.serviceTax/100))-(max(20,(mpItem.pgFee/100)*mpItem.currentSp)*(1+(mpItem.serviceTax/100)));
|
| - |
|
532 |
return round(ourTp,2)
|
| - |
|
533 |
|
| - |
|
534 |
def getNewServiceTax(mpItem,sdItem,data):
|
| - |
|
535 |
return round(mpItem.serviceTax/100*(sdItem.commission+(data.logisticCostSnapdeal+data.woodenPackagingCost)/1.1236),2)
|
| - |
|
536 |
|
| - |
|
537 |
def getNewLowestPossibleSp(mpItem,sdItem,data):
|
| - |
|
538 |
if (mpItem.pgFee/100)*mpItem.currentSp>=20:
|
| - |
|
539 |
lowestPossibleSp = (sdItem.maxNlc+(((data.logisticCostSnapdeal+data.woodenPackagingCost)/1.1236)+mpItem.closingFee)*(1+(mpItem.serviceTax/100))*(1+(mpItem.vat/100))+(15+mpItem.otherCost)*(1+(mpItem.vat)/100))/(1-(mpItem.commission/100+mpItem.emiFee/100+mpItem.pgFee/100)*(1+(mpItem.serviceTax/100))*(1+(mpItem.vat)/100)-(mpItem.returnProvision/100)*(1+(mpItem.vat)/100));
|
| - |
|
540 |
else:
|
| - |
|
541 |
lowestPossibleSp = (sdItem.maxNlc+(((data.logisticCostSnapdeal+data.woodenPackagingCost)/1.1236)+mpItem.closingFee+20)*(1+(mpItem.serviceTax/100))*(1+(mpItem.vat/100))+(15+mpItem.otherCost)*(1+(mpItem.vat)/100))/(1-(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))*(1+(mpItem.vat)/100)-(mpItem.returnProvision/100)*(1+(mpItem.vat)/100));
|
| - |
|
542 |
return round(lowestPossibleSp,2)
|
| - |
|
543 |
|
| - |
|
544 |
def sendCCSyncMail():
|
| - |
|
545 |
if len(courierCostToSync) == 0:
|
| - |
|
546 |
return
|
| - |
|
547 |
xstr = lambda s: s or ""
|
| - |
|
548 |
message="""<html>
|
| - |
|
549 |
<body>
|
| - |
|
550 |
<h3>Courier cost synced</h3>
|
| - |
|
551 |
<table border="1" style="width:100%;">
|
| - |
|
552 |
<thead>
|
| - |
|
553 |
<tr><th>Item Id</th>
|
| - |
|
554 |
<th>Product Name</th>
|
| - |
|
555 |
<th>Selling Price</th>
|
| - |
|
556 |
<th>Old Transfer Price</th>
|
| - |
|
557 |
<th>New Transfer Price</th>
|
| - |
|
558 |
<th>Old Courier Cost</th>
|
| - |
|
559 |
<th>New Courier Cost</th>
|
| - |
|
560 |
<th>Old Margin</th>
|
| - |
|
561 |
<th>New Margin</th>
|
| - |
|
562 |
<th>Old Margin %</th>
|
| - |
|
563 |
<th>New Margin %</th>
|
| - |
|
564 |
</tr></thead>
|
| - |
|
565 |
<tbody>"""
|
| - |
|
566 |
for value in oldPricing:
|
| - |
|
567 |
data = value[0]
|
| - |
|
568 |
mpItemOld = value[1]
|
| - |
|
569 |
mpItemNew = value[2]
|
| - |
|
570 |
message+="""<tr>
|
| - |
|
571 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
| - |
|
572 |
<td style="text-align:center">"""+xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color)+"""</td>
|
| - |
|
573 |
<td style="text-align:center">"""+str(mpItemOld.currentSp)+"""</td>
|
| - |
|
574 |
<td style="text-align:center">"""+str(mpItemOld.currentTp)+"""</td>
|
| - |
|
575 |
<td style="text-align:center">"""+str(mpItemNew.currentTp)+"""</td>
|
| - |
|
576 |
<td style="text-align:center">"""+str(mpItemOld.courierCostMarketplace)+"""</td>
|
| - |
|
577 |
<td style="text-align:center">"""+str(mpItemNew.courierCostMarketplace)+"""</td>
|
| - |
|
578 |
<td style="text-align:center">"""+str(round(mpItemOld.currentTp-mpItemOld.minimumPossibleTp))+"""</td>
|
| - |
|
579 |
<td style="text-align:center">"""+str(round(mpItemNew.currentTp-mpItemNew.minimumPossibleTp))+"""</td>
|
| - |
|
580 |
<td style="text-align:center">"""+str(round(((mpItemOld.currentTp-mpItemOld.minimumPossibleTp)/mpItemOld.currentSp)*100,2))+"""</td>
|
| - |
|
581 |
<td style="text-align:center">"""+str(round(((mpItemNew.currentTp-mpItemNew.minimumPossibleTp)/mpItemNew.currentSp)*100,2))+"""</td>
|
| - |
|
582 |
</tr>"""
|
| - |
|
583 |
message+="""</tbody></table></body></html>"""
|
| - |
|
584 |
print message
|
| - |
|
585 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
| - |
|
586 |
mailServer.ehlo()
|
| - |
|
587 |
mailServer.starttls()
|
| - |
|
588 |
mailServer.ehlo()
|
| - |
|
589 |
|
| - |
|
590 |
#recipients = ['kshitij.sood@saholic.com']
|
| - |
|
591 |
recipients = ['rajneesh.arora@saholic.com','rajveer.singh@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','sandeep.sachdeva@saholic.com']
|
| - |
|
592 |
msg = MIMEMultipart()
|
| - |
|
593 |
msg['Subject'] = "Snapdeal Courier Cost Synced" + ' - ' + str(datetime.now())
|
| - |
|
594 |
msg['From'] = ""
|
| - |
|
595 |
msg['To'] = ",".join(recipients)
|
| - |
|
596 |
msg.preamble = "Snapdeal Courier Cost Synced" + ' - ' + str(datetime.now())
|
| - |
|
597 |
html_msg = MIMEText(message, 'html')
|
| - |
|
598 |
msg.attach(html_msg)
|
| - |
|
599 |
try:
|
| - |
|
600 |
mailServer.login("build@shop2020.in", "cafe@nes")
|
| - |
|
601 |
#mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
|
| - |
|
602 |
mailServer.sendmail("cafe@nes", recipients, msg.as_string())
|
| - |
|
603 |
except Exception as e:
|
| - |
|
604 |
print e
|
| - |
|
605 |
print "Unable to send Snapdeal Courier Cost mail.Lets try with local SMTP."
|
| - |
|
606 |
smtpServer = smtplib.SMTP('localhost')
|
| - |
|
607 |
smtpServer.set_debuglevel(1)
|
| - |
|
608 |
sender = 'support@shop2020.in'
|
| - |
|
609 |
try:
|
| - |
|
610 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| - |
|
611 |
print "Successfully sent email"
|
| - |
|
612 |
except:
|
| - |
|
613 |
print "Error: unable to send email."
|
| - |
|
614 |
|
| 467 |
def main():
|
615 |
def main():
|
| 468 |
print "Opening snapdeal seller login page"
|
616 |
print "Opening snapdeal seller login page"
|
| 469 |
br = login("http://selleraccounts.snapdeal.com/")
|
617 |
br = login("http://selleraccounts.snapdeal.com/")
|
| 470 |
exceptionList, fetchedItems = populateStuff(br)
|
618 |
exceptionList, fetchedItems = populateStuff(br)
|
| 471 |
filteredData = filterData(fetchedItems)
|
619 |
filteredData = filterData(fetchedItems)
|
| 472 |
sendMail(filteredData,exceptionList)
|
620 |
sendMail(filteredData,exceptionList)
|
| 473 |
write_report(filteredData,exceptionList)
|
621 |
write_report(filteredData,exceptionList)
|
| - |
|
622 |
syncCourierCost(courierCostToSync)
|
| - |
|
623 |
sendCCSyncMail()
|
| 474 |
|
624 |
|
| 475 |
|
625 |
|
| 476 |
if __name__ == "__main__":
|
626 |
if __name__ == "__main__":
|
| 477 |
main()
|
627 |
main()
|
| 478 |
|
628 |
|