| Line 45... |
Line 45... |
| 45 |
print "Done cache population at: " + str(datetime.datetime.now())
|
45 |
print "Done cache population at: " + str(datetime.datetime.now())
|
| 46 |
|
46 |
|
| 47 |
def __cache_delivery_estimate_table():
|
47 |
def __cache_delivery_estimate_table():
|
| 48 |
delivery_estimates = DeliveryEstimate.query.all()
|
48 |
delivery_estimates = DeliveryEstimate.query.all()
|
| 49 |
for delivery_estimate in delivery_estimates:
|
49 |
for delivery_estimate in delivery_estimates:
|
| 50 |
delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id]\
|
50 |
delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
|
| 51 |
=delivery_estimate.delivery_time, delivery_estimate.delivery_delay
|
51 |
=delivery_estimate.delivery_time, delivery_estimate.delivery_delay
|
| 52 |
|
52 |
|
| 53 |
def __cache_serviceable_location_details_table():
|
53 |
def __cache_serviceable_location_details_table():
|
| 54 |
serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
|
54 |
serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
|
| 55 |
for serviceable_location in serviceable_locations:
|
55 |
for serviceable_location in serviceable_locations:
|
| Line 75... |
Line 75... |
| 75 |
|
75 |
|
| 76 |
def get_logistics_estimation(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
76 |
def get_logistics_estimation(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
| 77 |
logging.info("Getting logistics estimation for pincode:" + destination_pin )
|
77 |
logging.info("Getting logistics estimation for pincode:" + destination_pin )
|
| 78 |
|
78 |
|
| 79 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
|
79 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
|
| - |
|
80 |
warehouse_location = 0
|
| - |
|
81 |
if billingWarehouseId in [12,13]:
|
| - |
|
82 |
warehouse_location = 1
|
| 80 |
|
83 |
|
| 81 |
if not provider_id:
|
84 |
if not provider_id:
|
| 82 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
85 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
| 83 |
try:
|
86 |
try:
|
| 84 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id][0]
|
87 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
|
| 85 |
delivery_delay = delivery_estimate_cache[destination_pin, provider_id][1]
|
88 |
delivery_delay = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
|
| 86 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
|
89 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
|
| 87 |
return delivery_estimate
|
90 |
return delivery_estimate
|
| 88 |
except Exception as ex:
|
91 |
except Exception as ex:
|
| 89 |
print ex
|
92 |
print ex
|
| 90 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
93 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
| 91 |
|
94 |
|
| 92 |
def __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
95 |
def __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
| 93 |
if billingWarehouseId != 12 and serviceable_location_cache.get(6).has_key(destination_pin):
|
96 |
if billingWarehouseId not in [12,13] and serviceable_location_cache.get(6).has_key(destination_pin):
|
| 94 |
if weight < 480 and serviceable_location_cache.get(3).has_key(destination_pin) and (type == DeliveryType.PREPAID or item_selling_price < 3000):
|
97 |
if weight < 480 and serviceable_location_cache.get(3).has_key(destination_pin) and (type == DeliveryType.PREPAID or item_selling_price < 3000):
|
| 95 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(3).get(destination_pin)
|
98 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(3).get(destination_pin)
|
| 96 |
if item_selling_price <= providerPrepaidLimit:
|
99 |
if item_selling_price <= providerPrepaidLimit:
|
| 97 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
100 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
| 98 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
101 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| Line 287... |
Line 290... |
| 287 |
sp = client.getStorePricing(itemId)
|
290 |
sp = client.getStorePricing(itemId)
|
| 288 |
|
291 |
|
| 289 |
if codAllowed:
|
292 |
if codAllowed:
|
| 290 |
return sp.minAdvancePrice, True
|
293 |
return sp.minAdvancePrice, True
|
| 291 |
else:
|
294 |
else:
|
| 292 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(providerId).get(destination_pin)
|
295 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit = serviceable_location_cache.get(providerId).get(destination_pin)
|
| 293 |
if iscod:
|
296 |
if iscod:
|
| 294 |
if providerId == 6:
|
297 |
if providerId == 6:
|
| 295 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
298 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
| 296 |
if providerId == 3:
|
299 |
if providerId == 3:
|
| 297 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
300 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|