| Line 2... |
Line 2... |
| 2 |
Created on 13-Sep-2010
|
2 |
Created on 13-Sep-2010
|
| 3 |
|
3 |
|
| 4 |
@author: rajveer
|
4 |
@author: rajveer
|
| 5 |
'''
|
5 |
'''
|
| 6 |
|
6 |
|
| - |
|
7 |
from elixir import session
|
| - |
|
8 |
from shop2020.clients.CatalogClient import CatalogClient
|
| - |
|
9 |
from shop2020.clients.InventoryClient import InventoryClient
|
| 7 |
from shop2020.logistics.service.impl import DataService
|
10 |
from shop2020.logistics.service.impl import DataService
|
| 8 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
11 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
| 9 |
DeliveryEstimate, WarehouseAllocation, \
|
12 |
DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
|
| 10 |
PublicHolidays, ServiceableLocationDetails, PickupStore
|
13 |
ServiceableLocationDetails, PickupStore
|
| 11 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException,\
|
14 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
| 12 |
DeliveryType, LogisticsLocationInfo
|
15 |
DeliveryType, LogisticsLocationInfo
|
| - |
|
16 |
from shop2020.thriftpy.model.v1.inventory.ttypes import Warehouse, BillingType,\
|
| - |
|
17 |
WarehouseType
|
| 13 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
18 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
| 14 |
from sqlalchemy.sql import or_
|
19 |
from sqlalchemy.sql import or_
|
| 15 |
from elixir import session
|
- |
|
| 16 |
import datetime, time
|
20 |
import datetime
|
| 17 |
import sys
|
- |
|
| 18 |
import logging
|
21 |
import logging
|
| 19 |
import os
|
22 |
import os
|
| - |
|
23 |
import sys
|
| 20 |
from shop2020.clients.CatalogClient import CatalogClient
|
24 |
import time
|
| 21 |
logging.basicConfig(level=logging.DEBUG)
|
25 |
logging.basicConfig(level=logging.DEBUG)
|
| 22 |
|
26 |
|
| 23 |
warehouse_allocation_cache = {}
|
27 |
warehouse_allocation_cache = {}
|
| 24 |
serviceable_location_cache = {}
|
28 |
serviceable_location_cache = {}
|
| 25 |
delivery_estimate_cache = {}
|
29 |
delivery_estimate_cache = {}
|
| - |
|
30 |
warehouse_location_cache = {}
|
| 26 |
|
31 |
|
| 27 |
'''
|
32 |
'''
|
| 28 |
This class is for only data transfer. Never used outside this module.
|
33 |
This class is for only data transfer. Never used outside this module.
|
| 29 |
'''
|
34 |
'''
|
| 30 |
class _DeliveryEstimateObject:
|
35 |
class _DeliveryEstimateObject:
|
| Line 37... |
Line 42... |
| 37 |
|
42 |
|
| 38 |
def initialize(dbname="logistics", db_hostname="localhost"):
|
43 |
def initialize(dbname="logistics", db_hostname="localhost"):
|
| 39 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
44 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 40 |
DataService.initialize(dbname, db_hostname)
|
45 |
DataService.initialize(dbname, db_hostname)
|
| 41 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
46 |
print "Starting cache population at: " + str(datetime.datetime.now())
|
| 42 |
__cache_warehouse_allocation_table()
|
47 |
#__cache_warehouse_allocation_table()
|
| - |
|
48 |
__cache_warehouse_locations()
|
| 43 |
__cache_serviceable_location_details_table()
|
49 |
__cache_serviceable_location_details_table()
|
| 44 |
__cache_delivery_estimate_table()
|
50 |
__cache_delivery_estimate_table()
|
| 45 |
close_session()
|
51 |
close_session()
|
| 46 |
print "Done cache population at: " + str(datetime.datetime.now())
|
52 |
print "Done cache population at: " + str(datetime.datetime.now())
|
| 47 |
|
53 |
|
| Line 64... |
Line 70... |
| 64 |
def __cache_warehouse_allocation_table():
|
70 |
def __cache_warehouse_allocation_table():
|
| 65 |
warehouse_allocations = WarehouseAllocation.query.all()
|
71 |
warehouse_allocations = WarehouseAllocation.query.all()
|
| 66 |
for warehouse_allocation in warehouse_allocations:
|
72 |
for warehouse_allocation in warehouse_allocations:
|
| 67 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
73 |
warehouse_allocation_cache[warehouse_allocation.pincode]=warehouse_allocation.primary_warehouse_location
|
| 68 |
|
74 |
|
| - |
|
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 |
|
| 69 |
def get_provider(provider_id):
|
83 |
def get_provider(provider_id):
|
| 70 |
provider = Provider.get_by(id=provider_id)
|
84 |
provider = Provider.get_by(id=provider_id)
|
| 71 |
return provider
|
85 |
return provider
|
| 72 |
|
86 |
|
| 73 |
def get_providers():
|
87 |
def get_providers():
|
| Line 80... |
Line 94... |
| 80 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
|
94 |
provider_id, codAllowed, otgAvailable = __get_logistics_provider_for_destination_pincode(destination_pin, item_selling_price, weight, type, billingWarehouseId)
|
| 81 |
|
95 |
|
| 82 |
if item_selling_price > 60000 or item_selling_price <= 250:
|
96 |
if item_selling_price > 60000 or item_selling_price <= 250:
|
| 83 |
codAllowed = False
|
97 |
codAllowed = False
|
| 84 |
|
98 |
|
| 85 |
warehouse_location = 0
|
99 |
warehouse_location = warehouse_location_cache.get(billingWarehouseId)
|
| 86 |
if billingWarehouseId in [12,13]:
|
100 |
if warehouse_location is None:
|
| 87 |
warehouse_location = 1
|
101 |
warehouse_location = 0
|
| 88 |
|
102 |
|
| 89 |
if not provider_id:
|
103 |
if not provider_id:
|
| 90 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
104 |
raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
|
| 91 |
try:
|
105 |
try:
|
| - |
|
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]))
|
| 92 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
|
108 |
delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
|
| 93 |
delivery_delay = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
|
109 |
delivery_delay = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
|
| 94 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
|
110 |
delivery_estimate = _DeliveryEstimateObject(delivery_time, delivery_delay, provider_id, codAllowed, otgAvailable)
|
| 95 |
return delivery_estimate
|
111 |
return delivery_estimate
|
| 96 |
except Exception as ex:
|
112 |
except Exception as ex:
|