| Line 141... |
Line 141... |
| 141 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
141 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
| 142 |
warehouse_loc, warehouse_id, items_in_inventory, expected_delay = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
|
142 |
warehouse_loc, warehouse_id, items_in_inventory, expected_delay = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
|
| 143 |
except Exception as ex:
|
143 |
except Exception as ex:
|
| 144 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
144 |
raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
|
| 145 |
|
145 |
|
| 146 |
# We are revising the estimated based on the actual warehouse that will be assigned to this order.
|
146 |
# We are revising the estimates based on the actual warehouse that this order will be assigned to.
|
| 147 |
# This warehouse may be located in a different zone that the one we allocated for this pincode.
|
147 |
# This warehouse may be located in a zone which is different from the one we allocated for this pincode.
|
| 148 |
delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice, warehouse_loc, type)
|
148 |
delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice, warehouse_loc, type)
|
| 149 |
if delivery_estimate is None:
|
149 |
if delivery_estimate is None:
|
| 150 |
raise LogisticsServiceException(105, "Unable to fetch delivery estimate for pincode: " + destination_pin + " and revised location: " + str(warehouse_loc))
|
150 |
raise LogisticsServiceException(105, "Unable to fetch delivery estimate for pincode: " + destination_pin + " and revised location: " + str(warehouse_loc))
|
| 151 |
|
151 |
|
| 152 |
delivery_time = 24*delivery_estimate.delivery_time
|
152 |
delivery_time = 24 * delivery_estimate.delivery_time
|
| 153 |
|
153 |
|
| - |
|
154 |
'''
|
| - |
|
155 |
We're now calculating the expected shipping delay which is independent of
|
| - |
|
156 |
the courier agency and is completely within our control (well, almost).
|
| - |
|
157 |
'''
|
| 154 |
#Always add the expected delay
|
158 |
#Always add the expected delay
|
| 155 |
delivery_time = delivery_time + 24*expected_delay
|
159 |
shipping_delay = 24 * expected_delay
|
| 156 |
|
160 |
|
| 157 |
# Increase the estimate if the actual stock is less than the threshold
|
161 |
# Increase the estimate if the actual stock is less than the threshold
|
| 158 |
if items_in_inventory < self.stock_threshold :
|
162 |
if items_in_inventory < self.stock_threshold :
|
| 159 |
delivery_time = delivery_time + self.time_to_procure
|
163 |
shipping_delay = shipping_delay + self.time_to_procure
|
| 160 |
|
164 |
|
| 161 |
#Further increase the estimate if it's late in the day
|
165 |
#Further increase the estimate if it's late in the day
|
| 162 |
current_hour = datetime.datetime.now().hour
|
166 |
current_hour = datetime.datetime.now().hour
|
| 163 |
if type == DeliveryType.PREPAID and self.cutoff_time <= current_hour:
|
167 |
if type == DeliveryType.PREPAID and self.cutoff_time <= current_hour:
|
| 164 |
delivery_time = delivery_time + 24
|
168 |
shipping_delay = shipping_delay + 24
|
| 165 |
elif type == DeliveryType.COD and self.cod_cutoff_time <= current_hour:
|
169 |
elif type == DeliveryType.COD and self.cod_cutoff_time <= current_hour:
|
| 166 |
delivery_time = delivery_time + 24
|
170 |
shipping_delay = shipping_delay + 24
|
| - |
|
171 |
|
| - |
|
172 |
shipping_delay = int(math.ceil(shipping_delay/24.0))
|
| 167 |
|
173 |
|
| 168 |
delivery_time = int(math.ceil(delivery_time/24.0))
|
174 |
delivery_time = delivery_time + shipping_delay
|
| 169 |
|
175 |
|
| 170 |
'''
|
176 |
'''
|
| - |
|
177 |
Delays such as the following are delivery delays and are to only affect the
|
| - |
|
178 |
delivery time and not the shipping time.
|
| - |
|
179 |
'''
|
| - |
|
180 |
'''
|
| - |
|
181 |
##
|
| 171 |
## FIXME Due to Kanwaar on the delhi Dehradun route deliveries on following pin codes will be effected.
|
182 |
## FIXME Due to Kanwaar on the Delhi-Dehradun route, deliveries to the following
|
| - |
|
183 |
pin codes will be affected:
|
| 172 |
## Changing as per ticket number #462
|
184 |
## Changing as per ticket number #462
|
| 173 |
if destination_pin in self.kanwaar_effected_pins_by_two_days:
|
185 |
if destination_pin in self.kanwaar_effected_pins_by_two_days:
|
| 174 |
delivery_time += 2
|
186 |
delivery_time += 2
|
| 175 |
elif destination_pin in self.kanwaar_effected_pins_by_one_day:
|
187 |
elif destination_pin in self.kanwaar_effected_pins_by_one_day:
|
| 176 |
delivery_time += 1
|
188 |
delivery_time += 1
|
| Line 179... |
Line 191... |
| 179 |
|
191 |
|
| 180 |
logistics_info = LogisticsInfo()
|
192 |
logistics_info = LogisticsInfo()
|
| 181 |
logistics_info.deliveryTime = delivery_time
|
193 |
logistics_info.deliveryTime = delivery_time
|
| 182 |
logistics_info.providerId = delivery_estimate.provider_id
|
194 |
logistics_info.providerId = delivery_estimate.provider_id
|
| 183 |
logistics_info.warehouseId = warehouse_id
|
195 |
logistics_info.warehouseId = warehouse_id
|
| - |
|
196 |
logistics_info.shippingTime = shipping_delay
|
| 184 |
|
197 |
|
| 185 |
return logistics_info
|
198 |
return logistics_info
|
| 186 |
|
199 |
|
| 187 |
def getDestinationCode(self, providerId, pinCode):
|
200 |
def getDestinationCode(self, providerId, pinCode):
|
| 188 |
"""
|
201 |
"""
|