Subversion Repositories SmartDukaan

Rev

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

Rev 11753 Rev 11777
Line 1200... Line 1200...
1200
    except Exception as e:
1200
    except Exception as e:
1201
        print e
1201
        print e
1202
        print "Unable to send report.Trying with local SMTP"
1202
        print "Unable to send report.Trying with local SMTP"
1203
        smtpServer = smtplib.SMTP('localhost')
1203
        smtpServer = smtplib.SMTP('localhost')
1204
        smtpServer.set_debuglevel(1)
1204
        smtpServer.set_debuglevel(1)
1205
        sender = 'support@shop2020.in'
1205
        sender = 'build@shop2020.in'
1206
        #recipients = ['kshitij.sood@saholic.com']
1206
        #recipients = ['kshitij.sood@saholic.com']
1207
        msg = MIMEMultipart()
1207
        msg = MIMEMultipart()
1208
        msg['Subject'] = "Snapdeal Auto Pricing " +runType+" " + str(timestamp)
1208
        msg['Subject'] = "Snapdeal Auto Pricing " +runType+" " + str(timestamp)
1209
        msg['From'] = sender
1209
        msg['From'] = sender
1210
        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']
1210
        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']
Line 1561... Line 1561...
1561
    except Exception as e:
1561
    except Exception as e:
1562
        print e
1562
        print e
1563
        print "Unable to send pricing mail.Lets try with local SMTP."
1563
        print "Unable to send pricing mail.Lets try with local SMTP."
1564
        smtpServer = smtplib.SMTP('localhost')
1564
        smtpServer = smtplib.SMTP('localhost')
1565
        smtpServer.set_debuglevel(1)
1565
        smtpServer.set_debuglevel(1)
1566
        sender = 'support@shop2020.in'
1566
        sender = 'build@shop2020.in'
1567
        try:
1567
        try:
1568
            smtpServer.sendmail(sender, recipients, msg.as_string())
1568
            smtpServer.sendmail(sender, recipients, msg.as_string())
1569
            print "Successfully sent email"
1569
            print "Successfully sent email"
1570
        except:
1570
        except:
1571
            print "Error: unable to send email."
1571
            print "Error: unable to send email."
Line 1756... Line 1756...
1756
    except Exception as e:
1756
    except Exception as e:
1757
        print e
1757
        print e
1758
        print "Unable to send lost buy box mail.Lets try local SMTP"
1758
        print "Unable to send lost buy box mail.Lets try local SMTP"
1759
        smtpServer = smtplib.SMTP('localhost')
1759
        smtpServer = smtplib.SMTP('localhost')
1760
        smtpServer.set_debuglevel(1)
1760
        smtpServer.set_debuglevel(1)
1761
        sender = 'support@shop2020.in'
1761
        sender = 'build@shop2020.in'
1762
        try:
1762
        try:
1763
            smtpServer.sendmail(sender, recipients, msg.as_string())
1763
            smtpServer.sendmail(sender, recipients, msg.as_string())
1764
            print "Successfully sent email"
1764
            print "Successfully sent email"
1765
        except:
1765
        except:
1766
            print "Error: unable to send email."
1766
            print "Error: unable to send email."
Line 1858... Line 1858...
1858
                latestItemData.toGroup=True
1858
                latestItemData.toGroup=True
1859
                data.toGroup=False
1859
                data.toGroup=False
1860
        else:
1860
        else:
1861
            latestItemData=None
1861
            latestItemData=None
1862
    session.commit()
1862
    session.commit()
-
 
1863
 
-
 
1864
def sendAlertForNegativeMargins(timestamp):
-
 
1865
    xstr = lambda s: s or ""
-
 
1866
    negativeMargins = session.query(MarketPlaceHistory,Item).join((Item,MarketPlaceHistory.item_id==Item.id)).filter(MarketPlaceHistory.timestamp==timestamp).filter(MarketPlaceHistory.source==OrderSource.SNAPDEAL).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.NEGATIVE_MARGIN).all()
-
 
1867
    if len(negativeMargins) == 0:
-
 
1868
        return
-
 
1869
    message="""<html>
-
 
1870
            <body>
-
 
1871
            <h3 style="color:red;font-weight:bold;">Snapdeal Negative Margins</h3>
-
 
1872
            <table border="1" style="width:100%;">
-
 
1873
            <thead>
-
 
1874
            <tr><th>Item Id</th>
-
 
1875
            <th>Product Name</th>
-
 
1876
            <th>SP</th>
-
 
1877
            <th>TP</th>
-
 
1878
            <th>Lowest Possible SP</th>
-
 
1879
            <th>Lowest Possible TP</th>
-
 
1880
            <th>Margin</th>
-
 
1881
            <th>Margin %</th>
-
 
1882
            <th>Flipkart Inventory</th>
-
 
1883
            <th>Total Inventory</th>
-
 
1884
            <th>Sales History</th>
-
 
1885
            </tr></thead>
-
 
1886
            <tbody>"""
-
 
1887
    for item in negativeMargins:
-
 
1888
        mpHistory = item[0]
-
 
1889
        catItem = item[1]
-
 
1890
        netInventory=''
-
 
1891
        if not inventoryMap.has_key(mpHistory.item_id):
-
 
1892
            netInventory='Info Not Available'
-
 
1893
        else:
-
 
1894
            netInventory = str(getNetAvailability(inventoryMap.get(mpHistory.item_id)))
-
 
1895
        message+="""<tr>
-
 
1896
            <td style="text-align:center">"""+str(mpHistory.item_id)+"""</td>
-
 
1897
            <td style="text-align:center">"""+xstr(catItem.brand)+" "+xstr(catItem.model_name)+" "+xstr(catItem.model_number)+" "+xstr(catItem.color)+"""</td>
-
 
1898
            <td style="text-align:center">"""+str(mpHistory.ourSellingPrice)+"""</td>
-
 
1899
            <td style="text-align:center">"""+str(mpHistory.ourTp)+"""</td>
-
 
1900
            <td style="text-align:center">"""+str(mpHistory.lowestPossibleSp)+"""</td>
-
 
1901
            <td style="text-align:center">"""+str(mpHistory.lowestPossibleTp)+"""</td>
-
 
1902
            <td style="text-align:center">"""+str(mpHistory.margin)+"""</td>
-
 
1903
            <td style="text-align:center">"""+str(round(mpHistory.margin/mpHistory.ourSellingPrice,2))+"""</td>
-
 
1904
            <td style="text-align:center">"""+str(mpHistory.ourInventory)+"""</td>
-
 
1905
            <td style="text-align:center">"""+netInventory+"""</td>
-
 
1906
            <td style="text-align:center">"""+getOosString((itemSaleMap.get(mpHistory.item_id))[1])+"""</td>
-
 
1907
            </tr>"""
-
 
1908
    message+="""</tbody></table></body></html>"""
-
 
1909
    print message
-
 
1910
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
-
 
1911
    mailServer.ehlo()
-
 
1912
    mailServer.starttls()
-
 
1913
    mailServer.ehlo()
-
 
1914
 
-
 
1915
    #recipients = ['kshitij.sood@saholic.com']
-
 
1916
    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']
-
 
1917
    msg = MIMEMultipart()
-
 
1918
    msg['Subject'] = "Snapdeal Negative Margin" + ' - ' + str(datetime.now())
-
 
1919
    msg['From'] = ""
-
 
1920
    msg['To'] = ",".join(recipients)
-
 
1921
    msg.preamble = "Snapdeal Negative Margin" + ' - ' + str(datetime.now())
-
 
1922
    html_msg = MIMEText(message, 'html')
-
 
1923
    msg.attach(html_msg)
-
 
1924
    try:
-
 
1925
        mailServer.login("build@shop2020.in", "cafe@nes")
-
 
1926
        #mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
-
 
1927
        mailServer.sendmail("cafe@nes", recipients, msg.as_string())
-
 
1928
    except Exception as e:
-
 
1929
        print e
-
 
1930
        print "Unable to send Snapdeal Negative margin mail.Lets try local SMTP"
-
 
1931
        smtpServer = smtplib.SMTP('localhost')
-
 
1932
        smtpServer.set_debuglevel(1)
-
 
1933
        sender = 'build@shop2020.in'
-
 
1934
        try:
-
 
1935
            smtpServer.sendmail(sender, recipients, msg.as_string())
-
 
1936
            print "Successfully sent email"
-
 
1937
        except:
-
 
1938
            print "Error: unable to send email."
-
 
1939
 
1863
     
1940
     
1864
    
1941
    
1865
def main():
1942
def main():
1866
    parser = optparse.OptionParser()
1943
    parser = optparse.OptionParser()
1867
    parser.add_option("-t", "--type", dest="runType",
1944
    parser.add_option("-t", "--type", dest="runType",
Line 1887... Line 1964...
1887
    successfulAutoIncrease = fetchItemsForAutoIncrease(timestamp)
1964
    successfulAutoIncrease = fetchItemsForAutoIncrease(timestamp)
1888
    if options.runType=='FULL':
1965
    if options.runType=='FULL':
1889
        previousAutoFav, nowAutoFav = markAutoFavourite()
1966
        previousAutoFav, nowAutoFav = markAutoFavourite()
1890
    if options.runType=='FULL':
1967
    if options.runType=='FULL':
1891
        writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, previousAutoFav, nowAutoFav,timestamp, options.runType)
1968
        writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, previousAutoFav, nowAutoFav,timestamp, options.runType)
-
 
1969
        sendAlertForNegativeMargins(timestamp)
1892
    else:
1970
    else:
1893
        writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, None, None, timestamp, options.runType)
1971
        writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, None, None, timestamp, options.runType)
1894
    commitPricing(successfulAutoDecrease,successfulAutoIncrease,timestamp)
1972
    commitPricing(successfulAutoDecrease,successfulAutoIncrease,timestamp)
1895
    sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
1973
    sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
1896
    processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
1974
    processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)