Subversion Repositories SmartDukaan

Rev

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

Rev 4870 Rev 4934
Line 15... Line 15...
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 import DataAccessor
19
from shop2020.logistics.service.impl import DataAccessor
-
 
20
from shop2020.thriftpy.model.v1.catalog.ttypes import status
20
 
21
 
21
class LogisticsServiceHandler:
22
class LogisticsServiceHandler:
22
    
23
    
23
    def __init__(self, dbname='logistics', db_hostname='localhost'):
24
    def __init__(self, dbname='logistics', db_hostname='localhost'):
24
        initialize(dbname, db_hostname)
25
        initialize(dbname, db_hostname)
Line 238... Line 239...
238
        """
239
        """
239
        try:
240
        try:
240
            return is_alive()
241
            return is_alive()
241
        finally:
242
        finally:
242
            close_session()
243
            close_session()
-
 
244
    
-
 
245
    def getEntityLogisticsEstimation(self, catalogItemId, destination_pin, type):
-
 
246
        """
-
 
247
        Returns a LogisticsInfo structure w/o an airway bill number. Use this method during the estimation phase.
-
 
248
        Raises an exception if this pincode is not allocated to any warehouse zone or provider. Also, if the pincode
-
 
249
        is allocated to a warehouse zone but there are no actual warehouses in that zone, an exception is raised.
-
 
250
    
-
 
251
        Parameters:
-
 
252
         - catalogItemId
-
 
253
         - destination_pin
-
 
254
         - type
-
 
255
        """
-
 
256
        try:
-
 
257
            return self.get_entity_logistics_estimation_with_type(catalogItemId, destination_pin, type)
-
 
258
        finally:
-
 
259
            close_session()
-
 
260
 
-
 
261
    def get_entity_logistics_estimation_with_type(self, catalog_item_id, destination_pin, type):
-
 
262
        try:
-
 
263
            client = CatalogClient().get_client()
-
 
264
            items = client.getValidItemsByCatalogId(catalog_item_id)
-
 
265
        except Exception as ex:
-
 
266
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this entity.")
-
 
267
        
-
 
268
        estimateList = []
-
 
269
 
-
 
270
        for item in items:
-
 
271
            estimationInfo = self.get_logistics_estimation_with_type(item.id, destination_pin, type)
-
 
272
            if item.itemStatus == status.ACTIVE:
-
 
273
                estimateList.append((0, estimationInfo.deliveryTime, item.id))
-
 
274
            elif item.itemStatus == status.PAUSED:
-
 
275
                estimateList.append((1, estimationInfo.deliveryTime, item.id))
-
 
276
            elif item.itemStatus == status.PAUSED_BY_RISK:
-
 
277
                estimateList.append((2, estimationInfo.deliveryTime, item.id))
-
 
278
 
-
 
279
        estimateList.sort()
-
 
280
        
-
 
281
        return [estimate[-1] for estimate in estimateList]
243
282