Subversion Repositories SmartDukaan

Rev

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

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