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