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,\
723 chandransh 17
    get_category_object, mark_item_as_content_complete
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
 
723 chandransh 229
    def markItemAsContentComplete(self, entityId):
230
        """
231
        Parameters:
232
         - entityId
233
        """
234
        return mark_item_as_content_complete(entityId)
235
 
122 ashish 236
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
237
        """
238
        Parameters:
239
         - id
240
         - item_id
241
         - warehouse_id
242
         - from_date
243
         - to_date
244
        """
245
        pass
246
 
247
    def getAllWarehouses(self, isActive):
248
        """
249
        Parameters:
250
        - isActive
251
        """
252
        if isActive:
253
            warehouses = get_all_warehouses_by_status(status.ACTIVE)
254
 
255
        else:
256
            warehouses = get_all_warehouses_by_status(None)
257
 
258
        ret_warehouses = []
259
 
260
        for warehouse in warehouses:
261
            ret_warehouses.append(to_t_warehouse(warehouse))
262
        return ret_warehouses
263
 
264
    def getWarehouse(self, warehouse_id):
265
        """
266
        Parameters:
267
         - warehouse_id
268
        """
269
        log_entry(self, "get warehouse call")
270
        warehouse = get_Warehouse(warehouse_id)
271
        if warehouse:
272
            return to_t_warehouse(warehouse)
273
        else:
274
            raise InventoryServiceException(101, "no such warehouse")
275
 
276
    def getAllWarehousesForItem(self, item_id):
277
        """
278
        Parameters:
279
         - item_id
280
        """
281
        log_entry(self, "getting all warehouses for item")
282
        all_warehouses = get_all_warehouses_for_item(item_id)
283
        t_warehouses = []
284
        for warehouse in all_warehouses:
285
            t_warehouses.append(to_t_warehouse(warehouse))
286
        return t_warehouses
287
 
288
    def getAllItemsForWarehouse(self, warehouse_id):
289
        """
290
        Parameters:
291
         - warehouse_id
292
        """
293
        log_entry(self, "getting all items for warehouse")
294
        all_items = get_all_items_for_warehouse(warehouse_id)
295
        t_items = []
296
        for item in all_items:
297
            t_items.append(to_t_item(item))
298
        return t_items
598 chandransh 299
 
122 ashish 300
    def updateItem(self, item):
301
        """
302
        Parameters:
303
         - item
304
        """
305
        log_entry(self, "addItem called")
306
        return update_item(item)
307
 
626 chandransh 308
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
621 chandransh 309
        if total_items is None:
310
            total_items = self.best_sellers_limit
311
        stop_index = start_index + total_items
312
        return get_best_sellers(start_index, stop_index, category)
548 rajveer 313
 
626 chandransh 314
    def getBestSellersCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 315
        """
316
        Parameters:
317
         - beginIndex
318
         - totalItems
319
        """
621 chandransh 320
        if total_items is None:
321
            total_items = self.best_sellers_limit
322
        stop_index = start_index + total_items
323
        return get_best_sellers_catalog_ids(start_index, stop_index,category)
548 rajveer 324
 
591 chandransh 325
    def getBestSellersCount(self, ):
621 chandransh 326
        return get_best_sellers_count(None)
548 rajveer 327
 
591 chandransh 328
    def getBestDeals(self,):
609 chandransh 329
        return get_best_deals()
591 chandransh 330
 
626 chandransh 331
    def getBestDealsCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 332
        """
333
        Parameters:
334
         - beginIndex
335
         - totalItems
336
        """
621 chandransh 337
        stop_index = start_index + total_items
626 chandransh 338
        return get_best_deals_catalog_ids(start_index, stop_index, category)
548 rajveer 339
 
591 chandransh 340
    def getBestDealsCount(self, ):
609 chandransh 341
        return get_best_deals_count()
548 rajveer 342
 
591 chandransh 343
    def getLatestArrivals(self,):
602 chandransh 344
        return get_latest_arrivals(self.latest_arrivals_limit)
591 chandransh 345
 
626 chandransh 346
    def getLatestArrivalsCatalogIds(self, start_index, total_items, category=-1):
548 rajveer 347
        """
348
        Parameters:
349
         - beginIndex
350
         - totalItems
351
        """
609 chandransh 352
        if start_index > self.latest_arrivals_limit:
353
            return []
621 chandransh 354
        stop_index = start_index + total_items
355
        if stop_index > self.latest_arrivals_limit:
356
            stop_index = self.latest_arrivals_limit
357
        return get_latest_arrivals_catalog_ids(start_index, stop_index, category)
548 rajveer 358
 
591 chandransh 359
    def getLatestArrivalsCount(self, ):
602 chandransh 360
        return get_latest_arrivals_count(self.latest_arrivals_limit)
591 chandransh 361
 
635 rajveer 362
 
363
    def putCategoryObject(self, object):
364
        """
365
        Parameters:
366
         - object
367
        """
368
        return put_category_object(object)
369
 
370
    def getCategoryObject(self, ):
371
        return get_category_object()