| Line 110... |
Line 110... |
| 110 |
try:
|
110 |
try:
|
| 111 |
client = InventoryClient().get_client()
|
111 |
client = InventoryClient().get_client()
|
| 112 |
item = client.getItem(itemId)
|
112 |
item = client.getItem(itemId)
|
| 113 |
except Exception as ex:
|
113 |
except Exception as ex:
|
| 114 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
114 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
| - |
|
115 |
|
| 115 |
delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice)
|
116 |
delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice)
|
| 116 |
if delivery_estimate is None:
|
117 |
if delivery_estimate is None:
|
| 117 |
raise LogisticsServiceException(103, "Unable to fetch delivery estimate for this pincode.")
|
118 |
raise LogisticsServiceException(104, "Unable to fetch delivery estimate for this pincode.")
|
| 118 |
delivery_time = 24*delivery_estimate.delivery_time
|
- |
|
| 119 |
if self.cutoff_time <= datetime.datetime.now().hour:
|
- |
|
| 120 |
delivery_time = delivery_time + 24
|
119 |
|
| 121 |
warehouse_loc = delivery_estimate.warehouse_location
|
120 |
warehouse_loc = delivery_estimate.warehouse_location
|
| 122 |
try:
|
121 |
try:
|
| - |
|
122 |
#Get the id and location of actual warehouse that'll be used to fulfill this order.
|
| 123 |
warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
|
123 |
warehouse_loc, warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
|
| 124 |
except Exception as ex:
|
124 |
except Exception as ex:
|
| 125 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
125 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
| - |
|
126 |
|
| - |
|
127 |
# We are revising the estimated based on the actual warehouse that will be assigned to this order.
|
| - |
|
128 |
# This warehouse may be located in a different zone that the one we allocated for this pincode.
|
| - |
|
129 |
delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice, warehouse_loc)
|
| - |
|
130 |
if delivery_estimate is None:
|
| - |
|
131 |
raise LogisticsServiceException(105, "Unable to fetch delivery estimate for pincode: " + destination_pin + " and revised location: " + str(warehouse_loc))
|
| - |
|
132 |
|
| - |
|
133 |
delivery_time = 24*delivery_estimate.delivery_time
|
| - |
|
134 |
|
| - |
|
135 |
# Increase the estimate if the actual stock is less than the threshold
|
| 126 |
if items_in_inventory < self.stock_threshold :
|
136 |
if items_in_inventory < self.stock_threshold :
|
| 127 |
delivery_time = delivery_time + self.time_to_producre
|
137 |
delivery_time = delivery_time + self.time_to_producre
|
| 128 |
|
138 |
|
| - |
|
139 |
#Further increase the estimate if it's late in the day
|
| - |
|
140 |
if self.cutoff_time <= datetime.datetime.now().hour:
|
| - |
|
141 |
delivery_time = delivery_time + 24
|
| - |
|
142 |
|
| - |
|
143 |
#FIXME: Ugly hack to increase the estimate of Samsung Galaxy S II. Remove this.
|
| 129 |
if itemId == 1502:
|
144 |
if itemId == 1502:
|
| 130 |
delivery_time = delivery_time + 48
|
145 |
delivery_time = delivery_time + 48
|
| 131 |
|
146 |
|
| 132 |
delivery_time = int(math.ceil(delivery_time/24.0))
|
147 |
delivery_time = int(math.ceil(delivery_time/24.0))
|
| 133 |
|
148 |
|