Subversion Repositories SmartDukaan

Rev

Rev 3217 | Rev 3355 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3217 Rev 3218
Line 14... Line 14...
14
from shop2020.clients.CatalogClient import CatalogClient
14
from shop2020.clients.CatalogClient import CatalogClient
15
from shop2020.config.client.ConfigClient import ConfigClient
15
from shop2020.config.client.ConfigClient import ConfigClient
16
import datetime
16
import datetime
17
import math
17
import math
18
import sys
18
import sys
19
from shop2020.logistics.service.impl.DataService import ServiceableLocationDetails,\
-
 
20
    PublicHolidays
-
 
21
from shop2020.logistics.service.impl import DataAccessor
19
from shop2020.logistics.service.impl import DataAccessor
22
 
20
 
23
class LogisticsServiceHandler:
21
class LogisticsServiceHandler:
24
    
22
    
25
    def __init__(self, dbname='logistics', db_hostname='localhost'):
23
    def __init__(self, dbname='logistics', db_hostname='localhost'):
Line 132... Line 130...
132
            client = CatalogClient().get_client()
130
            client = CatalogClient().get_client()
133
            item = client.getItem(itemId)
131
            item = client.getItem(itemId)
134
        except Exception as ex:
132
        except Exception as ex:
135
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
133
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
136
 
134
 
137
        delivery_time, reliability, provider_id, warehouse_location  = get_logistics_estimation(destination_pin, item.sellingPrice, None, type)
135
        delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice, None, type)
138
        if delivery_time is None:
136
        if delivery_estimate is None:
139
            raise LogisticsServiceException(104, "Unable to fetch delivery estimate for this pincode.")
137
            raise LogisticsServiceException(104, "Unable to fetch delivery estimate for this pincode.")
140
        
138
        
141
        warehouse_loc = warehouse_location
139
        warehouse_loc = delivery_estimate.warehouse_location
142
        try:
140
        try:
143
            #Get the id and location of actual warehouse that'll be used to fulfill this order.
141
            #Get the id and location of actual warehouse that'll be used to fulfill this order.
144
            warehouse_loc, warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
142
            warehouse_loc, warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
145
        except Exception as ex:
143
        except Exception as ex:
146
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
144
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.")
147
        
145
        
148
        # We are revising the estimated based on the actual warehouse that will be assigned to this order.
146
        # We are revising the estimated based on the actual warehouse that will be assigned to this order.
149
        # 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 different zone that the one we allocated for this pincode.
150
        delivery_time, reliability, provider_id, warehouse_location = get_logistics_estimation(destination_pin, item.sellingPrice, warehouse_loc, type)
148
        delivery_estimate = get_logistics_estimation(destination_pin, item.sellingPrice, warehouse_loc, type)
151
        if delivery_time is None:
149
        if delivery_estimate is None:
152
            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))
153
        
151
        
154
        delivery_time = 24*delivery_time
152
        delivery_time = 24*delivery_estimate.delivery_time
155
        
153
        
156
        # Increase the estimate if the actual stock is less than the threshold 
154
        # Increase the estimate if the actual stock is less than the threshold 
157
        if items_in_inventory < self.stock_threshold :
155
        if items_in_inventory < self.stock_threshold :
158
            delivery_time = delivery_time + self.time_to_procure
156
            delivery_time = delivery_time + self.time_to_procure
159
        
157
        
Line 176... Line 174...
176
        ## FIXME Remove the above code once Kanwaar season is over
174
        ## FIXME Remove the above code once Kanwaar season is over
177
        '''
175
        '''
178
        
176
        
179
        logistics_info = LogisticsInfo()
177
        logistics_info = LogisticsInfo()
180
        logistics_info.deliveryTime = delivery_time
178
        logistics_info.deliveryTime = delivery_time
181
        logistics_info.providerId = provider_id
179
        logistics_info.providerId = delivery_estimate.provider_id
182
        logistics_info.warehouseId = warehouse_id
180
        logistics_info.warehouseId = warehouse_id
183
        
181
        
184
        return logistics_info
182
        return logistics_info
185
        
183
        
186
    def getDestinationCode(self, providerId, pinCode):
184
    def getDestinationCode(self, providerId, pinCode):
Line 192... Line 190...
192
         - providerId
190
         - providerId
193
         - pinCode
191
         - pinCode
194
        """
192
        """
195
        try:
193
        try:
196
            try:
194
            try:
197
                dest_code, exp, cod, station_type = DataAccessor.sl_cache[providerId][pinCode]
195
                dest_code = DataAccessor.serviceable_location_cache[providerId][pinCode][0]
198
                return dest_code
196
                return dest_code
199
            except:
197
            except:
200
                raise LogisticsServiceException(101, "The pincode " + pinCode + " is not serviced by this provider: " + str(providerId))
198
                raise LogisticsServiceException(101, "The pincode " + pinCode + " is not serviced by this provider: " + str(providerId))
201
        finally:
199
        finally:
202
            close_session()
200
            close_session()