| Line 15... |
Line 15... |
| 15 |
use, please remember to update the logic of get_logistics_estimation
|
15 |
use, please remember to update the logic of get_logistics_estimation
|
| 16 |
in DataAccessor.py.
|
16 |
in DataAccessor.py.
|
| 17 |
|
17 |
|
| 18 |
@author: Ankur Singhal
|
18 |
@author: Ankur Singhal
|
| 19 |
'''
|
19 |
'''
|
| 20 |
import optparse
|
20 |
from datetime import *
|
| 21 |
import xlrd
|
- |
|
| 22 |
from elixir import *
|
21 |
from elixir import *
|
| - |
|
22 |
from shop2020.logistics.service.impl import DataService, EcomExpressService
|
| 23 |
from shop2020.thriftpy.model.v1 import inventory
|
23 |
from shop2020.logistics.service.impl.DataService import \
|
| - |
|
24 |
ServiceableLocationDetails
|
| - |
|
25 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| - |
|
26 |
import optparse
|
| 24 |
|
27 |
|
| 25 |
if __name__ == '__main__' and __package__ is None:
|
28 |
if __name__ == '__main__' and __package__ is None:
|
| 26 |
import sys
|
29 |
import sys
|
| 27 |
import os
|
30 |
import os
|
| 28 |
sys.path.insert(0, os.getcwd())
|
31 |
sys.path.insert(0, os.getcwd())
|
| 29 |
|
32 |
|
| 30 |
from shop2020.logistics.service.impl import DataService
|
- |
|
| 31 |
from shop2020.logistics.service.impl.DataService import Provider, DestinationProviderAllocation
|
- |
|
| 32 |
from shop2020.thriftpy.model.v1.inventory.ttypes import WarehouseLocation, InventoryServiceException
|
- |
|
| 33 |
|
33 |
|
| 34 |
def load_providers(filename, sheet_no, db_hostname):
|
- |
|
| 35 |
DataService.initialize(dbname='logistics', db_hostname=db_hostname)
|
- |
|
| 36 |
|
- |
|
| 37 |
workbook = xlrd.open_workbook(filename)
|
- |
|
| 38 |
sheet = workbook.sheet_by_index(sheet_no)
|
- |
|
| 39 |
num_rows = sheet.nrows
|
- |
|
| 40 |
providers = Provider.query.all()
|
- |
|
| 41 |
provider_map = dict([(p.name, p) for p in providers])
|
- |
|
| 42 |
provider_for_warehouse_location = {}
|
- |
|
| 43 |
|
- |
|
| 44 |
for rownum in range(1, num_rows):
|
- |
|
| 45 |
dest_pincode, provider_for_warehouse_location[WarehouseLocation.Delhi], provider_for_warehouse_location[WarehouseLocation.Mumbai],\
|
- |
|
| 46 |
provider_for_warehouse_location[WarehouseLocation.Karnataka], provider_for_warehouse_location[WarehouseLocation.Telangana] = sheet.row_values(rownum)[0:5]
|
- |
|
| 47 |
dest_pincode = str(int(dest_pincode))
|
- |
|
| 48 |
|
- |
|
| 49 |
for warehouse_loc, provider_name in provider_for_warehouse_location.iteritems():
|
- |
|
| 50 |
if provider_name == '' or provider_name == None:
|
- |
|
| 51 |
continue
|
- |
|
| 52 |
try:
|
- |
|
| 53 |
query = DestinationProviderAllocation.query.filter_by(destination_pin = dest_pincode)
|
- |
|
| 54 |
query = query.filter_by(warehouse_location = warehouse_loc)
|
- |
|
| 55 |
dpa = query.one()
|
- |
|
| 56 |
except:
|
- |
|
| 57 |
dpa = DestinationProviderAllocation()
|
- |
|
| 58 |
dpa.destination_pin = dest_pincode
|
- |
|
| 59 |
dpa.warehouse_location = warehouse_loc
|
- |
|
| 60 |
provider = provider_map[provider_name]
|
- |
|
| 61 |
if provider is None:
|
- |
|
| 62 |
raise InventoryServiceException(103, "Invalid provider --> " + provider_name)
|
- |
|
| 63 |
if sheet_no == 0:
|
- |
|
| 64 |
dpa.provider_less_amount = provider
|
- |
|
| 65 |
else:
|
- |
|
| 66 |
dpa.provider_more_amount = provider
|
- |
|
| 67 |
session.commit()
|
- |
|
| 68 |
|
34 |
|
| 69 |
def main():
|
35 |
def main():
|
| 70 |
parser = optparse.OptionParser()
|
36 |
parser = optparse.OptionParser()
|
| 71 |
parser.add_option("-f", "--file", dest="filename",
|
- |
|
| 72 |
default="DestinationProviderAllocation.xls", type="string",
|
- |
|
| 73 |
help="Read the providers list for different destinations and warehouse locations from FILE",
|
- |
|
| 74 |
metavar="FILE")
|
- |
|
| 75 |
parser.add_option("-H", "--host", dest="hostname",
|
37 |
parser.add_option("-H", "--host", dest="hostname",
|
| 76 |
default="localhost",
|
38 |
default="localhost",
|
| 77 |
type="string", help="The HOST where the DB server is running",
|
39 |
type="string", help="The HOST where the DB server is running",
|
| 78 |
metavar="HOST")
|
40 |
metavar="HOST")
|
| - |
|
41 |
parser.add_option("-P", "--provider_id", dest="provider_id",
|
| - |
|
42 |
default="localhost",
|
| - |
|
43 |
type="string", help="The HOST where the DB server is running",
|
| - |
|
44 |
metavar="HOST")
|
| 79 |
(options, args) = parser.parse_args()
|
45 |
(options, args) = parser.parse_args()
|
| 80 |
if len(args) != 0:
|
46 |
if len(args) != 0:
|
| 81 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
47 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| - |
|
48 |
provider_id = options.provider_id
|
| 82 |
filename = options.filename
|
49 |
hostname = options.hostname
|
| 83 |
if filename is None:
|
50 |
if provider_id is None or hostname is None:
|
| 84 |
parser.error("A filename must be provided. Use -h for more details.")
|
51 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| - |
|
52 |
|
| 85 |
load_providers(filename, 0, options.hostname)
|
53 |
DataService.initialize(dbname='logistics', db_hostname=hostname)
|
| - |
|
54 |
if provider_id=="49":
|
| - |
|
55 |
subject = "Tat is missing for Ecom Express active pincodes"
|
| - |
|
56 |
missingPincodes = []
|
| - |
|
57 |
serviceabilityPincodeList = EcomExpressService.getServiceablePinCodes(datetime.now()-timedelta(days=5))
|
| - |
|
58 |
#print "serviceabilityPincodeList", serviceabilityPincodeList
|
| - |
|
59 |
for serviceabilityPincode in serviceabilityPincodeList:
|
| - |
|
60 |
pincode = str(serviceabilityPincode["pincode"])
|
| - |
|
61 |
serviceableLocationDetails = ServiceableLocationDetails.query.filter_by(provider_id=int(provider_id)).filter_by(dest_pincode=pincode).first()
|
| 86 |
load_providers(filename, 1, options.hostname)
|
62 |
if serviceableLocationDetails:
|
| - |
|
63 |
if serviceabilityPincode['active']:
|
| - |
|
64 |
serviceableLocationDetails.exp=1
|
| - |
|
65 |
serviceableLocationDetails.cod=1
|
| - |
|
66 |
else:
|
| - |
|
67 |
serviceableLocationDetails.exp=0
|
| - |
|
68 |
serviceableLocationDetails.cod=0
|
| - |
|
69 |
|
| - |
|
70 |
elif serviceabilityPincode['active']:
|
| - |
|
71 |
missingPincodes.append(pincode)
|
| - |
|
72 |
print missingPincodes
|
| - |
|
73 |
if missingPincodes:
|
| - |
|
74 |
subject += " - " + ", ".join(missingPincodes)
|
| - |
|
75 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["deena.nath@profitmandi.com"], subject, text="")
|
| - |
|
76 |
|
| - |
|
77 |
session.commit()
|
| - |
|
78 |
session.close()
|
| - |
|
79 |
|
| 87 |
|
80 |
|
| 88 |
if __name__ == '__main__':
|
81 |
if __name__ == '__main__':
|
| 89 |
main()
|
82 |
main()
|
| 90 |
|
83 |
|