| 442 |
rajveer |
1 |
'''
|
|
|
2 |
Created on 13-Sep-2010
|
|
|
3 |
|
|
|
4 |
@author: rajveer
|
|
|
5 |
'''
|
|
|
6 |
|
| 16025 |
amit.gupta |
7 |
from elixir import session
|
|
|
8 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
9 |
from shop2020.clients.InventoryClient import InventoryClient
|
| 442 |
rajveer |
10 |
from shop2020.logistics.service.impl import DataService
|
| 644 |
chandransh |
11 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
| 16025 |
amit.gupta |
12 |
DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
|
|
|
13 |
ServiceableLocationDetails, PickupStore
|
|
|
14 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
| 7786 |
manish.sha |
15 |
DeliveryType, LogisticsLocationInfo
|
| 16025 |
amit.gupta |
16 |
from shop2020.thriftpy.model.v1.inventory.ttypes import Warehouse, BillingType,\
|
|
|
17 |
WarehouseType
|
| 442 |
rajveer |
18 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
| 5964 |
amar.kumar |
19 |
from sqlalchemy.sql import or_
|
| 16025 |
amit.gupta |
20 |
import datetime
|
| 3355 |
chandransh |
21 |
import logging
|
| 13146 |
manish.sha |
22 |
import os
|
| 16025 |
amit.gupta |
23 |
import sys
|
|
|
24 |
import time
|
| 3355 |
chandransh |
25 |
logging.basicConfig(level=logging.DEBUG)
|
| 442 |
rajveer |
26 |
|
| 3217 |
rajveer |
27 |
warehouse_allocation_cache = {}
|
|
|
28 |
serviceable_location_cache = {}
|
|
|
29 |
delivery_estimate_cache = {}
|
| 16025 |
amit.gupta |
30 |
warehouse_location_cache = {}
|
| 6370 |
rajveer |
31 |
|
| 3218 |
rajveer |
32 |
'''
|
|
|
33 |
This class is for only data transfer. Never used outside this module.
|
|
|
34 |
'''
|
|
|
35 |
class _DeliveryEstimateObject:
|
| 6537 |
rajveer |
36 |
def __init__(self, delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable):
|
| 3218 |
rajveer |
37 |
self.delivery_time = delivery_time
|
| 6537 |
rajveer |
38 |
self.delivery_delay = delivery_delay
|
| 3218 |
rajveer |
39 |
self.provider_id = provider_id
|
| 4866 |
rajveer |
40 |
self.codAllowed = codAllowed
|
| 6524 |
rajveer |
41 |
self.otgAvailable = otgAvailable
|
| 3218 |
rajveer |
42 |
|
| 3187 |
rajveer |
43 |
def initialize(dbname="logistics", db_hostname="localhost"):
|
| 442 |
rajveer |
44 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 3187 |
rajveer |
45 |
DataService.initialize(dbname, db_hostname)
|
| 3218 |
rajveer |
46 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
| 16025 |
amit.gupta |
47 |
#__cache_warehouse_allocation_table()
|
|
|
48 |
__cache_warehouse_locations()
|
| 3217 |
rajveer |
49 |
__cache_serviceable_location_details_table()
|
|
|
50 |
__cache_delivery_estimate_table()
|
|
|
51 |
close_session()
|
| 3218 |
rajveer |
52 |
print "Done cache population at: " + str(datetime.datetime.now())
|
| 442 |
rajveer |
53 |
|
| 3217 |
rajveer |
54 |
def __cache_delivery_estimate_table():
|
|
|
55 |
delivery_estimates = DeliveryEstimate.query.all()
|
|
|
56 |
for delivery_estimate in delivery_estimates:
|
| 7857 |
rajveer |
57 |
delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
|
| 6537 |
rajveer |
58 |
=delivery_estimate.delivery_time, delivery_estimate.delivery_delay
|
| 3217 |
rajveer |
59 |
|
|
|
60 |
def __cache_serviceable_location_details_table():
|
| 5964 |
amar.kumar |
61 |
serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
|
| 3217 |
rajveer |
62 |
for serviceable_location in serviceable_locations:
|
|
|
63 |
try:
|
|
|
64 |
provider_pincodes = serviceable_location_cache[serviceable_location.provider_id]
|
|
|
65 |
except:
|
|
|
66 |
provider_pincodes = {}
|
|
|
67 |
serviceable_location_cache[serviceable_location.provider_id] = provider_pincodes
|
| 7627 |
rajveer |
68 |
provider_pincodes[serviceable_location.dest_pincode] = serviceable_location.dest_code, serviceable_location.exp, serviceable_location.cod, serviceable_location.otgAvailable, serviceable_location.websiteCodLimit, serviceable_location.storeCodLimit, serviceable_location.providerPrepaidLimit
|
| 3217 |
rajveer |
69 |
|
|
|
70 |
def __cache_warehouse_allocation_table():
|
|
|
71 |
warehouse_allocations = WarehouseAllocation.query.all()
|
|
|
72 |
for warehouse_allocation in warehouse_allocations:
|
|
|
73 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
|
|
74 |
|
| 16025 |
amit.gupta |
75 |
def __cache_warehouse_locations():
|
|
|
76 |
client = InventoryClient().get_client()
|
|
|
77 |
client.getAllWarehouses(True)
|
|
|
78 |
#for WarehouseAllocation.query.all()
|
|
|
79 |
warehouse = Warehouse()
|
|
|
80 |
for warehouse in client.getAllWarehouses(True):
|
|
|
81 |
warehouse_location_cache[warehouse.billingWarehouseId]=warehouse.logisticsLocation
|
|
|
82 |
|
| 644 |
chandransh |
83 |
def get_provider(provider_id):
|
| 766 |
rajveer |
84 |
provider = Provider.get_by(id=provider_id)
|
|
|
85 |
return provider
|
| 644 |
chandransh |
86 |
|
|
|
87 |
def get_providers():
|
| 5387 |
rajveer |
88 |
providers = Provider.query.filter_by(isActive = 1).all()
|
| 766 |
rajveer |
89 |
return providers
|
| 644 |
chandransh |
90 |
|
| 7608 |
rajveer |
91 |
def get_logistics_estimation(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
| 5692 |
rajveer |
92 |
logging.info("Getting logistics estimation for pincode:" + destination_pin )
|
| 1504 |
ankur.sing |
93 |
|
| 7608 |
rajveer |
94 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
|
| 9964 |
anupam.sin |
95 |
|
|
|
96 |
if item_selling_price > 60000 or item_selling_price <= 250:
|
|
|
97 |
codAllowed = False
|
|
|
98 |
|
| 16025 |
amit.gupta |
99 |
warehouse_location = warehouse_location_cache.get(billingWarehouseId)
|
|
|
100 |
if warehouse_location is None:
|
|
|
101 |
warehouse_location = 0
|
| 7857 |
rajveer |
102 |
|
| 3217 |
rajveer |
103 |
if not provider_id:
|
| 5692 |
rajveer |
104 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
| 644 |
chandransh |
105 |
try:
|
| 16025 |
amit.gupta |
106 |
logging.info( "destination_pin %s, provider_id %s, warehouse_location %s"%(destination_pin, provider_id, warehouse_location))
|
|
|
107 |
logging.info( "Estimates %s, %s"%(delivery_estimate_cache[destination_pin, provider_id, warehouse_location]))
|
| 7857 |
rajveer |
108 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
|
|
|
109 |
delivery_delay = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
|
| 6537 |
rajveer |
110 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
|
| 3218 |
rajveer |
111 |
return delivery_estimate
|
| 1504 |
ankur.sing |
112 |
except Exception as ex:
|
|
|
113 |
print ex
|
| 644 |
chandransh |
114 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
| 3150 |
rajveer |
115 |
|
| 7608 |
rajveer |
116 |
def __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId):
|
| 13357 |
manish.sha |
117 |
'''
|
|
|
118 |
if serviceable_location_cache.get(6).has_key(destination_pin):
|
|
|
119 |
if weight < 480 and serviceable_location_cache.get(3).has_key(destination_pin) and type == DeliveryType.PREPAID:
|
|
|
120 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(3).get(destination_pin)
|
|
|
121 |
if item_selling_price <= providerPrepaidLimit:
|
|
|
122 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
123 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
|
|
124 |
return 3, iscod, otgAvailable
|
|
|
125 |
else:
|
|
|
126 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(6).get(destination_pin)
|
|
|
127 |
if item_selling_price <= providerPrepaidLimit:
|
|
|
128 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
129 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
|
|
130 |
return 6, iscod, otgAvailable
|
|
|
131 |
'''
|
| 7981 |
rajveer |
132 |
if serviceable_location_cache.get(3).has_key(destination_pin):
|
|
|
133 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(3).get(destination_pin)
|
| 7627 |
rajveer |
134 |
if item_selling_price <= providerPrepaidLimit:
|
| 7608 |
rajveer |
135 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
136 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| 7981 |
rajveer |
137 |
return 3, iscod, otgAvailable
|
| 8575 |
rajveer |
138 |
|
|
|
139 |
if billingWarehouseId not in [12,13] and serviceable_location_cache.get(7).has_key(destination_pin):
|
|
|
140 |
if item_selling_price < 3000 and serviceable_location_cache.get(1).has_key(destination_pin):
|
|
|
141 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(1).get(destination_pin)
|
|
|
142 |
if item_selling_price <= providerPrepaidLimit:
|
|
|
143 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
144 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
|
|
145 |
return 1, iscod, otgAvailable
|
|
|
146 |
else:
|
|
|
147 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(7).get(destination_pin)
|
|
|
148 |
if item_selling_price <= providerPrepaidLimit:
|
|
|
149 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
150 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
|
|
151 |
return 7, iscod, otgAvailable
|
|
|
152 |
|
| 7627 |
rajveer |
153 |
if serviceable_location_cache.get(1).has_key(destination_pin):
|
|
|
154 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(1).get(destination_pin)
|
|
|
155 |
if item_selling_price <= providerPrepaidLimit:
|
| 7608 |
rajveer |
156 |
iscod = iscod and item_selling_price <= websiteCodLimit
|
|
|
157 |
otgAvailable = otgAvailable and item_selling_price >= 2000
|
| 7627 |
rajveer |
158 |
return 1, iscod, otgAvailable
|
| 7981 |
rajveer |
159 |
|
| 10185 |
amit.gupta |
160 |
return None, False, False
|
| 5278 |
rajveer |
161 |
|
| 6017 |
amar.kumar |
162 |
def get_destination_code(providerId, pinCode):
|
|
|
163 |
serviceableLocationDetail = ServiceableLocationDetails.query.filter_by(provider_id = providerId, dest_pincode = pinCode).one()
|
|
|
164 |
return serviceableLocationDetail.dest_code
|
|
|
165 |
|
| 644 |
chandransh |
166 |
def add_empty_AWBs(numbers, provider_id, type):
|
| 442 |
rajveer |
167 |
for number in numbers:
|
| 644 |
chandransh |
168 |
query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
|
| 444 |
rajveer |
169 |
try:
|
|
|
170 |
query.one()
|
|
|
171 |
except:
|
| 644 |
chandransh |
172 |
awb = Awb()
|
| 444 |
rajveer |
173 |
awb.awb_number = number
|
| 644 |
chandransh |
174 |
awb.provider_id = provider_id
|
| 444 |
rajveer |
175 |
awb.is_available = True
|
| 644 |
chandransh |
176 |
awb.type = type
|
|
|
177 |
session.commit()
|
| 442 |
rajveer |
178 |
|
| 444 |
rajveer |
179 |
def set_AWB_as_used(awb_number):
|
| 644 |
chandransh |
180 |
query = Awb.query.filter_by(awb_number = awb_number)
|
| 444 |
rajveer |
181 |
awb = query.one()
|
|
|
182 |
awb.is_available=False
|
|
|
183 |
session.commit()
|
|
|
184 |
|
| 3044 |
chandransh |
185 |
def get_empty_AWB(provider_id, type = DeliveryType.PREPAID):
|
| 2342 |
chandransh |
186 |
query = Awb.query.with_lockmode("update").filter_by(provider_id = provider_id, is_available = True) #check the provider thing
|
| 3044 |
chandransh |
187 |
if type == DeliveryType.PREPAID:
|
|
|
188 |
query = query.filter_by(type="Prepaid")
|
|
|
189 |
if type == DeliveryType.COD:
|
|
|
190 |
query = query.filter_by(type="COD")
|
|
|
191 |
|
| 13158 |
manish.sha |
192 |
additionalQuery = query
|
|
|
193 |
query = query.filter_by(awbUsedFor=0)
|
|
|
194 |
|
| 442 |
rajveer |
195 |
try:
|
| 644 |
chandransh |
196 |
awb = query.first()
|
| 13158 |
manish.sha |
197 |
if awb is None:
|
|
|
198 |
additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
|
|
|
199 |
awb = additionalQuery.first()
|
| 644 |
chandransh |
200 |
awb.is_available = False
|
|
|
201 |
session.commit()
|
| 444 |
rajveer |
202 |
return awb.awb_number
|
| 442 |
rajveer |
203 |
except:
|
| 644 |
chandransh |
204 |
raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
|
| 1137 |
chandransh |
205 |
|
| 3103 |
chandransh |
206 |
def get_free_awb_count(provider_id, type):
|
|
|
207 |
count = Awb.query.filter_by(provider_id = provider_id, is_available = True, type=type).count()
|
| 1137 |
chandransh |
208 |
if count == None:
|
|
|
209 |
count = 0
|
|
|
210 |
return count
|
| 442 |
rajveer |
211 |
|
| 644 |
chandransh |
212 |
def get_shipment_info(awb_number, provider_id):
|
|
|
213 |
awb = Awb.get_by(awb_number = awb_number, provider_id = provider_id)
|
|
|
214 |
query = AwbUpdate.query.filter_by(awb = awb)
|
| 766 |
rajveer |
215 |
info = query.all()
|
|
|
216 |
return info
|
|
|
217 |
|
| 6643 |
rajveer |
218 |
def store_shipment_info(update):
|
|
|
219 |
updates = AwbUpdate.query.filter_by(providerId = update.providerId, awbNumber = update.awbNumber, location = update.location, date = to_py_date(update.date), status = update.status, description = update.description).all()
|
|
|
220 |
if not updates:
|
|
|
221 |
dupdate = AwbUpdate()
|
|
|
222 |
dupdate.providerId = update.providerId
|
|
|
223 |
dupdate.awbNumber = update.awbNumber
|
|
|
224 |
dupdate.location = update.location
|
|
|
225 |
dupdate.date = to_py_date(update.date)
|
|
|
226 |
dupdate.status = update.status
|
|
|
227 |
dupdate.description = update.description
|
|
|
228 |
session.commit()
|
|
|
229 |
|
| 1730 |
ankur.sing |
230 |
def get_holidays(start_date, end_date):
|
|
|
231 |
query = PublicHolidays.query
|
|
|
232 |
if start_date != -1:
|
|
|
233 |
query = query.filter(PublicHolidays.date >= to_py_date(start_date))
|
|
|
234 |
if end_date != -1:
|
|
|
235 |
query = query.filter(PublicHolidays.date <= to_py_date(end_date))
|
|
|
236 |
holidays = query.all()
|
|
|
237 |
holiday_dates = [to_java_date(datetime.datetime(*time.strptime(str(holiday.date), '%Y-%m-%d')[:3])) for holiday in holidays]
|
|
|
238 |
return holiday_dates
|
|
|
239 |
|
| 5527 |
anupam.sin |
240 |
def get_provider_for_pickup_type(pickUp):
|
|
|
241 |
return Provider.query.filter(Provider.pickup == pickUp).first().id
|
|
|
242 |
|
| 766 |
rajveer |
243 |
def close_session():
|
|
|
244 |
if session.is_active:
|
|
|
245 |
print "session is active. closing it."
|
| 2823 |
chandransh |
246 |
session.close()
|
| 3376 |
rajveer |
247 |
|
|
|
248 |
def is_alive():
|
|
|
249 |
try:
|
|
|
250 |
session.query(Awb.id).limit(1).one()
|
|
|
251 |
return True
|
|
|
252 |
except:
|
| 5555 |
rajveer |
253 |
return False
|
|
|
254 |
|
|
|
255 |
def get_all_pickup_stores():
|
| 5572 |
anupam.sin |
256 |
pickupStores = PickupStore.query.all()
|
|
|
257 |
return pickupStores
|
| 5555 |
rajveer |
258 |
|
|
|
259 |
def get_pickup_store(storeId):
|
| 5719 |
rajveer |
260 |
return PickupStore.query.filter_by(id = storeId).one()
|
|
|
261 |
|
|
|
262 |
def get_pickup_store_by_hotspot_id(hotspotId):
|
|
|
263 |
return PickupStore.query.filter_by(hotspotId = hotspotId).one()
|
| 6322 |
amar.kumar |
264 |
|
| 6524 |
rajveer |
265 |
def add_pincode(provider, pincode, destCode, exp, cod, stationType, otgAvailable):
|
| 7914 |
rajveer |
266 |
provider = Provider.query.filter_by(id = provider).one()
|
| 6322 |
amar.kumar |
267 |
serviceableLocationDetails = ServiceableLocationDetails()
|
|
|
268 |
serviceableLocationDetails.provider = provider
|
|
|
269 |
serviceableLocationDetails.dest_pincode = pincode
|
|
|
270 |
serviceableLocationDetails.dest_code = destCode
|
|
|
271 |
serviceableLocationDetails.exp = exp
|
|
|
272 |
serviceableLocationDetails.cod = cod
|
|
|
273 |
serviceableLocationDetails.station_type = stationType
|
| 6524 |
rajveer |
274 |
serviceableLocationDetails.otgAvailable = otgAvailable
|
| 7733 |
manish.sha |
275 |
if provider.id == 1:
|
| 7627 |
rajveer |
276 |
codlimit = 10000
|
|
|
277 |
prepaidlimit = 50000
|
| 7733 |
manish.sha |
278 |
elif provider.id == 3:
|
| 7627 |
rajveer |
279 |
codlimit = 25000
|
|
|
280 |
prepaidlimit = 100000
|
| 7733 |
manish.sha |
281 |
elif provider.id == 6:
|
| 7627 |
rajveer |
282 |
codlimit = 25000
|
|
|
283 |
prepaidlimit = 100000
|
|
|
284 |
serviceableLocationDetails.providerPrepaidLimit = prepaidlimit
|
|
|
285 |
serviceableLocationDetails.providerCodLimit = codlimit
|
|
|
286 |
serviceableLocationDetails.websiteCodLimit = codlimit
|
|
|
287 |
serviceableLocationDetails.storeCodLimit = codlimit
|
| 6322 |
amar.kumar |
288 |
session.commit()
|
|
|
289 |
|
| 6524 |
rajveer |
290 |
def update_pincode(providerId, pincode, exp, cod, otgAvailable):
|
| 6615 |
amar.kumar |
291 |
serviceableLocationDetails = ServiceableLocationDetails.get_by(provider_id = providerId, dest_pincode = pincode)
|
| 6322 |
amar.kumar |
292 |
serviceableLocationDetails.exp = exp
|
|
|
293 |
serviceableLocationDetails.cod = cod
|
| 6524 |
rajveer |
294 |
serviceableLocationDetails.otgAvailable = otgAvailable
|
| 7256 |
rajveer |
295 |
session.commit()
|
| 7567 |
rajveer |
296 |
|
| 13146 |
manish.sha |
297 |
def add_new_awbs(provider_id, isCod, awbs, awbUsedFor):
|
| 7567 |
rajveer |
298 |
provider = get_provider(provider_id)
|
|
|
299 |
if isCod:
|
|
|
300 |
dtype = 'Cod'
|
|
|
301 |
else:
|
|
|
302 |
dtype = 'Prepaid'
|
|
|
303 |
for awb in awbs:
|
|
|
304 |
a = Awb()
|
|
|
305 |
a.type = dtype
|
|
|
306 |
a.is_available = True
|
|
|
307 |
a.awb_number = awb
|
| 13146 |
manish.sha |
308 |
a.awbUsedFor = awbUsedFor
|
| 7567 |
rajveer |
309 |
a.provider = provider
|
|
|
310 |
session.commit()
|
| 7608 |
rajveer |
311 |
return True
|
| 7256 |
rajveer |
312 |
|
|
|
313 |
def adjust_delivery_time(start_time, delivery_days):
|
|
|
314 |
'''
|
|
|
315 |
Returns the actual no. of days which will pass while 'delivery_days'
|
|
|
316 |
no. of business days will pass since 'order_time'.
|
|
|
317 |
'''
|
|
|
318 |
start_date = start_time.date()
|
|
|
319 |
end_date = start_date + datetime.timedelta(days = delivery_days)
|
| 7272 |
amit.gupta |
320 |
holidays = get_holidays(to_java_date(start_time), -1)
|
| 7256 |
rajveer |
321 |
holidays = [to_py_date(holiday).date() for holiday in holidays]
|
|
|
322 |
|
|
|
323 |
while start_date <= end_date:
|
|
|
324 |
if start_date.weekday() == 6 or start_date in holidays:
|
|
|
325 |
delivery_days = delivery_days + 1
|
|
|
326 |
end_date = end_date + datetime.timedelta(days = 1)
|
|
|
327 |
start_date = start_date + datetime.timedelta(days = 1)
|
|
|
328 |
|
|
|
329 |
return delivery_days
|
| 7275 |
rajveer |
330 |
|
|
|
331 |
def get_min_advance_amount(itemId, destination_pin, providerId, codAllowed):
|
|
|
332 |
client = CatalogClient().get_client()
|
|
|
333 |
sp = client.getStorePricing(itemId)
|
|
|
334 |
|
|
|
335 |
if codAllowed:
|
|
|
336 |
return sp.minAdvancePrice, True
|
|
|
337 |
else:
|
| 7857 |
rajveer |
338 |
dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit = serviceable_location_cache.get(providerId).get(destination_pin)
|
| 7275 |
rajveer |
339 |
if iscod:
|
|
|
340 |
if providerId == 6:
|
| 7489 |
rajveer |
341 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
| 7275 |
rajveer |
342 |
if providerId == 3:
|
| 7489 |
rajveer |
343 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
| 7275 |
rajveer |
344 |
if providerId == 1:
|
| 7489 |
rajveer |
345 |
return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
|
| 7275 |
rajveer |
346 |
else:
|
| 7425 |
rajveer |
347 |
return sp.recommendedPrice, False
|
| 7733 |
manish.sha |
348 |
#Start:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
349 |
|
| 7786 |
manish.sha |
350 |
def run_Logistics_Location_Info_Update(logisticsLocationInfoList, runCompleteUpdate):
|
|
|
351 |
if runCompleteUpdate == True :
|
|
|
352 |
serviceableLocationDetails = ServiceableLocationDetails.query.all()
|
|
|
353 |
for serviceableLocationDetail in serviceableLocationDetails:
|
| 7841 |
manish.sha |
354 |
serviceableLocationDetail.exp = False
|
|
|
355 |
serviceableLocationDetail.cod = False
|
| 7786 |
manish.sha |
356 |
for logisticsLocationInfo in logisticsLocationInfoList:
|
| 7841 |
manish.sha |
357 |
serviceableLocationDetail = ServiceableLocationDetails.get_by(provider_id = logisticsLocationInfo.providerId, dest_pincode = logisticsLocationInfo.pinCode)
|
| 7914 |
rajveer |
358 |
provider = Provider.query.filter_by(id = logisticsLocationInfo.providerId).one()
|
| 7841 |
manish.sha |
359 |
if serviceableLocationDetail:
|
|
|
360 |
serviceableLocationDetail.exp = logisticsLocationInfo.expAvailable
|
|
|
361 |
serviceableLocationDetail.cod = logisticsLocationInfo.codAvailable
|
|
|
362 |
serviceableLocationDetail.otgAvailable = logisticsLocationInfo.otgAvailable
|
|
|
363 |
serviceableLocationDetail.providerCodLimit = logisticsLocationInfo.codLimit
|
|
|
364 |
serviceableLocationDetail.providerPrepaidLimit = logisticsLocationInfo.prepaidLimit
|
|
|
365 |
serviceableLocationDetail.storeCodLimit = logisticsLocationInfo.codLimit
|
| 8219 |
manish.sha |
366 |
serviceableLocationDetail.websiteCodLimit = min(26000,logisticsLocationInfo.codLimit)
|
| 7841 |
manish.sha |
367 |
else:
|
|
|
368 |
serviceableLocationDetail= ServiceableLocationDetails()
|
|
|
369 |
serviceableLocationDetail.provider = provider
|
|
|
370 |
serviceableLocationDetail.dest_pincode = logisticsLocationInfo.pinCode
|
|
|
371 |
serviceableLocationDetail.dest_code = logisticsLocationInfo.destinationCode
|
|
|
372 |
serviceableLocationDetail.exp = logisticsLocationInfo.expAvailable
|
|
|
373 |
serviceableLocationDetail.cod = logisticsLocationInfo.codAvailable
|
|
|
374 |
serviceableLocationDetail.station_type = 0
|
|
|
375 |
serviceableLocationDetail.otgAvailable = logisticsLocationInfo.otgAvailable
|
|
|
376 |
serviceableLocationDetail.providerCodLimit = logisticsLocationInfo.codLimit
|
|
|
377 |
serviceableLocationDetail.providerPrepaidLimit = logisticsLocationInfo.prepaidLimit
|
|
|
378 |
serviceableLocationDetail.storeCodLimit = logisticsLocationInfo.codLimit
|
| 8219 |
manish.sha |
379 |
serviceableLocationDetail.websiteCodLimit = min(26000,logisticsLocationInfo.codLimit)
|
| 7841 |
manish.sha |
380 |
|
| 7870 |
rajveer |
381 |
deliveryEstimate = DeliveryEstimate.get_by(provider_id = logisticsLocationInfo.providerId, destination_pin = logisticsLocationInfo.pinCode, warehouse_location = logisticsLocationInfo.warehouseId)
|
| 7841 |
manish.sha |
382 |
if deliveryEstimate:
|
|
|
383 |
deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
|
|
|
384 |
deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
|
|
|
385 |
deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
|
|
|
386 |
else:
|
|
|
387 |
deliveryEstimate = DeliveryEstimate()
|
|
|
388 |
deliveryEstimate.destination_pin= logisticsLocationInfo.pinCode
|
|
|
389 |
deliveryEstimate.provider = provider
|
|
|
390 |
deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
|
|
|
391 |
deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
|
|
|
392 |
deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
|
| 7733 |
manish.sha |
393 |
session.commit()
|
| 7786 |
manish.sha |
394 |
|
| 7733 |
manish.sha |
395 |
#End:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 7275 |
rajveer |
396 |
|
| 12895 |
manish.sha |
397 |
def get_first_delivery_estimate_for_wh_location(pincode, whLocation):
|
|
|
398 |
delEstimate = DeliveryEstimate.query.filter(DeliveryEstimate.destination_pin == pincode).filter(DeliveryEstimate.warehouse_location == whLocation).first()
|
|
|
399 |
if delEstimate is None:
|
|
|
400 |
return -1
|
|
|
401 |
else:
|
|
|
402 |
return 1
|
| 13146 |
manish.sha |
403 |
|
|
|
404 |
def get_provider_limit_details_for_pincode(provider, pincode):
|
|
|
405 |
serviceAbleDetails = ServiceableLocationDetails.get_by(provider_id = provider, dest_pincode = pincode)
|
|
|
406 |
returnDataMap = {}
|
|
|
407 |
if serviceAbleDetails:
|
|
|
408 |
returnDataMap["websiteCodLimit"] = str(serviceAbleDetails.websiteCodLimit)
|
|
|
409 |
returnDataMap["providerPrepaidLimit"] = str(serviceAbleDetails.providerPrepaidLimit)
|
|
|
410 |
|
|
|
411 |
return returnDataMap
|
|
|
412 |
|
|
|
413 |
def get_new_empty_awb(providerId, type, orderQuantity):
|
|
|
414 |
query = Awb.query.with_lockmode("update").filter_by(provider_id = providerId, is_available = True) #check the provider thing
|
|
|
415 |
if type == DeliveryType.PREPAID:
|
|
|
416 |
query = query.filter_by(type="Prepaid")
|
|
|
417 |
if type == DeliveryType.COD:
|
|
|
418 |
query = query.filter_by(type="COD")
|
|
|
419 |
|
|
|
420 |
additionalQuery = query
|
|
|
421 |
if orderQuantity == 1:
|
|
|
422 |
query = query.filter_by(awbUsedFor=0)
|
|
|
423 |
if orderQuantity >1:
|
|
|
424 |
query = query.filter_by(awbUsedFor=1)
|
|
|
425 |
|
|
|
426 |
try:
|
|
|
427 |
awb = query.first()
|
|
|
428 |
if awb is None:
|
|
|
429 |
additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
|
|
|
430 |
awb = additionalQuery.first()
|
|
|
431 |
awb.is_available = False
|
|
|
432 |
session.commit()
|
|
|
433 |
return awb.awb_number
|
|
|
434 |
except:
|
|
|
435 |
raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(providerId))
|
|
|
436 |
|