Subversion Repositories SmartDukaan

Rev

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

Rev 776 Rev 796
Line 37... Line 37...
37
        Returns a provider for a given provider ID. Throws an exception if none found.
37
        Returns a provider for a given provider ID. Throws an exception if none found.
38
        
38
        
39
        Parameters:
39
        Parameters:
40
         - providerId
40
         - providerId
41
        """
41
        """
-
 
42
        try:
42
        return to_t_provider(get_provider(providerId))
43
            return to_t_provider(get_provider(providerId))
-
 
44
        finally:
-
 
45
            close_session()
43
 
46
            
44
    def getAllProviders(self, ):
47
    def getAllProviders(self, ):
45
        """
48
        """
46
        Returns a list containing all the providers.
49
        Returns a list containing all the providers.
47
        """
50
        """
-
 
51
        try:
48
        return [to_t_provider(provider) for provider in get_providers()]
52
            return [to_t_provider(provider) for provider in get_providers()]
-
 
53
        finally:
-
 
54
            close_session()
49
 
55
            
50
    def getLogisticsInfo(self, destination_pincode, itemId):
56
    def getLogisticsInfo(self, destination_pincode, itemId):
51
        """
57
        """
52
        Parameters:
58
        Parameters:
53
         - destination_pincode
59
         - destination_pincode
54
         - item_id
60
         - item_id
55
        """
61
        """
-
 
62
        try:
56
        logistics_info = self.getLogisticsEstimation(itemId, destination_pincode)
63
            logistics_info = self.getLogisticsEstimation(itemId, destination_pincode)
57
        logistics_info.airway_billno = get_empty_AWB(logistics_info.providerId)
64
            logistics_info.airway_billno = get_empty_AWB(logistics_info.providerId)
58
        return logistics_info
65
            return logistics_info
-
 
66
        finally:
-
 
67
            close_session()
59
 
68
            
60
    def getEmptyAWB(self, provider_id):
69
    def getEmptyAWB(self, provider_id):
61
        """
70
        """
62
        Parameters:
71
        Parameters:
63
         - provider_id
72
         - provider_id
64
        """
73
        """
-
 
74
        try:
65
        return get_empty_AWB(provider_id)
75
            return get_empty_AWB(provider_id)
-
 
76
        finally:
-
 
77
            close_session()
66
 
78
            
67
    def getShipmentInfo(self, awb, providerId):
79
    def getShipmentInfo(self, awb, providerId):
68
        """
80
        """
69
        Parameters:
81
        Parameters:
70
         - awb
82
         - awb
71
         - providerId
83
         - providerId
72
        """
84
        """
-
 
85
        try:
73
        awb_updates = get_shipment_info(awb, providerId)
86
            awb_updates = get_shipment_info(awb, providerId)
74
        t_updates = []
87
            t_updates = []
75
        for update in awb_updates:
88
            for update in awb_updates:
76
            t_updates.append(to_t_awbupdate(update))
89
                t_updates.append(to_t_awbupdate(update))
77
        return t_updates
90
            return t_updates
-
 
91
        finally:
-
 
92
            close_session()
78
 
93
            
79
    def getLogisticsEstimation(self, itemId, destination_pin):
94
    def getLogisticsEstimation(self, itemId, destination_pin):
80
        """
95
        """
81
        Parameters:
96
        Parameters:
82
         - itemId
97
         - itemId
83
         - destination_pin
98
         - destination_pin
84
        """
99
        """
-
 
100
        try:
85
        if not destination_pin:
101
            if not destination_pin:
86
            destination_pin = self.default_pincode
102
                destination_pin = self.default_pincode
87
        delivery_estimate = get_logistics_estimation(destination_pin)
103
            delivery_estimate = get_logistics_estimation(destination_pin)
88
        if delivery_estimate is None:
104
            if delivery_estimate is None:
89
            raise LogisticsServiceException(103, "Unable to fetch delivery estimate for this pincode.")
105
                raise LogisticsServiceException(103, "Unable to fetch delivery estimate for this pincode.")
90
        delivery_time = 24*delivery_estimate.delivery_time
106
            delivery_time = 24*delivery_estimate.delivery_time
91
        if self.cutoff_time <= datetime.datetime.now().hour:
107
            if self.cutoff_time <= datetime.datetime.now().hour:
92
            delivery_time = delivery_time + 24
108
                delivery_time = delivery_time + 24
93
        warehouse_loc = delivery_estimate.warehouse_location
109
            warehouse_loc = delivery_estimate.warehouse_location
94
        try:
110
            try:
95
            client = InventoryClient().get_client()
111
                client = InventoryClient().get_client()
96
            warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
112
                warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(warehouse_loc, itemId)
97
        except:
113
            except:
98
            raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.") 
114
                raise LogisticsServiceException(103, "Unable to fetch inventory information about this item.") 
99
        if items_in_inventory < self.stock_threshold :
115
            if items_in_inventory < self.stock_threshold :
100
            delivery_time = delivery_time + self.time_to_producre
116
                delivery_time = delivery_time + self.time_to_producre
101
        delivery_time = int(math.ceil(delivery_time/24.0))
117
            delivery_time = int(math.ceil(delivery_time/24.0))
102
        
118
            
103
        logistics_info = LogisticsInfo()
119
            logistics_info = LogisticsInfo()
104
        logistics_info.deliveryTime = delivery_time
120
            logistics_info.deliveryTime = delivery_time
105
        logistics_info.providerId = delivery_estimate.provider_id
121
            logistics_info.providerId = delivery_estimate.provider_id
106
        logistics_info.warehouseId = warehouse_id
122
            logistics_info.warehouseId = warehouse_id
107
        
123
            
108
        return logistics_info
124
            return logistics_info
109
    
125
        finally:
-
 
126
            close_session()
-
 
127
                    
110
    def getDestinationCode(self, providerId, pinCode):
128
    def getDestinationCode(self, providerId, pinCode):
111
        """
129
        """
112
        Returns the short three letter code of a pincode for the given provider.
130
        Returns the short three letter code of a pincode for the given provider.
113
        Raises an exception if the pin code is not serviced by the given provider.
131
        Raises an exception if the pin code is not serviced by the given provider.
114
        
132
        
115
        Parameters:
133
        Parameters:
116
         - providerId
134
         - providerId
117
         - pinCode
135
         - pinCode
118
        """
136
        """
-
 
137
        try:
119
        sld = ServiceableLocationDetails.get_by(provider_id = providerId, dest_pincode = pinCode)
138
            sld = ServiceableLocationDetails.get_by(provider_id = providerId, dest_pincode = pinCode)
120
        if sld != None:
139
            if sld != None:
121
            return sld.dest_code
140
                return sld.dest_code
122
        else:
141
            else:
123
            raise LogisticsServiceException(101, "The pincode " + pinCode + " is not serviced by this provider: " + str(providerId))
142
                raise LogisticsServiceException(101, "The pincode " + pinCode + " is not serviced by this provider: " + str(providerId))
-
 
143
        finally:
-
 
144
            close_session()
124
     
145
        
125
    def closeSession(self, ):
146
    def closeSession(self, ):
126
        close_session()
147
        close_session()