| Line 5... |
Line 5... |
| 5 |
'''
|
5 |
'''
|
| 6 |
|
6 |
|
| 7 |
from shop2020.logistics.service.impl import DataService
|
7 |
from shop2020.logistics.service.impl import DataService
|
| 8 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
8 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
| 9 |
DeliveryEstimate, WarehouseAllocation, \
|
9 |
DeliveryEstimate, WarehouseAllocation, \
|
| 10 |
PublicHolidays, ServiceableLocationDetails, DestinationProviderAllocation
|
10 |
PublicHolidays, ServiceableLocationDetails
|
| 11 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException,\
|
11 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException,\
|
| 12 |
DeliveryType
|
12 |
DeliveryType
|
| 13 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
13 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
| 14 |
from elixir import session
|
14 |
from elixir import session
|
| 15 |
import datetime, time
|
15 |
import datetime, time
|
| Line 18... |
Line 18... |
| 18 |
logging.basicConfig(level=logging.DEBUG)
|
18 |
logging.basicConfig(level=logging.DEBUG)
|
| 19 |
|
19 |
|
| 20 |
warehouse_allocation_cache = {}
|
20 |
warehouse_allocation_cache = {}
|
| 21 |
serviceable_location_cache = {}
|
21 |
serviceable_location_cache = {}
|
| 22 |
delivery_estimate_cache = {}
|
22 |
delivery_estimate_cache = {}
|
| 23 |
destination_provider_allocation_cache = {}
|
- |
|
| 24 |
ncr_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
|
23 |
ncr_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
|
| 25 |
'110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
|
24 |
'110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
|
| 26 |
'110031','110032','110033','110034','110035','110038','110041','110044','110045','110046','110047','110048','110049','110051','110052',\
|
25 |
'110031','110032','110033','110034','110035','110038','110041','110044','110045','110046','110047','110048','110049','110051','110052',\
|
| 27 |
'110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065','110066','110067',\
|
26 |
'110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065','110066','110067',\
|
| 28 |
'110068','110070','110071','110074','110075','110076','110078','110081','110082','110083','110084','110085','110086','110087','110088',\
|
27 |
'110068','110070','110071','110074','110075','110076','110078','110081','110082','110083','110084','110085','110086','110087','110088',\
|
| Line 48... |
Line 47... |
| 48 |
DataService.initialize(dbname, db_hostname)
|
47 |
DataService.initialize(dbname, db_hostname)
|
| 49 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
48 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
| 50 |
__cache_warehouse_allocation_table()
|
49 |
__cache_warehouse_allocation_table()
|
| 51 |
__cache_serviceable_location_details_table()
|
50 |
__cache_serviceable_location_details_table()
|
| 52 |
__cache_delivery_estimate_table()
|
51 |
__cache_delivery_estimate_table()
|
| 53 |
__cache_destination_provider_allocation_table()
|
- |
|
| 54 |
close_session()
|
52 |
close_session()
|
| 55 |
print "Done cache population at: " + str(datetime.datetime.now())
|
53 |
print "Done cache population at: " + str(datetime.datetime.now())
|
| 56 |
|
54 |
|
| 57 |
def __cache_delivery_estimate_table():
|
55 |
def __cache_delivery_estimate_table():
|
| 58 |
delivery_estimates = DeliveryEstimate.query.all()
|
56 |
delivery_estimates = DeliveryEstimate.query.all()
|
| Line 73... |
Line 71... |
| 73 |
def __cache_warehouse_allocation_table():
|
71 |
def __cache_warehouse_allocation_table():
|
| 74 |
warehouse_allocations = WarehouseAllocation.query.all()
|
72 |
warehouse_allocations = WarehouseAllocation.query.all()
|
| 75 |
for warehouse_allocation in warehouse_allocations:
|
73 |
for warehouse_allocation in warehouse_allocations:
|
| 76 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
74 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
| 77 |
|
75 |
|
| 78 |
def __cache_destination_provider_allocation_table():
|
- |
|
| 79 |
destiontion_providers = DestinationProviderAllocation.query.all()
|
- |
|
| 80 |
for destiontion_provider in destiontion_providers:
|
- |
|
| 81 |
destination_provider_allocation_cache[destiontion_provider.destination_pin] = destiontion_provider.provider_less_amount.id, destiontion_provider.provider_more_amount.id
|
- |
|
| 82 |
|
- |
|
| 83 |
def get_provider(provider_id):
|
76 |
def get_provider(provider_id):
|
| 84 |
provider = Provider.get_by(id=provider_id)
|
77 |
provider = Provider.get_by(id=provider_id)
|
| 85 |
return provider
|
78 |
return provider
|
| 86 |
|
79 |
|
| 87 |
def get_providers():
|
80 |
def get_providers():
|
| Line 119... |
Line 112... |
| 119 |
dest_code, exp, iscod, station_type = serviceable_location_cache.get(1).get(destination_pin)
|
112 |
dest_code, exp, iscod, station_type = serviceable_location_cache.get(1).get(destination_pin)
|
| 120 |
iscod = iscod and item_selling_price <= 10000
|
113 |
iscod = iscod and item_selling_price <= 10000
|
| 121 |
return 1, iscod
|
114 |
return 1, iscod
|
| 122 |
else:
|
115 |
else:
|
| 123 |
return None, False
|
116 |
return None, False
|
| 124 |
'''
|
117 |
|
| 125 |
for provider_id, value in serviceable_location_cache.iteritems():
|
- |
|
| 126 |
try:
|
- |
|
| 127 |
dest_code, exp, cod, station_type = value[destination_pin]
|
- |
|
| 128 |
except:
|
- |
|
| 129 |
print "Unexpected error:", sys.exc_info()[0]
|
- |
|
| 130 |
continue
|
- |
|
| 131 |
if type == DeliveryType.PREPAID and exp:
|
- |
|
| 132 |
ret_provider_list.append(provider_id)
|
- |
|
| 133 |
if type == DeliveryType.COD and cod:
|
- |
|
| 134 |
ret_provider_list.append(provider_id)
|
- |
|
| 135 |
#FIXME As per ticket location from where only Aramex is servicing, should not be given to Aramex.
|
- |
|
| 136 |
if len(ret_provider_list) == 1:
|
- |
|
| 137 |
if ret_provider_list.__contains__(1):
|
- |
|
| 138 |
return ret_provider_list[0]
|
- |
|
| 139 |
else:
|
- |
|
| 140 |
return None
|
- |
|
| 141 |
elif len(ret_provider_list) == 0:
|
- |
|
| 142 |
return None
|
- |
|
| 143 |
elif destination_provider_allocation_cache.has_key(destination_pin):
|
- |
|
| 144 |
if item_selling_price < 10000:
|
- |
|
| 145 |
return destination_provider_allocation_cache.get(destination_pin)[0]
|
- |
|
| 146 |
else:
|
- |
|
| 147 |
return destination_provider_allocation_cache.get(destination_pin)[1]
|
- |
|
| 148 |
else:
|
- |
|
| 149 |
return ret_provider_list[0]
|
- |
|
| 150 |
'''
|
- |
|
| 151 |
|
118 |
|
| 152 |
def add_empty_AWBs(numbers, provider_id, type):
|
119 |
def add_empty_AWBs(numbers, provider_id, type):
|
| 153 |
for number in numbers:
|
120 |
for number in numbers:
|
| 154 |
query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
|
121 |
query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
|
| 155 |
try:
|
122 |
try:
|