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