Subversion Repositories SmartDukaan

Rev

Rev 20275 | Rev 20724 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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, \
19421 manish.sha 13
    ServiceableLocationDetails, PickupStore, Locations, ProviderCosting
16025 amit.gupta 14
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
19421 manish.sha 15
    DeliveryType, LogisticsLocationInfo, LocationInfo, ProviderInfo, DeliveryEstimateAndCosting
19413 amit.gupta 16
from shop2020.thriftpy.model.v1.inventory.ttypes import Warehouse, BillingType, \
16025 amit.gupta 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
19413 amit.gupta 25
from collections import namedtuple
19483 manish.sha 26
import math
19413 amit.gupta 27
 
3355 chandransh 28
logging.basicConfig(level=logging.DEBUG)
442 rajveer 29
 
19413 amit.gupta 30
PincodeProvider = namedtuple("PincodeProvider", ["dest_pin", "provider"])
31
 
3217 rajveer 32
warehouse_allocation_cache = {}
33
serviceable_location_cache = {}
34
delivery_estimate_cache = {}
16025 amit.gupta 35
warehouse_location_cache = {}
19413 amit.gupta 36
location_state={}
20275 amit.gupta 37
 
38
'Delhivery Bluedart, Fedex Surface, Fedex Air'
19413 amit.gupta 39
state_locations = {}
19421 manish.sha 40
provider_costing_sheet = {}
41
DELHIVERY = 3
6370 rajveer 42
 
19413 amit.gupta 43
#pincode location map is ab
44
#{'110001':{1:{"sameState":False, "providerInfo":{1:(1,1), 2:(1,1)}}},}
45
pincode_locations = {}
46
#{(dest_pin, provider):(otgAvailable,providerCodLimit, websiteCodLimit, storeCodLimit, providerPrepaidLimit)} 
47
serviceable_map = {}
48
 
49
#Need to identify a better way
50
statepinmap={'11':0, 
51
             '40':1,'41':1,'42':1,'43':1,'44':1,
52
             '56':2, '57':2, '58':2, '59':2,
53
             '12':3, '13':3, 
54
             '30':4, '31':4, '32':4, '33':4, '34':4,
55
             '36':6,'37':6,'38':6,'39':6
56
             }
57
 
3218 rajveer 58
'''
59
This class is for only data transfer. Never used outside this module.
60
'''
61
class _DeliveryEstimateObject:
6537 rajveer 62
    def __init__(self, delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable):
3218 rajveer 63
        self.delivery_time = delivery_time
6537 rajveer 64
        self.delivery_delay = delivery_delay
3218 rajveer 65
        self.provider_id = provider_id
4866 rajveer 66
        self.codAllowed = codAllowed
6524 rajveer 67
        self.otgAvailable = otgAvailable
3218 rajveer 68
 
3187 rajveer 69
def initialize(dbname="logistics", db_hostname="localhost"):
442 rajveer 70
    log_entry("initialize@DataAccessor", "Initializing data service")
3187 rajveer 71
    DataService.initialize(dbname, db_hostname)
3218 rajveer 72
    print "Starting cache population at: " + str(datetime.datetime.now())
16025 amit.gupta 73
    #__cache_warehouse_allocation_table()
74
    __cache_warehouse_locations()
3217 rajveer 75
    __cache_serviceable_location_details_table()
76
    __cache_delivery_estimate_table()
20275 amit.gupta 77
    __cache_pincode_provider_serviceability()
19413 amit.gupta 78
    __cache_locations()
79
    __cache_pincode_estimates()    
19421 manish.sha 80
    __cache_courier_costing_table()
3217 rajveer 81
    close_session()
3218 rajveer 82
    print "Done cache population at: " + str(datetime.datetime.now())
442 rajveer 83
 
19413 amit.gupta 84
def __cache_locations():
85
    locations = Locations.query.all()
86
    for location in locations:
87
        location_state[location.id] = location.state_id
88
        if not state_locations.has_key(location.state_id):
89
            state_locations[location.state_id] = []
90
        state_locations[location.state_id] = state_locations[location.state_id].append(location.state_id)
91
 
92
def __cache_pincode_estimates():
93
    delivery_estimates = DeliveryEstimate.query.all()
94
    for delivery_estimate in delivery_estimates:
95
        if not pincode_locations.has_key(delivery_estimate.destination_pin):
96
            pincode_locations[delivery_estimate.destination_pin] = {}
97
        destination_pinMap = pincode_locations[delivery_estimate.destination_pin] 
98
        if not destination_pinMap.has_key(delivery_estimate.warehouse_location):
99
            destination_pinMap[delivery_estimate.warehouse_location] = {}
100
            state_id = location_state.get(delivery_estimate.warehouse_location)
101
            sameState = __getStateFromPin(delivery_estimate.destination_pin) == state_id
102
            destination_pinMap[delivery_estimate.warehouse_location]['sameState']=sameState
103
            destination_pinMap[delivery_estimate.warehouse_location]['providerInfo'] = {} 
104
        destination_pinMap[delivery_estimate.warehouse_location]['providerInfo'][delivery_estimate.provider_id] = delivery_estimate.delivery_time + delivery_estimate.delivery_delay
105
 
106
 
107
 
108
def __cache_pincode_provider_serviceability():
109
    pincode_providers = ServiceableLocationDetails.query.filter(ServiceableLocationDetails.exp==1)
110
    for pp in pincode_providers:
111
        serviceable_map[PincodeProvider(pp.dest_pincode, pp.provider_id)] = (pp.cod, pp.otgAvailable,pp.providerCodLimit, pp.websiteCodLimit, pp.storeCodLimit, pp.providerPrepaidLimit)
112
 
113
 
3217 rajveer 114
def __cache_delivery_estimate_table():
115
    delivery_estimates = DeliveryEstimate.query.all()
116
    for delivery_estimate in delivery_estimates:
7857 rajveer 117
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
19421 manish.sha 118
        =delivery_estimate.delivery_time, delivery_estimate.delivery_delay, delivery_estimate.providerZoneCode
3217 rajveer 119
 
120
def __cache_serviceable_location_details_table():
5964 amar.kumar 121
    serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
3217 rajveer 122
    for serviceable_location in serviceable_locations:
123
        try:
124
            provider_pincodes = serviceable_location_cache[serviceable_location.provider_id]
125
        except:
126
            provider_pincodes = {}
127
            serviceable_location_cache[serviceable_location.provider_id] = provider_pincodes 
19474 manish.sha 128
        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, serviceable_location.providerCodLimit
3217 rajveer 129
 
130
def __cache_warehouse_allocation_table():
131
    warehouse_allocations = WarehouseAllocation.query.all()
132
    for warehouse_allocation in warehouse_allocations:
133
        warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
134
 
16025 amit.gupta 135
def __cache_warehouse_locations():
136
    client = InventoryClient().get_client()
19413 amit.gupta 137
    #client.getAllWarehouses(True)
16025 amit.gupta 138
    for warehouse in client.getAllWarehouses(True):
139
        warehouse_location_cache[warehouse.billingWarehouseId]=warehouse.logisticsLocation
19421 manish.sha 140
 
141
def __cache_courier_costing_table():
142
    allCostings = ProviderCosting.query.all()
143
    for costing in allCostings:
144
        if provider_costing_sheet.has_key(costing.provider_id):
145
            costingMap = provider_costing_sheet.get(costing.provider_id)
146
            costingMap[costing.zoneCode] = costing
147
            provider_costing_sheet[costing.provider_id] = costingMap
148
        else:
149
            costingMap = {}
150
            costingMap[costing.zoneCode] = costing
151
            provider_costing_sheet[costing.provider_id] = costingMap
152
 
16025 amit.gupta 153
 
644 chandransh 154
def get_provider(provider_id):
766 rajveer 155
    provider =  Provider.get_by(id=provider_id)
156
    return provider
644 chandransh 157
 
158
def get_providers():
5387 rajveer 159
    providers = Provider.query.filter_by(isActive = 1).all()
19413 amit.gupta 160
    return providers
644 chandransh 161
 
19413 amit.gupta 162
#it would return only states where our warehouses are present else return -1
163
def __getStateFromPin(pin):
164
    if pin[:3] in ['744', '682']:
165
        return -1
166
    elif statepinmap.has_key(pin[:2]):
167
        return statepinmap[pin[:2]]
168
    else:
169
        return -1
170
 
171
 
172
def get_logistics_locations(destination_pin, selling_price_list):
173
    #pincode_locations = {1:{"sameState":False, "providerInfo":{<provider_id>:<delay_days>}},}
174
    #pp.otgAvailable,pp.providerCodLimit, pp.websiteCodLimit, pp.storeCodLimit, pp.providerPrepaidLimit
175
    returnMap = {}
176
    if pincode_locations.has_key(destination_pin):
177
        locations = pincode_locations[destination_pin]
178
        for item_selling_price in selling_price_list:
179
            returnMap[item_selling_price] = {}
180
            for location_id, value in locations.iteritems():
181
                #put weight logic here
182
                otgAvailable = False
183
                codAvailable = False
184
                minDelay = -1
185
                maxDelay = -1
186
                serviceable = False
187
                for provider_id, delay_days in value['providerInfo'].iteritems():
19420 amit.gupta 188
                    pp = PincodeProvider(destination_pin, provider_id)
189
                    if not serviceable_map.has_key(pp):
190
                        continue
191
                    iscod, isotg, providerCodLimit, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_map[pp]  
19413 amit.gupta 192
                    if item_selling_price <= providerPrepaidLimit:
193
                        if not serviceable:
20275 amit.gupta 194
                            returnMap[item_selling_price][location_id] = LocationInfo(locationId = location_id, sameState=value['sameState'])
19413 amit.gupta 195
                            serviceable = True
196
                            minDelay = delay_days
197
                            maxDelay = delay_days
198
                        else:
199
                            minDelay = min(delay_days,minDelay)
200
                            maxDelay = max(delay_days,maxDelay)
201
                        iscod = iscod and item_selling_price <= min(providerCodLimit, websiteCodLimit)
202
                        isotg = (isotg and item_selling_price >= 2000)
203
                        otgAvailable = otgAvailable or isotg
204
                        codAvailable = codAvailable or iscod
205
                if serviceable:        
20275 amit.gupta 206
                    returnMap[item_selling_price][location_id].isOtg = otgAvailable
207
                    returnMap[item_selling_price][location_id].isCod = codAvailable
19413 amit.gupta 208
                    returnMap[item_selling_price][location_id].minDelay = minDelay
209
                    returnMap[item_selling_price][location_id].maxDelay = maxDelay
210
    return returnMap
211
 
7608 rajveer 212
def get_logistics_estimation(destination_pin, item_selling_price, weight, type, billingWarehouseId):
5692 rajveer 213
    logging.info("Getting logistics estimation for pincode:" + destination_pin )
1504 ankur.sing 214
 
7608 rajveer 215
    provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
9964 anupam.sin 216
 
17530 manish.sha 217
    logging.info("Provider Id:  " + str(provider_id) +" codAllowed: "+str(codAllowed)+" otgAvailable: "+str(otgAvailable)+ " item_selling_price: "+str(item_selling_price))
218
 
219
    if item_selling_price > 60000:# or item_selling_price <= 250:
9964 anupam.sin 220
        codAllowed = False
221
 
16025 amit.gupta 222
    warehouse_location = warehouse_location_cache.get(billingWarehouseId)
223
    if warehouse_location is None:
224
        warehouse_location = 0
7857 rajveer 225
 
3217 rajveer 226
    if not provider_id:
5692 rajveer 227
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
644 chandransh 228
    try:
16025 amit.gupta 229
        logging.info( "destination_pin %s, provider_id %s, warehouse_location %s"%(destination_pin, provider_id, warehouse_location))
19481 manish.sha 230
        logging.info( "Estimates %s, %s, %s"%(delivery_estimate_cache[destination_pin, provider_id, warehouse_location]))
7857 rajveer 231
        delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
232
        delivery_delay = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
6537 rajveer 233
        delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
3218 rajveer 234
        return delivery_estimate
1504 ankur.sing 235
    except Exception as ex:
236
        print ex
644 chandransh 237
        raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
3150 rajveer 238
 
7608 rajveer 239
def __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId):
20641 amit.gupta 240
    #As of now we are dealing with Aramex and Bluedart. i.e. 1 and 2 and we have just one location i.e. gurgaon will generailise this 
241
    #Once bandwidth is available these things will be derived through improved logic.
242
    #As of now otg is set to False
243
    otg=False
244
    prepaidProvider=None
245
    if serviceable_location_cache.has_key(2) and serviceable_location_cache.get(2).has_key(destination_pin):
246
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(2).get(destination_pin)
247
        if item_selling_price <= providerPrepaidLimit:
248
            iscod = iscod and item_selling_price <= websiteCodLimit
249
            if iscod:
250
                return 2, True, otg
251
        prepaidProvider=2
252
    if serviceable_location_cache.has_key(1) and serviceable_location_cache.get(1).has_key(destination_pin):
253
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(1).get(destination_pin)
254
        if item_selling_price <= providerPrepaidLimit:
255
            iscod = iscod and item_selling_price <= websiteCodLimit
256
            if iscod:
257
                return 1, True, otg
258
        if prepaidProvider is None:
259
            prepaidProvider=1
260
 
261
    if prepaidProvider:
262
        return prepaidProvider, False, otg 
263
 
264
    return None, False, False
265
 
266
def __get_logistics_provider_for_destination_pincode_old(destination_pin, item_selling_price, weight, type, billingWarehouseId):
13357 manish.sha 267
    '''
268
    if serviceable_location_cache.get(6).has_key(destination_pin):
269
        if weight < 480 and serviceable_location_cache.get(3).has_key(destination_pin) and type == DeliveryType.PREPAID:
270
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(3).get(destination_pin)
271
            if item_selling_price <= providerPrepaidLimit:
272
                iscod = iscod and item_selling_price <= websiteCodLimit
273
                otgAvailable = otgAvailable and item_selling_price >= 2000
274
                return 3, iscod, otgAvailable
275
        else:
276
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(6).get(destination_pin)
277
            if item_selling_price <= providerPrepaidLimit:
278
                iscod = iscod and item_selling_price <= websiteCodLimit
279
                otgAvailable = otgAvailable and item_selling_price >= 2000
280
                return 6, iscod, otgAvailable
20641 amit.gupta 281
    '''        
282
    if serviceable_location_cache.has_key(3) and serviceable_location_cache.get(3).has_key(destination_pin):
283
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(3).get(destination_pin)
284
        if item_selling_price <= providerPrepaidLimit:
285
            iscod = iscod and item_selling_price <= websiteCodLimit
286
            otgAvailable = otgAvailable and item_selling_price >= 2000
287
            return 3, iscod, otgAvailable
8575 rajveer 288
 
17992 manish.sha 289
    if billingWarehouseId not in [12,13] and serviceable_location_cache.has_key(7) and serviceable_location_cache.get(7).has_key(destination_pin):
19533 manish.sha 290
        if item_selling_price < 3000 and serviceable_location_cache.has_key(1) and serviceable_location_cache.get(1).has_key(destination_pin):
19476 manish.sha 291
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(1).get(destination_pin)
8575 rajveer 292
            if item_selling_price <= providerPrepaidLimit:
293
                iscod = iscod and item_selling_price <= websiteCodLimit
294
                otgAvailable = otgAvailable and item_selling_price >= 2000
20275 amit.gupta 295
                if iscod:
296
                    return 1, iscod, otgAvailable
8575 rajveer 297
        else:
19476 manish.sha 298
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(7).get(destination_pin)
8575 rajveer 299
            if item_selling_price <= providerPrepaidLimit:
300
                iscod = iscod and item_selling_price <= websiteCodLimit
301
                otgAvailable = otgAvailable and item_selling_price >= 2000
20275 amit.gupta 302
                if iscod:
303
                    return 7, iscod, otgAvailable
19533 manish.sha 304
 
305
    if billingWarehouseId not in [12,13] and serviceable_location_cache.has_key(46) and serviceable_location_cache.get(46).has_key(destination_pin):
306
        if item_selling_price < 3000 and serviceable_location_cache.has_key(1) and serviceable_location_cache.get(1).has_key(destination_pin):
307
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(1).get(destination_pin)
308
            if item_selling_price <= providerPrepaidLimit:
309
                iscod = iscod and item_selling_price <= websiteCodLimit
310
                otgAvailable = otgAvailable and item_selling_price >= 2000
20275 amit.gupta 311
                if iscod:
312
                    return 1, iscod, otgAvailable
19533 manish.sha 313
        else:
314
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(46).get(destination_pin)
315
            if item_selling_price <= providerPrepaidLimit:
316
                iscod = iscod and item_selling_price <= websiteCodLimit
317
                otgAvailable = otgAvailable and item_selling_price >= 2000
20275 amit.gupta 318
                if iscod:
319
                    return 46, iscod, otgAvailable
8575 rajveer 320
 
19533 manish.sha 321
    if serviceable_location_cache.has_key(1) and serviceable_location_cache.get(1).has_key(destination_pin):
19476 manish.sha 322
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(1).get(destination_pin)
7627 rajveer 323
        if item_selling_price <= providerPrepaidLimit:
7608 rajveer 324
            iscod = iscod and item_selling_price <= websiteCodLimit
325
            otgAvailable = otgAvailable and item_selling_price >= 2000
20275 amit.gupta 326
            if iscod:
327
                return 1, iscod, otgAvailable
7981 rajveer 328
 
20275 amit.gupta 329
    if serviceable_location_cache.has_key(3) and serviceable_location_cache.get(3).has_key(destination_pin):
330
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(3).get(destination_pin)
331
        if item_selling_price <= providerPrepaidLimit:
332
            iscod = iscod and item_selling_price <= websiteCodLimit
333
            otgAvailable = otgAvailable and item_selling_price >= 2000
334
            return 3, iscod, otgAvailable
10185 amit.gupta 335
    return None, False, False    
5278 rajveer 336
 
6017 amar.kumar 337
def get_destination_code(providerId, pinCode):
338
    serviceableLocationDetail = ServiceableLocationDetails.query.filter_by(provider_id = providerId, dest_pincode = pinCode).one()
339
    return serviceableLocationDetail.dest_code
340
 
644 chandransh 341
def add_empty_AWBs(numbers, provider_id, type):
442 rajveer 342
    for number in numbers:
644 chandransh 343
        query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
444 rajveer 344
        try:
345
            query.one()
346
        except:    
644 chandransh 347
            awb = Awb()
444 rajveer 348
            awb.awb_number = number
644 chandransh 349
            awb.provider_id = provider_id
444 rajveer 350
            awb.is_available = True
644 chandransh 351
            awb.type = type
352
    session.commit()
442 rajveer 353
 
444 rajveer 354
def set_AWB_as_used(awb_number):
644 chandransh 355
    query = Awb.query.filter_by(awb_number = awb_number)
444 rajveer 356
    awb = query.one() 
357
    awb.is_available=False
358
    session.commit()
359
 
3044 chandransh 360
def get_empty_AWB(provider_id, type = DeliveryType.PREPAID):
2342 chandransh 361
    query = Awb.query.with_lockmode("update").filter_by(provider_id = provider_id, is_available = True)  #check the provider thing
3044 chandransh 362
    if type == DeliveryType.PREPAID:
363
        query = query.filter_by(type="Prepaid")
364
    if type == DeliveryType.COD:
365
        query = query.filter_by(type="COD")
366
 
13158 manish.sha 367
    additionalQuery = query
368
    query = query.filter_by(awbUsedFor=0)
369
 
442 rajveer 370
    try:
644 chandransh 371
        awb = query.first()
13158 manish.sha 372
        if awb is None:
373
            additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
374
            awb = additionalQuery.first()
644 chandransh 375
        awb.is_available = False
376
        session.commit()
444 rajveer 377
        return awb.awb_number
442 rajveer 378
    except:
644 chandransh 379
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
1137 chandransh 380
 
3103 chandransh 381
def get_free_awb_count(provider_id, type):
382
    count = Awb.query.filter_by(provider_id = provider_id, is_available = True, type=type).count()
1137 chandransh 383
    if count == None:
384
        count = 0
385
    return count
442 rajveer 386
 
644 chandransh 387
def get_shipment_info(awb_number, provider_id):
388
    awb = Awb.get_by(awb_number = awb_number, provider_id = provider_id)
389
    query = AwbUpdate.query.filter_by(awb = awb)
766 rajveer 390
    info = query.all()
391
    return info
392
 
6643 rajveer 393
def store_shipment_info(update):
394
    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()
395
    if not updates:
396
        dupdate = AwbUpdate()
397
        dupdate.providerId = update.providerId
398
        dupdate.awbNumber  = update.awbNumber
399
        dupdate.location = update.location
400
        dupdate.date = to_py_date(update.date)
401
        dupdate.status = update.status
402
        dupdate.description = update.description
403
        session.commit()
404
 
1730 ankur.sing 405
def get_holidays(start_date, end_date):
406
    query = PublicHolidays.query
407
    if start_date != -1:
408
        query = query.filter(PublicHolidays.date >= to_py_date(start_date))
409
    if end_date != -1:
410
        query = query.filter(PublicHolidays.date <= to_py_date(end_date))
411
    holidays = query.all()
412
    holiday_dates = [to_java_date(datetime.datetime(*time.strptime(str(holiday.date), '%Y-%m-%d')[:3])) for holiday in holidays] 
413
    return holiday_dates
414
 
5527 anupam.sin 415
def get_provider_for_pickup_type(pickUp):
416
    return Provider.query.filter(Provider.pickup == pickUp).first().id
417
 
766 rajveer 418
def close_session():
419
    if session.is_active:
420
        print "session is active. closing it."
2823 chandransh 421
        session.close()
3376 rajveer 422
 
423
def is_alive():
424
    try:
425
        session.query(Awb.id).limit(1).one()
426
        return True
427
    except:
5555 rajveer 428
        return False
429
 
430
def get_all_pickup_stores():
5572 anupam.sin 431
    pickupStores = PickupStore.query.all()
432
    return pickupStores
5555 rajveer 433
 
434
def get_pickup_store(storeId):
5719 rajveer 435
    return PickupStore.query.filter_by(id = storeId).one()
436
 
437
def get_pickup_store_by_hotspot_id(hotspotId):
438
    return PickupStore.query.filter_by(hotspotId = hotspotId).one()
6322 amar.kumar 439
 
6524 rajveer 440
def add_pincode(provider, pincode, destCode, exp, cod, stationType, otgAvailable):
7914 rajveer 441
    provider = Provider.query.filter_by(id = provider).one()
6322 amar.kumar 442
    serviceableLocationDetails = ServiceableLocationDetails()
443
    serviceableLocationDetails.provider = provider
444
    serviceableLocationDetails.dest_pincode = pincode
445
    serviceableLocationDetails.dest_code = destCode
446
    serviceableLocationDetails.exp = exp
447
    serviceableLocationDetails.cod = cod
448
    serviceableLocationDetails.station_type = stationType
6524 rajveer 449
    serviceableLocationDetails.otgAvailable = otgAvailable
7733 manish.sha 450
    if provider.id == 1:
7627 rajveer 451
        codlimit = 10000
452
        prepaidlimit = 50000
7733 manish.sha 453
    elif provider.id == 3:
7627 rajveer 454
        codlimit = 25000
455
        prepaidlimit = 100000
7733 manish.sha 456
    elif provider.id == 6:
7627 rajveer 457
        codlimit = 25000
458
        prepaidlimit = 100000
459
    serviceableLocationDetails.providerPrepaidLimit = prepaidlimit
460
    serviceableLocationDetails.providerCodLimit = codlimit
461
    serviceableLocationDetails.websiteCodLimit = codlimit
462
    serviceableLocationDetails.storeCodLimit = codlimit
6322 amar.kumar 463
    session.commit()
464
 
6524 rajveer 465
def update_pincode(providerId, pincode, exp, cod, otgAvailable):
6615 amar.kumar 466
    serviceableLocationDetails = ServiceableLocationDetails.get_by(provider_id = providerId, dest_pincode = pincode)
6322 amar.kumar 467
    serviceableLocationDetails.exp = exp
468
    serviceableLocationDetails.cod = cod
6524 rajveer 469
    serviceableLocationDetails.otgAvailable = otgAvailable
7256 rajveer 470
    session.commit()
7567 rajveer 471
 
13146 manish.sha 472
def add_new_awbs(provider_id, isCod, awbs, awbUsedFor):
7567 rajveer 473
    provider = get_provider(provider_id)
474
    if isCod:
475
        dtype = 'Cod'
476
    else:
477
        dtype = 'Prepaid'
478
    for awb in awbs:
479
        a = Awb()
480
        a.type =  dtype
481
        a.is_available = True
482
        a.awb_number = awb
13146 manish.sha 483
        a.awbUsedFor = awbUsedFor
7567 rajveer 484
        a.provider = provider 
485
    session.commit()
7608 rajveer 486
    return True
7256 rajveer 487
 
488
def adjust_delivery_time(start_time, delivery_days):
489
    '''
490
    Returns the actual no. of days which will pass while 'delivery_days'
491
    no. of business days will pass since 'order_time'. 
492
    '''
493
    start_date = start_time.date()
494
    end_date = start_date + datetime.timedelta(days = delivery_days)
7272 amit.gupta 495
    holidays = get_holidays(to_java_date(start_time), -1)
7256 rajveer 496
    holidays = [to_py_date(holiday).date() for holiday in holidays]
497
 
498
    while start_date <= end_date:
499
        if start_date.weekday() == 6 or start_date in holidays:
500
            delivery_days = delivery_days + 1
501
            end_date = end_date + datetime.timedelta(days = 1)
502
        start_date = start_date + datetime.timedelta(days = 1)
503
 
504
    return delivery_days
7275 rajveer 505
 
506
def get_min_advance_amount(itemId, destination_pin, providerId, codAllowed):
507
    client = CatalogClient().get_client()
508
    sp = client.getStorePricing(itemId)
509
 
510
    if codAllowed:
511
        return sp.minAdvancePrice, True
512
    else:
20275 amit.gupta 513
        dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit  = serviceable_location_cache.get(providerId).get(destination_pin)
7275 rajveer 514
        if iscod:
515
            if providerId == 6:
7489 rajveer 516
                return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
7275 rajveer 517
            if providerId == 3:
7489 rajveer 518
                return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
7275 rajveer 519
            if providerId == 1:
7489 rajveer 520
                return max(sp.minAdvancePrice, sp.recommendedPrice - storeCodLimit), True
7275 rajveer 521
        else:
7425 rajveer 522
            return sp.recommendedPrice, False
7733 manish.sha 523
#Start:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
524
 
7786 manish.sha 525
def run_Logistics_Location_Info_Update(logisticsLocationInfoList, runCompleteUpdate):
526
    if runCompleteUpdate == True :
527
        serviceableLocationDetails = ServiceableLocationDetails.query.all()
528
        for serviceableLocationDetail in serviceableLocationDetails:
7841 manish.sha 529
            serviceableLocationDetail.exp = False
530
            serviceableLocationDetail.cod = False
7786 manish.sha 531
    for logisticsLocationInfo in logisticsLocationInfoList:
7841 manish.sha 532
        serviceableLocationDetail = ServiceableLocationDetails.get_by(provider_id = logisticsLocationInfo.providerId, dest_pincode = logisticsLocationInfo.pinCode)
7914 rajveer 533
        provider = Provider.query.filter_by(id = logisticsLocationInfo.providerId).one()
7841 manish.sha 534
        if serviceableLocationDetail:
535
            serviceableLocationDetail.exp = logisticsLocationInfo.expAvailable
536
            serviceableLocationDetail.cod = logisticsLocationInfo.codAvailable
537
            serviceableLocationDetail.otgAvailable = logisticsLocationInfo.otgAvailable
538
            serviceableLocationDetail.providerCodLimit = logisticsLocationInfo.codLimit
539
            serviceableLocationDetail.providerPrepaidLimit = logisticsLocationInfo.prepaidLimit
540
            serviceableLocationDetail.storeCodLimit = logisticsLocationInfo.codLimit
8219 manish.sha 541
            serviceableLocationDetail.websiteCodLimit = min(26000,logisticsLocationInfo.codLimit)
7841 manish.sha 542
        else:
543
            serviceableLocationDetail= ServiceableLocationDetails()
544
            serviceableLocationDetail.provider = provider
545
            serviceableLocationDetail.dest_pincode = logisticsLocationInfo.pinCode
546
            serviceableLocationDetail.dest_code = logisticsLocationInfo.destinationCode
547
            serviceableLocationDetail.exp = logisticsLocationInfo.expAvailable
548
            serviceableLocationDetail.cod = logisticsLocationInfo.codAvailable
549
            serviceableLocationDetail.station_type = 0
550
            serviceableLocationDetail.otgAvailable = logisticsLocationInfo.otgAvailable
551
            serviceableLocationDetail.providerCodLimit = logisticsLocationInfo.codLimit
552
            serviceableLocationDetail.providerPrepaidLimit = logisticsLocationInfo.prepaidLimit
553
            serviceableLocationDetail.storeCodLimit = logisticsLocationInfo.codLimit
8219 manish.sha 554
            serviceableLocationDetail.websiteCodLimit = min(26000,logisticsLocationInfo.codLimit)
7841 manish.sha 555
 
7870 rajveer 556
        deliveryEstimate = DeliveryEstimate.get_by(provider_id = logisticsLocationInfo.providerId, destination_pin = logisticsLocationInfo.pinCode, warehouse_location = logisticsLocationInfo.warehouseId) 
7841 manish.sha 557
        if deliveryEstimate:
558
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
559
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
560
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
19421 manish.sha 561
            deliveryEstimate.providerZoneCode = logisticsLocationInfo.zoneCode
7841 manish.sha 562
        else:
563
            deliveryEstimate = DeliveryEstimate()
564
            deliveryEstimate.destination_pin= logisticsLocationInfo.pinCode
565
            deliveryEstimate.provider = provider
566
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
567
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
568
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
19421 manish.sha 569
            deliveryEstimate.providerZoneCode = logisticsLocationInfo.zoneCode
7733 manish.sha 570
    session.commit()
7786 manish.sha 571
 
7733 manish.sha 572
#End:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013             
7275 rajveer 573
 
12895 manish.sha 574
def get_first_delivery_estimate_for_wh_location(pincode, whLocation):
575
    delEstimate = DeliveryEstimate.query.filter(DeliveryEstimate.destination_pin == pincode).filter(DeliveryEstimate.warehouse_location == whLocation).first()
576
    if delEstimate is None:
577
        return -1
578
    else:
579
        return 1
13146 manish.sha 580
 
581
def get_provider_limit_details_for_pincode(provider, pincode):
582
    serviceAbleDetails = ServiceableLocationDetails.get_by(provider_id = provider, dest_pincode = pincode)
583
    returnDataMap = {}
584
    if serviceAbleDetails:
585
        returnDataMap["websiteCodLimit"] = str(serviceAbleDetails.websiteCodLimit)
19230 manish.sha 586
        returnDataMap["providerCodLimit"] = str(serviceAbleDetails.providerCodLimit)
13146 manish.sha 587
        returnDataMap["providerPrepaidLimit"] = str(serviceAbleDetails.providerPrepaidLimit)
588
 
589
    return returnDataMap
590
 
591
def get_new_empty_awb(providerId, type, orderQuantity):
592
    query = Awb.query.with_lockmode("update").filter_by(provider_id = providerId, is_available = True)  #check the provider thing
593
    if type == DeliveryType.PREPAID:
594
        query = query.filter_by(type="Prepaid")
595
    if type == DeliveryType.COD:
596
        query = query.filter_by(type="COD")
597
 
598
    additionalQuery = query
599
    if orderQuantity == 1:
600
        query = query.filter_by(awbUsedFor=0)
601
    if orderQuantity >1:
602
        query = query.filter_by(awbUsedFor=1) 
603
 
604
    try:
605
        awb = query.first()
606
        if awb is None:
607
            additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
608
            awb = additionalQuery.first()
609
        awb.is_available = False
610
        session.commit()
611
        return awb.awb_number
612
    except:
613
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(providerId))
19421 manish.sha 614
 
19474 manish.sha 615
def get_costing_and_delivery_estimate_for_pincode(pincode, transactionAmount, isCod, weight, billingWarehouseId, isCompleteTxn):
616
    print pincode, transactionAmount, isCod, weight, billingWarehouseId
19421 manish.sha 617
    deliveryEstimate = {}
618
    logsiticsCosting = {}
619
    providerCostingMap = {}
620
    serviceability = {}
621
 
622
    for providerId in serviceable_location_cache.keys():
623
        if serviceable_location_cache.has_key(providerId) and serviceable_location_cache.get(providerId).has_key(pincode):
19474 manish.sha 624
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = serviceable_location_cache.get(providerId).get(pincode)
19421 manish.sha 625
            if isCod and iscod:
19474 manish.sha 626
                if not isCompleteTxn:
627
                    if transactionAmount <= providerCodLimit:
628
                        serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
629
                    else:
630
                        continue
631
                else:
632
                    serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
19421 manish.sha 633
            elif isCod and not iscod:
634
                continue
635
            else:
19474 manish.sha 636
                if not isCompleteTxn:
637
                    if transactionAmount <= providerPrepaidLimit:
638
                        serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
639
                    else:
640
                        continue
641
                else:
642
                    serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
19421 manish.sha 643
 
644
    warehouse_location = warehouse_location_cache.get(billingWarehouseId)
645
    if warehouse_location is None:
646
        warehouse_location = 0
647
 
648
    noCostFoundCount = 0
649
    if len(serviceability)>0:
650
        for providerId, serviceableDetails in serviceability.items():
651
            delivery_time = delivery_estimate_cache[pincode, providerId, warehouse_location][0]
652
            delivery_delay = delivery_estimate_cache[pincode, providerId, warehouse_location][1]
653
            zoneCode = delivery_estimate_cache[pincode, providerId, warehouse_location][2]
654
            sla = delivery_time + delivery_delay
655
            if deliveryEstimate.has_key(sla):
656
                estimate = deliveryEstimate.get(sla)
657
                estimate.append(providerId)
658
                deliveryEstimate[sla] = estimate
659
            else:
660
                estimate = []
661
                estimate.append(providerId)
662
                deliveryEstimate[sla] = estimate
663
 
664
            logisticsCost = 0
665
            codCollectionCharges = 0    
666
            logisticsCostObj = None 
667
            if provider_costing_sheet.has_key(providerId) and provider_costing_sheet.get(providerId).has_key(zoneCode):
668
                logisticsCostObj = provider_costing_sheet.get(providerId).get(zoneCode)
669
                logisticsCost = logisticsCostObj.initialLogisticsCost
670
                if weight > logisticsCostObj.initialWeightUpperLimit:
671
                    additionalWeight = weight-logisticsCostObj.initialWeightUpperLimit
19663 manish.sha 672
                    additionalWeight = round(additionalWeight,0)
19483 manish.sha 673
                    additionalCostMultiplier = math.ceil(additionalWeight/logisticsCostObj.additionalUnitWeight)
19421 manish.sha 674
                    additionalCost = additionalCostMultiplier*logisticsCostObj.additionalUnitLogisticsCost
675
                    logisticsCost = logisticsCost + additionalCost
676
                if isCod:
677
                    if logisticsCostObj.codCollectionFactor:
19474 manish.sha 678
                        codCollectionCharges = max(logisticsCostObj.minimumCodCollectionCharges, (transactionAmount*logisticsCostObj.codCollectionFactor)/100)
679
                        logisticsCost = logisticsCost + max(logisticsCostObj.minimumCodCollectionCharges, (transactionAmount*logisticsCostObj.codCollectionFactor)/100)
19421 manish.sha 680
                    else:
681
                        codCollectionCharges = logisticsCostObj.minimumCodCollectionCharges
682
                        logisticsCost = logisticsCost + logisticsCostObj.minimumCodCollectionCharges
683
 
19474 manish.sha 684
                if logsiticsCosting.has_key(round(logisticsCost,0)):
685
                    costingList = logsiticsCosting.get(round(logisticsCost,0))
19421 manish.sha 686
                    costingList.append(providerId)
19474 manish.sha 687
                    logsiticsCosting[round(logisticsCost,0)] = costingList
19421 manish.sha 688
                else:
689
                    costingList = []
690
                    costingList.append(providerId)
19474 manish.sha 691
                    logsiticsCosting[round(logisticsCost,0)] = costingList                    
19421 manish.sha 692
 
693
                providerCostingMap[providerId] = [logisticsCost,codCollectionCharges]
694
            else:
695
                noCostFoundCount = noCostFoundCount +1
696
                continue
697
    else:
19474 manish.sha 698
        print "No provider assigned for pincode: " + str(pincode)
19535 manish.sha 699
        raise LogisticsServiceException(103, "Unable to get Provider for given pincode: " + str(pincode)+" Amount:- "+str(transactionAmount)+" Weight:- "+ str(weight))
19421 manish.sha 700
 
701
 
702
    if noCostFoundCount == len(serviceability):
19474 manish.sha 703
        print "No Costing Found for this pincode: " + str(pincode) +" for any of the provider"
19535 manish.sha 704
        raise LogisticsServiceException(103, "Unable to get Provider for given pincode: " + str(pincode)+" Amount:- "+str(transactionAmount)+" Weight:- "+ str(weight)+". Due to no costing found")
19421 manish.sha 705
 
706
    allSla = sorted(deliveryEstimate.keys())
707
    if len(allSla)==1:
708
        allEligibleProviders = deliveryEstimate.get(allSla[0])
709
        if len(allEligibleProviders)==1:
19474 manish.sha 710
            try:
19421 manish.sha 711
                costingDetails = providerCostingMap.get(allEligibleProviders[0])
712
                delEstCostObj = DeliveryEstimateAndCosting()
713
                delEstCostObj.logistics_provider_id = allEligibleProviders[0]
714
                delEstCostObj.pincode = pincode
715
                delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][0]
716
                delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][1]
717
                delEstCostObj.codAllowed = serviceability[allEligibleProviders[0]][2]
718
                delEstCostObj.otgAvailable = serviceability[allEligibleProviders[0]][3]
719
                delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
720
                delEstCostObj.codCollectionCharges = costingDetails[1]
721
                return delEstCostObj
19474 manish.sha 722
            except:
19535 manish.sha 723
                raise LogisticsServiceException(103, "Unable to get Provider for given pincode: " + str(pincode)+" Amount:- "+str(transactionAmount)+" Weight:- "+ str(weight)+".")
19421 manish.sha 724
        else:
725
            costingListOrder = []
726
            for providerId in allEligibleProviders:
19474 manish.sha 727
                costingDetails = providerCostingMap.get(providerId)
728
                if costingDetails and costingDetails[0] not in costingListOrder:
729
                    costingListOrder.append(round(costingDetails[0],0))
730
 
731
            costingListOrder = sorted(costingListOrder)
732
            eligibleProviders = logsiticsCosting.get(costingListOrder[0])
733
            for providerId in eligibleProviders:
734
                if providerCostingMap.has_key(providerId):
735
                    costingDetails = providerCostingMap.get(providerId)
19421 manish.sha 736
                    delEstCostObj = DeliveryEstimateAndCosting()
19474 manish.sha 737
                    delEstCostObj.logistics_provider_id = providerId
19421 manish.sha 738
                    delEstCostObj.pincode = pincode
19474 manish.sha 739
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, providerId, warehouse_location][0]
740
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, providerId, warehouse_location][1]
741
                    delEstCostObj.codAllowed = serviceability[providerId][2]
742
                    delEstCostObj.otgAvailable = serviceability[providerId][3]
19421 manish.sha 743
                    delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
744
                    delEstCostObj.codCollectionCharges = costingDetails[1]
745
                    return delEstCostObj
19474 manish.sha 746
                else:
747
                    continue
19535 manish.sha 748
            raise LogisticsServiceException(103, "Unable to get Provider for given pincode: " + str(pincode)+" Amount:- "+str(transactionAmount)+" Weight:- "+ str(weight)+".")
19474 manish.sha 749
    else:
750
        allEligibleProviders = []
751
        virtualDelayCostMap = {}
752
        virtualCommercialsCostMap = {} 
753
        for sla in allSla:
754
            if sla-allSla[0]<=1:
755
                consideredProviders = deliveryEstimate.get(sla)
756
                for providerId in consideredProviders:
757
                    if isCod and providerId in [7,46]:
758
                        virtualCommercialsCostMap[providerId] = 10
759
                    if providerId not in allEligibleProviders:
760
                        allEligibleProviders.append(providerId)
761
                    virtualDelayCostMap[providerId] = 0
762
            elif sla-allSla[0]==2:
763
                consideredProviders = deliveryEstimate.get(sla)
764
                for providerId in consideredProviders:
765
                    if isCod and providerId in [7,46]:
766
                        virtualCommercialsCostMap[providerId] = 10
767
                    if providerId not in allEligibleProviders:
768
                        allEligibleProviders.append(providerId)
769
                    virtualDelayCostMap[providerId] = 20+round((0.3*transactionAmount)/100,0)
770
            elif sla-allSla[0]==3:
771
                consideredProviders = deliveryEstimate.get(sla)
772
                for providerId in consideredProviders:
773
                    if isCod and providerId in [7,46]:
774
                        virtualCommercialsCostMap[providerId] = 10
775
                    if providerId not in allEligibleProviders:
776
                        allEligibleProviders.append(providerId)
777
                    virtualDelayCostMap[providerId] = 40+round((0.6*transactionAmount)/100,0)
778
 
779
        costingListOrder = []
780
        costingListMap = {}
781
        for providerId in allEligibleProviders:
782
            costingDetails = providerCostingMap.get(providerId)
783
            if costingDetails:
784
                cost = round(costingDetails[0],0)
785
                if virtualDelayCostMap.has_key(providerId):
786
                    cost = cost + virtualDelayCostMap.get(providerId)
787
                if virtualCommercialsCostMap.has_key(providerId):
788
                    cost = cost + virtualCommercialsCostMap.get(providerId)
789
                if costingListMap.has_key(cost):
790
                    providers = costingListMap.get(cost)
791
                    providers.append(providerId)                       
792
                    costingListMap[cost] = providers 
793
                else:
794
                    providers = []
795
                    providers.append(providerId)                       
796
                    costingListMap[cost] = providers  
797
                if cost not in costingListOrder:
798
                    costingListOrder.append(cost)
799
 
800
        costingListOrder = sorted(costingListOrder)
801
 
802
        print costingListMap
803
        eligibleProviders = costingListMap.get(costingListOrder[0])
804
        for providerId in eligibleProviders:
805
            if providerCostingMap.has_key(providerId):
806
                costingDetails = providerCostingMap.get(providerId)
19421 manish.sha 807
                delEstCostObj = DeliveryEstimateAndCosting()
19474 manish.sha 808
                delEstCostObj.logistics_provider_id = providerId
19421 manish.sha 809
                delEstCostObj.pincode = pincode
19474 manish.sha 810
                delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, providerId, warehouse_location][0]
811
                delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, providerId, warehouse_location][1]
812
                delEstCostObj.codAllowed = serviceability[providerId][2]
813
                delEstCostObj.otgAvailable = serviceability[providerId][3]
19421 manish.sha 814
                delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
815
                delEstCostObj.codCollectionCharges = costingDetails[1]
816
                return delEstCostObj
19474 manish.sha 817
            else:
818
                continue
19535 manish.sha 819
        raise LogisticsServiceException(103, "Unable to get Provider for given pincode: " + str(pincode)+" Amount:- "+str(transactionAmount)+" Weight:- "+ str(weight)+".")