| Line 37... |
Line 37... |
| 37 |
|
37 |
|
| 38 |
'''
|
38 |
'''
|
| 39 |
This class is for only data transfer. Never used outside this module.
|
39 |
This class is for only data transfer. Never used outside this module.
|
| 40 |
'''
|
40 |
'''
|
| 41 |
class _DeliveryEstimateObject:
|
41 |
class _DeliveryEstimateObject:
|
| 42 |
def __init__(self, delivery_time, reliability, provider_id, codAllowed):
|
42 |
def __init__(self, delivery_time, reliability, provider_id, codAllowed, otgAvailable):
|
| 43 |
self.delivery_time = delivery_time
|
43 |
self.delivery_time = delivery_time
|
| 44 |
self.reliability = reliability
|
44 |
self.reliability = reliability
|
| 45 |
self.provider_id = provider_id
|
45 |
self.provider_id = provider_id
|
| 46 |
self.codAllowed = codAllowed
|
46 |
self.codAllowed = codAllowed
|
| - |
|
47 |
self.otgAvailable = otgAvailable
|
| 47 |
|
48 |
|
| 48 |
def initialize(dbname="logistics", db_hostname="localhost"):
|
49 |
def initialize(dbname="logistics", db_hostname="localhost"):
|
| 49 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
50 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 50 |
DataService.initialize(dbname, db_hostname)
|
51 |
DataService.initialize(dbname, db_hostname)
|
| 51 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
52 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
| Line 67... |
Line 68... |
| 67 |
try:
|
68 |
try:
|
| 68 |
provider_pincodes = serviceable_location_cache[serviceable_location.provider_id]
|
69 |
provider_pincodes = serviceable_location_cache[serviceable_location.provider_id]
|
| 69 |
except:
|
70 |
except:
|
| 70 |
provider_pincodes = {}
|
71 |
provider_pincodes = {}
|
| 71 |
serviceable_location_cache[serviceable_location.provider_id] = provider_pincodes
|
72 |
serviceable_location_cache[serviceable_location.provider_id] = provider_pincodes
|
| 72 |
provider_pincodes[serviceable_location.dest_pincode] = serviceable_location.dest_code, serviceable_location.exp, serviceable_location.cod, serviceable_location.station_type
|
73 |
provider_pincodes[serviceable_location.dest_pincode] = serviceable_location.dest_code, serviceable_location.exp, serviceable_location.cod, serviceable_location.otgAvailable
|
| 73 |
|
74 |
|
| 74 |
def __cache_warehouse_allocation_table():
|
75 |
def __cache_warehouse_allocation_table():
|
| 75 |
warehouse_allocations = WarehouseAllocation.query.all()
|
76 |
warehouse_allocations = WarehouseAllocation.query.all()
|
| 76 |
for warehouse_allocation in warehouse_allocations:
|
77 |
for warehouse_allocation in warehouse_allocations:
|
| 77 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
78 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
| Line 82... |
Line 83... |
| 82 |
|
83 |
|
| 83 |
def get_providers():
|
84 |
def get_providers():
|
| 84 |
providers = Provider.query.filter_by(isActive = 1).all()
|
85 |
providers = Provider.query.filter_by(isActive = 1).all()
|
| 85 |
return providers
|
86 |
return providers
|
| 86 |
|
87 |
|
| 87 |
def get_logistics_estimation(destination_pin, item_selling_price, type=DeliveryType.PREPAID):
|
88 |
def get_logistics_estimation(destination_pin, item_selling_price):
|
| 88 |
logging.info("Getting logistics estimation for pincode:" + destination_pin )
|
89 |
logging.info("Getting logistics estimation for pincode:" + destination_pin )
|
| 89 |
|
90 |
|
| 90 |
provider_id, codAllowed = __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price)
|
91 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price)
|
| 91 |
|
92 |
|
| 92 |
if not provider_id:
|
93 |
if not provider_id:
|
| 93 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
94 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
| 94 |
try:
|
95 |
try:
|
| 95 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id][0]
|
96 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id][0]
|
| 96 |
reliability = delivery_estimate_cache[destination_pin, provider_id][1]
|
97 |
reliability = delivery_estimate_cache[destination_pin, provider_id][1]
|
| 97 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, reliability, provider_id, codAllowed)
|
98 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, reliability, provider_id, codAllowed, otgAvailable)
|
| 98 |
return delivery_estimate
|
99 |
return delivery_estimate
|
| 99 |
except Exception as ex:
|
100 |
except Exception as ex:
|
| 100 |
print ex
|
101 |
print ex
|
| 101 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
102 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
| 102 |
|
103 |
|
| 103 |
def __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price):
|
104 |
def __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price):
|
| 104 |
if ncr_pincodes.__contains__(destination_pin) and item_selling_price <= 20000:
|
105 |
if ncr_pincodes.__contains__(destination_pin) and item_selling_price <= 20000:
|
| - |
|
106 |
dest_code, exp, iscod, otgAvailable = serviceable_location_cache.get(3).get(destination_pin)
|
| - |
|
107 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| 105 |
return 3, True
|
108 |
return 3, True, otgAvailable
|
| 106 |
|
109 |
|
| 107 |
if serviceable_location_cache.get(3).has_key(destination_pin):
|
110 |
if serviceable_location_cache.get(3).has_key(destination_pin):
|
| 108 |
dest_code, exp, iscod, station_type = serviceable_location_cache.get(3).get(destination_pin)
|
111 |
dest_code, exp, iscod, otgAvailable = serviceable_location_cache.get(3).get(destination_pin)
|
| 109 |
iscod = iscod and item_selling_price <= 9600
|
112 |
iscod = iscod and item_selling_price <= 9600
|
| - |
|
113 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| 110 |
return 3, iscod
|
114 |
return 3, iscod, otgAvailable
|
| 111 |
|
115 |
|
| 112 |
if serviceable_location_cache.get(1).has_key(destination_pin):
|
116 |
if serviceable_location_cache.get(1).has_key(destination_pin):
|
| 113 |
dest_code, exp, iscod, station_type = serviceable_location_cache.get(1).get(destination_pin)
|
117 |
dest_code, exp, iscod, otgAvailable = serviceable_location_cache.get(1).get(destination_pin)
|
| 114 |
iscod = iscod and item_selling_price <= 9600
|
118 |
iscod = iscod and item_selling_price <= 9600
|
| - |
|
119 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| 115 |
return 1, iscod
|
120 |
return 1, iscod, otgAvailable
|
| 116 |
else:
|
121 |
else:
|
| 117 |
return None, False
|
122 |
return None, False
|
| 118 |
|
123 |
|
| 119 |
def get_destination_code(providerId, pinCode):
|
124 |
def get_destination_code(providerId, pinCode):
|
| 120 |
serviceableLocationDetail = ServiceableLocationDetails.query.filter_by(provider_id = providerId, dest_pincode = pinCode).one()
|
125 |
serviceableLocationDetail = ServiceableLocationDetails.query.filter_by(provider_id = providerId, dest_pincode = pinCode).one()
|
| Line 199... |
Line 204... |
| 199 |
return PickupStore.query.filter_by(id = storeId).one()
|
204 |
return PickupStore.query.filter_by(id = storeId).one()
|
| 200 |
|
205 |
|
| 201 |
def get_pickup_store_by_hotspot_id(hotspotId):
|
206 |
def get_pickup_store_by_hotspot_id(hotspotId):
|
| 202 |
return PickupStore.query.filter_by(hotspotId = hotspotId).one()
|
207 |
return PickupStore.query.filter_by(hotspotId = hotspotId).one()
|
| 203 |
|
208 |
|
| 204 |
def add_pincode(provider, pincode, destCode, exp, cod, stationType):
|
209 |
def add_pincode(provider, pincode, destCode, exp, cod, stationType, otgAvailable):
|
| 205 |
provider = Provider().query.filter_by(id = provider).one()
|
210 |
provider = Provider().query.filter_by(id = provider).one()
|
| 206 |
serviceableLocationDetails = ServiceableLocationDetails()
|
211 |
serviceableLocationDetails = ServiceableLocationDetails()
|
| 207 |
serviceableLocationDetails.provider = provider
|
212 |
serviceableLocationDetails.provider = provider
|
| 208 |
serviceableLocationDetails.dest_pincode = pincode
|
213 |
serviceableLocationDetails.dest_pincode = pincode
|
| 209 |
serviceableLocationDetails.dest_code = destCode
|
214 |
serviceableLocationDetails.dest_code = destCode
|
| 210 |
serviceableLocationDetails.exp = exp
|
215 |
serviceableLocationDetails.exp = exp
|
| 211 |
serviceableLocationDetails.cod = cod
|
216 |
serviceableLocationDetails.cod = cod
|
| 212 |
serviceableLocationDetails.station_type = stationType
|
217 |
serviceableLocationDetails.station_type = stationType
|
| - |
|
218 |
serviceableLocationDetails.otgAvailable = otgAvailable
|
| 213 |
session.commit()
|
219 |
session.commit()
|
| 214 |
|
220 |
|
| 215 |
def update_pincode(providerId, pincode, exp, cod):
|
221 |
def update_pincode(providerId, pincode, exp, cod, otgAvailable):
|
| 216 |
serviceableLocationDetails = ServiceableLocationDetails().get_by(provider_id = providerId, dest_pincode = pincode).one()
|
222 |
serviceableLocationDetails = ServiceableLocationDetails().get_by(provider_id = providerId, dest_pincode = pincode).one()
|
| 217 |
serviceableLocationDetails.exp = exp
|
223 |
serviceableLocationDetails.exp = exp
|
| 218 |
serviceableLocationDetails.cod = cod
|
224 |
serviceableLocationDetails.cod = cod
|
| - |
|
225 |
serviceableLocationDetails.otgAvailable = otgAvailable
|
| 219 |
session.commit()
|
226 |
session.commit()
|
| 220 |
|
227 |
|