Subversion Repositories SmartDukaan

Rev

Rev 35718 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35718 Rev 35722
Line 3... Line 3...
3
 
3
 
4
@author: rajveer
4
@author: rajveer
5
'''
5
'''
6
 
6
 
7
from collections import namedtuple
7
from collections import namedtuple
8
from elixir import session
8
from elixir import metadata, session
9
from shop2020.clients.CatalogClient import CatalogClient
9
from shop2020.clients.CatalogClient import CatalogClient
10
from shop2020.clients.InventoryClient import InventoryClient
10
from shop2020.clients.InventoryClient import InventoryClient
11
from shop2020.clients.TransactionClient import TransactionClient
11
from shop2020.clients.TransactionClient import TransactionClient
12
from shop2020.logistics.service.impl import BluedartService, DataService, \
12
from shop2020.logistics.service.impl import BluedartService, DataService, \
13
    EcomExpressService
13
    EcomExpressService
Line 100... Line 100...
100
    inventory_client = InventoryClient().get_client()
100
    inventory_client = InventoryClient().get_client()
101
    return inventory_client.getStateMaster()
101
    return inventory_client.getStateMaster()
102
 
102
 
103
 
103
 
104
def __cache_locations():
104
def __cache_locations():
105
    locations = Locations.query.all()
105
    rows = metadata.bind.execute("SELECT id, state_id FROM locations")
106
    for location in locations:
106
    for row in rows:
107
        location_state[location.id] = location.state_id
107
        location_state[row[0]] = row[1]
108
        if not state_locations.has_key(location.state_id):
108
        if not state_locations.has_key(row[1]):
109
            state_locations[location.state_id] = []
109
            state_locations[row[1]] = []
110
        state_locations[location.state_id] = state_locations[location.state_id].append(location.state_id)
110
        state_locations[row[1]] = state_locations[row[1]].append(row[1])
111
 
111
 
112
def __cache_pincode_estimates():
112
def __cache_pincode_estimates():
113
    delivery_estimates = DeliveryEstimate.query.all()
113
    rows = metadata.bind.execute("SELECT destination_pin, warehouse_location, provider_id, delivery_time, delivery_delay FROM deliveryestimate")
-
 
114
    for row in rows:
114
    for delivery_estimate in delivery_estimates:
115
        dest_pin, wh_loc, provider_id, delivery_time, delivery_delay = row
115
        if not pincode_locations.has_key(delivery_estimate.destination_pin):
116
        if not pincode_locations.has_key(dest_pin):
116
            pincode_locations[delivery_estimate.destination_pin] = {}
117
            pincode_locations[dest_pin] = {}
117
        destination_pinMap = pincode_locations[delivery_estimate.destination_pin] 
118
        destination_pinMap = pincode_locations[dest_pin]
118
        if not destination_pinMap.has_key(delivery_estimate.warehouse_location):
119
        if not destination_pinMap.has_key(wh_loc):
119
            destination_pinMap[delivery_estimate.warehouse_location] = {}
120
            destination_pinMap[wh_loc] = {}
120
            state_id = location_state.get(delivery_estimate.warehouse_location)
121
            state_id = location_state.get(wh_loc)
121
            sameState = __getStateFromPin(delivery_estimate.destination_pin) == state_id
122
            sameState = __getStateFromPin(dest_pin) == state_id
122
            destination_pinMap[delivery_estimate.warehouse_location]['sameState']=sameState
123
            destination_pinMap[wh_loc]['sameState']=sameState
123
            destination_pinMap[delivery_estimate.warehouse_location]['providerInfo'] = {} 
124
            destination_pinMap[wh_loc]['providerInfo'] = {}
124
        destination_pinMap[delivery_estimate.warehouse_location]['providerInfo'][delivery_estimate.provider_id] = delivery_estimate.delivery_time + delivery_estimate.delivery_delay
125
        destination_pinMap[wh_loc]['providerInfo'][provider_id] = delivery_time + delivery_delay
125
        
126
        
126
 
127
 
127
    
128
    
128
def __cache_pincode_provider_serviceability():
129
def __cache_pincode_provider_serviceability():
129
    pincode_providers = ServiceableLocationDetails.query.filter(ServiceableLocationDetails.exp==1)
130
    rows = metadata.bind.execute("SELECT dest_pincode, provider_id, cod, otgAvailable, providerCodLimit, websiteCodLimit, storeCodLimit, providerPrepaidLimit FROM serviceablelocationdetails WHERE exp=1")
130
    for pp in pincode_providers:
131
    for row in rows:
131
        serviceable_map[PincodeProvider(pp.dest_pincode, pp.provider_id)] = (pp.cod, pp.otgAvailable,pp.providerCodLimit, pp.websiteCodLimit, pp.storeCodLimit, pp.providerPrepaidLimit)
132
        serviceable_map[PincodeProvider(row[0], row[1])] = (row[2], row[3], row[4], row[5], row[6], row[7])
132
        
133
        
133
 
134
 
134
def __cache_delivery_estimate_table():
135
def __cache_delivery_estimate_table():
135
    delivery_estimates = DeliveryEstimate.query.all()
136
    rows = metadata.bind.execute("SELECT destination_pin, provider_id, warehouse_location, delivery_time, delivery_delay, providerZoneCode FROM deliveryestimate")
136
    for delivery_estimate in delivery_estimates:
137
    for row in rows:
137
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
-
 
138
        =delivery_estimate.delivery_time, delivery_estimate.delivery_delay, delivery_estimate.providerZoneCode
138
        delivery_estimate_cache[row[0], row[1], row[2]] = row[3], row[4], row[5]
139
 
139
 
140
def __cache_serviceable_location_details_table():
140
def __cache_serviceable_location_details_table():
141
    serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
141
    rows = metadata.bind.execute("SELECT provider_id, dest_pincode, dest_code, exp, cod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit FROM serviceablelocationdetails WHERE exp!=0 OR cod!=0")
142
    for serviceable_location in serviceable_locations:
142
    for row in rows:
-
 
143
        provider_id, dest_pincode, dest_code, exp, cod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit = row
143
        #Bluedart is temporarily not serviceable
144
        #Bluedart is temporarily not serviceable
144
        if serviceable_location.provider_id==1:
145
        if provider_id==1:
145
            continue
146
            continue
146
        try:
147
        try:
147
            provider_pincodes = serviceable_location_cache[serviceable_location.provider_id]
148
            provider_pincodes = serviceable_location_cache[provider_id]
148
        except:
149
        except:
149
            provider_pincodes = {}
150
            provider_pincodes = {}
150
            serviceable_location_cache[serviceable_location.provider_id] = provider_pincodes 
151
            serviceable_location_cache[provider_id] = provider_pincodes
151
        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
152
        provider_pincodes[dest_pincode] = dest_code, exp, cod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit, providerCodLimit
152
 
153
 
153
def __cache_warehouse_allocation_table():
154
def __cache_warehouse_allocation_table():
154
    warehouse_allocations = WarehouseAllocation.query.all()
155
    warehouse_allocations = WarehouseAllocation.query.all()
155
    for warehouse_allocation in warehouse_allocations:
156
    for warehouse_allocation in warehouse_allocations:
156
        warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
157
        warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location