Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
122 ashish 1
'''
2
Created on 27-Apr-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.model.v1.catalog.impl import DataService
7
from shop2020.utils.Utils import log_entry
8
from shop2020.model.v1.catalog.impl.DataAcessors import add_item, add_warehouse,\
9
    update_inventory, retire_warehouse, retire_item, change_item_status,\
635 rajveer 10
    get_item, get_all_items, get_all_items_by_status, get_item_inventoy,\
643 chandransh 11
    get_item_availability_for_warehouse, get_item_availability_for_location, get_all_warehouses_by_status,\
122 ashish 12
    get_Warehouse, get_all_warehouses_for_item, get_all_items_for_warehouse,\
609 chandransh 13
    update_item, start_item_on,\
635 rajveer 14
    retire_item_on, get_item_inventory_by_item_id, get_items_by_catalog_id,\
609 chandransh 15
    get_item_by_vendor_id, get_best_deals, get_best_deals_catalog_ids, get_best_deals_count, get_best_sellers, get_latest_arrivals, get_latest_arrivals_catalog_ids, get_latest_arrivals_count,\
635 rajveer 16
    is_active, get_best_sellers_catalog_ids, get_best_sellers_count, put_category_object,\
17
    get_category_object
122 ashish 18
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
19
    to_t_item_inventory, to_t_warehouse
20
from shop2020.thriftpy.model.v1.catalog.ttypes import status,\
21
    InventoryServiceException
599 chandransh 22
from shop2020.config.client.ConfigClient import ConfigClient
122 ashish 23
 
24
 
25
class InventoryServiceHandler:
26
    '''
27
    classdocs
28
    '''
599 chandransh 29
 
122 ashish 30
    def __init__(self):
31
        '''
32
        Constructor
33
        '''
34
        DataService.initialize()
599 chandransh 35
        try:
621 chandransh 36
            config_client = ConfigClient()
37
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
38
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
599 chandransh 39
        except:
621 chandransh 40
            self.latest_arrivals_limit = 50
41
            self.best_sellers_limit = 50
122 ashish 42
 
43
    #DONE
44
    def addItem(self, item):
45
        """
46
        Availability and inventory attributes
47
 
48
        Parameters:
49
         - item
50
        """
51
        log_entry(self, "addItem called")
52
        return add_item(item)
53
        pass
54
 
55
    def addWarehouse(self, warehouse):
56
        """
57
        Parameters:
58
         - warehouse
59
        """
60
        log_entry(self, "addWarehouse called")
61
        return add_warehouse(warehouse)
62
        pass
63
 
483 rajveer 64
 
65
    def updateInventory(self, warehouse_id, timestamp, availability):
122 ashish 66
        """
67
        Parameters:
68
         - warehouse_id
69
         - timestamp
483 rajveer 70
         - availability
122 ashish 71
        """
72
        log_entry(self, "update Inventory called")
483 rajveer 73
        return update_inventory(warehouse_id, timestamp, availability)
122 ashish 74
 
635 rajveer 75
    def isActive(self, item_id):
563 chandransh 76
        """
77
        Parameters:
635 rajveer 78
         - item_id
563 chandransh 79
        """
635 rajveer 80
        return is_active(item_id)
122 ashish 81
 
82
    def retireWarehouse(self, warehouse_id):
83
        """
84
        Parameters:
85
         - warehouse_id
86
        """
87
        log_entry(self, "retire warehouse called")
88
        return retire_warehouse(warehouse_id)
89
 
90
 
91
    def retireItem(self, item_id):
92
        """
93
        Parameters:
94
        - item_id
95
        """
96
        log_entry(self, "retire item called")
97
        return retire_item(item_id)
98
 
99
    def startItemOn(self, item_id, timestamp):
100
        """
101
        Parameters:
102
         - item_id
103
         - timestamp
104
        """
105
        start_item_on(item_id, timestamp)
106
 
107
    def retireItemOn(self, item_id, timestamp):
108
        """
109
        Parameters:
110
         - item_id
111
         - timestamp
112
        """
113
        retire_item_on(item_id, timestamp)
114
 
115
    def changeItemStatus(self, item_id, timestamp, newstatus):
116
        """
117
        Parameters:
118
         - item_id
119
         - timestamp
120
         - newstatus
121
        """
122
        log_entry(self, "change item status called")
123
        return change_item_status(item_id, newstatus)
124
 
125
 
126
    def getItem(self, item_id):
127
        """
128
        Parameters:
129
         - item_id
130
        """
131
        log_entry(self, "item requested")
635 rajveer 132
        return to_t_item( get_item(item_id))
379 ashish 133
 
635 rajveer 134
    def getItemsByCatalogId(self, catalog_item_id):
379 ashish 135
        """
136
        Parameters:
137
        - catalog_item_id
138
        """
386 ashish 139
        log_entry(self, "item requested")
635 rajveer 140
        return get_items_by_catalog_id(catalog_item_id)
122 ashish 141
 
483 rajveer 142
    def getItemByVendorId(self, vendor_item_id):
143
        """
144
        Parameters:
145
        - catalog_item_id
146
        """
147
        log_entry(self, "item requested")
148
        return to_t_item( get_item_by_vendor_id(vendor_item_id))
149
        pass
150
 
151
 
122 ashish 152
    def getAllItems(self, isActive):
153
        """
154
        Parameters:
155
         - isActive
156
        """
157
        log_entry(self, "all items requested")
158
 
159
        items = get_all_items(isActive)
160
        ret_items = []
161
        for item in items:
162
            if item:
163
                ret_items.append(to_t_item(item))
164
        return ret_items
165
 
166
    def getAllItemsByStatus(self, itemStatus):
167
        """
168
        Parameters:
169
         - itemStatus
170
        """
171
        log_entry(self, "all items requested")
172
 
173
        items = get_all_items_by_status(itemStatus)
174
        ret_items = []
175
        for item in items:
176
            if item:
177
                ret_items.append(to_t_item(item))
178
        return ret_items
179
 
180
    def getItemInventory(self, item_id):
181
        """
182
        Parameters:
183
        - item_id
184
        """
185
        log_entry(self, "item inventory requested")
186
        inventory = get_item_inventoy(item_id)
187
        return to_t_item_inventory(inventory, item_id)
188
 
635 rajveer 189
    def getItemInventoryByItemId(self, item_id):
190
        """
191
        Parameters:
192
         - item_id
193
        """
194
        log_entry(self, "item inventory requested")
195
        inventory = get_item_inventory_by_item_id(item_id)
196
        return to_t_item_inventory(inventory, item_id)
197
 
198
    '''
379 ashish 199
    def getItemInventoryByCatalogId(self, item_id):
200
        """
201
        Parameters:
202
         - item_id
203
        """
383 ashish 204
        log_entry(self, "item inventory requested")
205
        inventory = get_item_inventory_by_catalog_id(item_id)
206
        return to_t_item_inventory(inventory, item_id)
635 rajveer 207
    '''
208
 
379 ashish 209
 
643 chandransh 210
    def getItemAvailabilityAtLocation(self, warehouse_loc, item_id):
211
        """
212
        Returns the id of the warehouse with the largest inventory of the item and the inventory size. The size of list will always be 2.
213
 
214
        Parameters:
215
         - warehouse_loc
216
         - item_id
217
        """
218
        return get_item_availability_for_location(warehouse_loc, item_id)
379 ashish 219
 
122 ashish 220
    def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):
221
        """
222
        Parameters:
223
         - warehouse_id
224
         - item_id
225
        """
226
        log_entry(self, "item availability at warehouse requested")
227
        return get_item_availability_for_warehouse(warehouse_id, item_id)
228
 
229
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
230
        """
231
        Parameters:
232
         - id
233
         - item_id
234
         - warehouse_id
235
         - from_date
236
         - to_date
237
        """
238
        pass
239
 
240
    def getAllWarehouses(self, isActive):
241
        """
242
        Parameters:
243
        - isActive
244
        """
245
        if isActive:
246
            warehouses = get_all_warehouses_by_status(status.ACTIVE)
247
 
248
        else:
249
            warehouses = get_all_warehouses_by_status(None)
250
 
251
        ret_warehouses = []
252
 
253
        for warehouse in warehouses:
254
            ret_warehouses.append(to_t_warehouse(warehouse))
255
        return ret_warehouses
256
 
257
    def getWarehouse(self, warehouse_id):
258
        """
259
        Parameters:
260
         - warehouse_id
261
        """
262
        log_entry(self, "get warehouse call")
263
        warehouse = get_Warehouse(warehouse_id)
264
        if warehouse:
265
            return to_t_warehouse(warehouse)
266
        else:
267
            raise InventoryServiceException(101, "no such warehouse")
268
 
269
    def getAllWarehousesForItem(self, item_id):
270
        """
271
        Parameters:
272
         - item_id
273
        """
274
        log_entry(self, "getting all warehouses for item")
275
        all_warehouses = get_all_warehouses_for_item(item_id)
276
        t_warehouses = []
277
        for warehouse in all_warehouses:
278
            t_warehouses.append(to_t_warehouse(warehouse))
279
        return t_warehouses
280
 
281
    def getAllItemsForWarehouse(self, warehouse_id):
282
        """
283
        Parameters:
284
         - warehouse_id
285
        """
286
        log_entry(self, "getting all items for warehouse")
287
        all_items = get_all_items_for_warehouse(warehouse_id)
288
        t_items = []
289
        for item in all_items:
290
            t_items.append(to_t_item(item))
291
        return t_items
598 chandransh 292
 
122 ashish 293
    def updateItem(self, item):
294
        """
295
        Parameters:
296
         - item
297
        """
298
        log_entry(self, "addItem called")
299
        return update_item(item)
300
 
626 chandransh 301
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
621 chandransh 302
        if total_items is None:
303
            total_items = self.best_sellers_limit
304
        stop_index = start_index + total_items
305
        return get_best_sellers(start_index, stop_index, category)
548 rajveer 306
 
626 chandransh 307
    def getBestSellersCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 308
        """
309
        Parameters:
310
         - beginIndex
311
         - totalItems
312
        """
621 chandransh 313
        if total_items is None:
314
            total_items = self.best_sellers_limit
315
        stop_index = start_index + total_items
316
        return get_best_sellers_catalog_ids(start_index, stop_index,category)
548 rajveer 317
 
591 chandransh 318
    def getBestSellersCount(self, ):
621 chandransh 319
        return get_best_sellers_count(None)
548 rajveer 320
 
591 chandransh 321
    def getBestDeals(self,):
609 chandransh 322
        return get_best_deals()
591 chandransh 323
 
626 chandransh 324
    def getBestDealsCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 325
        """
326
        Parameters:
327
         - beginIndex
328
         - totalItems
329
        """
621 chandransh 330
        stop_index = start_index + total_items
626 chandransh 331
        return get_best_deals_catalog_ids(start_index, stop_index, category)
548 rajveer 332
 
591 chandransh 333
    def getBestDealsCount(self, ):
609 chandransh 334
        return get_best_deals_count()
548 rajveer 335
 
591 chandransh 336
    def getLatestArrivals(self,):
602 chandransh 337
        return get_latest_arrivals(self.latest_arrivals_limit)
591 chandransh 338
 
626 chandransh 339
    def getLatestArrivalsCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 340
        """
341
        Parameters:
342
         - beginIndex
343
         - totalItems
344
        """
609 chandransh 345
        if start_index > self.latest_arrivals_limit:
346
            return []
621 chandransh 347
        stop_index = start_index + total_items
348
        if stop_index > self.latest_arrivals_limit:
349
            stop_index = self.latest_arrivals_limit
350
        return get_latest_arrivals_catalog_ids(start_index, stop_index, category)
548 rajveer 351
 
591 chandransh 352
    def getLatestArrivalsCount(self, ):
602 chandransh 353
        return get_latest_arrivals_count(self.latest_arrivals_limit)
591 chandransh 354
 
635 rajveer 355
 
356
    def putCategoryObject(self, object):
357
        """
358
        Parameters:
359
         - object
360
        """
361
        return put_category_object(object)
362
 
363
    def getCategoryObject(self, ):
364
        return get_category_object()