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