Subversion Repositories SmartDukaan

Rev

Rev 23132 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/python

'''
Loads the static logic of assigning provider to a particular pincode
into the DestinationProviderAllocation table.

It reads the logic from a XLS workbook containing two sheets. The first sheet is
for shipments worth less than Rs 5000. The second sheet is for shipments costing
more than Rs 5000.

@attention: This script may need enhancement if we want to differentiate between
COD and Prepaid orders.

@attention: This table is not being used currently. If and when this comes into 
use, please remember to update the logic of get_logistics_estimation 
in DataAccessor.py. 

@author: Ankur Singhal
'''
from datetime import *
from elixir import *
from shop2020.logistics.service.impl import DataService, EcomExpressService
from shop2020.logistics.service.impl.DataService import \
    ServiceableLocationDetails
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
import optparse

if __name__ == '__main__' and __package__ is None:
    import sys
    import os
    sys.path.insert(0, os.getcwd())



def main():
    parser = optparse.OptionParser()
    parser.add_option("-H", "--host", dest="hostname",
                  default="localhost",
                  type="string", help="The HOST where the DB server is running",
                  metavar="HOST")
    parser.add_option("-P", "--provider_id", dest="provider_id",
                  default="localhost",
                  type="string", help="The HOST where the DB server is running",
                  metavar="HOST")
    (options, args) = parser.parse_args()
    if len(args) != 0:
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
    provider_id = options.provider_id
    hostname = options.hostname
    if provider_id is None or hostname is None:
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
    
    DataService.initialize(dbname='logistics', db_hostname=hostname)
    if provider_id=="49":
        subject = "Tat is missing for Ecom Express active pincodes"
        missingPincodes = []
        serviceabilityPincodeList = EcomExpressService.getServiceablePinCodes(datetime.now()-timedelta(days=5))
        #print "serviceabilityPincodeList", serviceabilityPincodeList
        for serviceabilityPincode in serviceabilityPincodeList:
            pincode = str(serviceabilityPincode["pincode"])
            serviceableLocationDetails = ServiceableLocationDetails.query.filter_by(provider_id=int(provider_id)).filter_by(dest_pincode=pincode).first()
            if serviceableLocationDetails:
                if serviceabilityPincode['active']:
                    serviceableLocationDetails.exp=1
                    serviceableLocationDetails.cod=1
                else:
                    serviceableLocationDetails.exp=0
                    serviceableLocationDetails.cod=0
                    
            elif serviceabilityPincode['active']:
                missingPincodes.append(pincode)
        print missingPincodes
        if missingPincodes:
            subject += " - " + ", ".join(missingPincodes)
            mail("cnc.center@shop2020.in", "5h0p2o2o", ["deena.nath@smartdukaan.com"], subject, text="")
        
    session.commit()
    session.close()
                
        
if __name__ == '__main__':
    main()