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,\
766 rajveer 13
    update_item, start_item_on, close_session, \
635 rajveer 14
    retire_item_on, get_item_inventory_by_item_id, get_items_by_catalog_id,\
1308 chandransh 15
    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,\
871 chandransh 17
    get_category_object, mark_item_as_content_complete,\
1341 chandransh 18
    reserve_item_in_warehouse, reduce_reservation_count, generate_new_entity_id,\
2116 ankur.sing 19
    get_all_item_pricing, add_vendor_pricing, \
2035 rajveer 20
    get_item_pricing, get_category, get_all_categories, add_category,\
2116 ankur.sing 21
    get_item_status_description, get_all_vendors, check_vendor_item_mapping,\
2286 ankur.sing 22
    get_item_mappings, add_vendor_item_mapping, check_similar_item,\
2809 rajveer 23
    change_risky_flag, get_items_by_vendor_category, get_risky_items,\
3086 rajveer 24
    get_similar_items_catalog_ids, add_product_notification,\
3348 varun.gupt 25
    send_product_notifications, update_inventory_history,\
3557 rajveer 26
    get_all_brands_by_category, is_alive, get_item_pricing_by_source,\
27
    add_source_item_pricing, get_all_sources, get_item_for_source,\
3849 chandransh 28
    get_all_source_pricing, get_item_count_by_status
122 ashish 29
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
2065 ankur.sing 30
    to_t_item_inventory, to_t_warehouse, to_t_vendor_item_pricing, to_t_category,\
3557 rajveer 31
    to_t_vendor, to_t_vendor_item_mapping, to_t_source_item_pricing
122 ashish 32
from shop2020.thriftpy.model.v1.catalog.ttypes import status,\
33
    InventoryServiceException
599 chandransh 34
from shop2020.config.client.ConfigClient import ConfigClient
122 ashish 35
 
36
 
37
class InventoryServiceHandler:
38
    '''
39
    classdocs
40
    '''
599 chandransh 41
 
3187 rajveer 42
    def __init__(self, dbname='catalog', db_hostname='localhost'):
122 ashish 43
        '''
44
        Constructor
45
        '''
3187 rajveer 46
        DataService.initialize(dbname, db_hostname)
599 chandransh 47
        try:
621 chandransh 48
            config_client = ConfigClient()
49
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
50
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
599 chandransh 51
        except:
621 chandransh 52
            self.latest_arrivals_limit = 50
53
            self.best_sellers_limit = 50
122 ashish 54
 
55
    #DONE
56
    def addItem(self, item):
57
        """
58
        Availability and inventory attributes
59
 
60
        Parameters:
61
         - item
62
        """
63
        log_entry(self, "addItem called")
785 rajveer 64
        try:
65
            return add_item(item)
66
        finally:
67
            close_session()
122 ashish 68
 
69
    def addWarehouse(self, warehouse):
70
        """
71
        Parameters:
72
         - warehouse
73
        """
74
        log_entry(self, "addWarehouse called")
785 rajveer 75
        try:
76
            return add_warehouse(warehouse)
77
        finally:
78
            close_session()
122 ashish 79
 
3325 chandransh 80
    def updateInventoryHistory(self, warehouse_id, timestamp, availability):
81
        """
82
        Stores the incremental warehouse updates of items.
83
 
84
        Parameters:
85
         - warehouse_id
86
         - timestamp
87
         - availability
88
        """
89
        try:
90
            return update_inventory_history(warehouse_id, timestamp, availability)
91
        finally:
92
            close_session()
483 rajveer 93
 
94
    def updateInventory(self, warehouse_id, timestamp, availability):
122 ashish 95
        """
96
        Parameters:
97
         - warehouse_id
98
         - timestamp
483 rajveer 99
         - availability
122 ashish 100
        """
101
        log_entry(self, "update Inventory called")
785 rajveer 102
        try:
103
            return update_inventory(warehouse_id, timestamp, availability)
104
        finally:
105
            close_session()
106
 
107
 
635 rajveer 108
    def isActive(self, item_id):
563 chandransh 109
        """
110
        Parameters:
635 rajveer 111
         - item_id
563 chandransh 112
        """
785 rajveer 113
        try:
114
            return is_active(item_id)
115
        finally:
116
            close_session()
122 ashish 117
 
2035 rajveer 118
    def getItemStatusDescription(self, itemId):
119
        """
120
        Parameters:
121
         - itemId
122
        """
123
        try:
124
            return get_item_status_description(itemId)
125
        finally:
126
            close_session()
127
 
122 ashish 128
    def retireWarehouse(self, warehouse_id):
129
        """
130
        Parameters:
131
         - warehouse_id
132
        """
133
        log_entry(self, "retire warehouse called")
785 rajveer 134
        try:
135
            return retire_warehouse(warehouse_id)
136
        finally:
137
            close_session()
138
 
122 ashish 139
 
140
    def retireItem(self, item_id):
141
        """
142
        Parameters:
143
        - item_id
144
        """
145
        log_entry(self, "retire item called")
785 rajveer 146
        try:
147
            return retire_item(item_id)
148
        finally:
149
            close_session()
122 ashish 150
 
151
    def startItemOn(self, item_id, timestamp):
152
        """
153
        Parameters:
154
         - item_id
155
         - timestamp
156
        """
785 rajveer 157
        try:
158
            start_item_on(item_id, timestamp)
159
        finally:
160
            close_session()
122 ashish 161
 
162
    def retireItemOn(self, item_id, timestamp):
163
        """
164
        Parameters:
165
         - item_id
166
         - timestamp
167
        """
785 rajveer 168
        try:
169
            retire_item_on(item_id, timestamp)
170
        finally:
171
            close_session()
122 ashish 172
 
173
    def changeItemStatus(self, item_id, timestamp, newstatus):
174
        """
175
        Parameters:
176
         - item_id
177
         - timestamp
178
         - newstatus
179
        """
180
        log_entry(self, "change item status called")
785 rajveer 181
        try:
182
            return change_item_status(item_id, newstatus)
183
        finally:
184
            close_session()
122 ashish 185
 
785 rajveer 186
 
122 ashish 187
    def getItem(self, item_id):
188
        """
189
        Parameters:
190
         - item_id
191
        """
192
        log_entry(self, "item requested")
785 rajveer 193
        try:
2065 ankur.sing 194
            item = to_t_item( get_item(item_id))
195
            return item
785 rajveer 196
        finally:
197
            close_session()
379 ashish 198
 
635 rajveer 199
    def getItemsByCatalogId(self, catalog_item_id):
379 ashish 200
        """
201
        Parameters:
202
        - catalog_item_id
203
        """
386 ashish 204
        log_entry(self, "item requested")
766 rajveer 205
        try:
206
            return get_items_by_catalog_id(catalog_item_id)
207
        finally:
208
            close_session()
122 ashish 209
 
483 rajveer 210
 
122 ashish 211
    def getAllItems(self, isActive):
212
        """
213
        Parameters:
214
         - isActive
215
        """
216
        log_entry(self, "all items requested")
766 rajveer 217
        try:
218
            items = get_all_items(isActive)
219
            ret_items = []
220
            for item in items:
221
                if item:
222
                    ret_items.append(to_t_item(item))
223
            return ret_items
224
        finally:
225
            close_session()
226
 
122 ashish 227
    def getAllItemsByStatus(self, itemStatus):
228
        """
229
        Parameters:
230
         - itemStatus
231
        """
232
        log_entry(self, "all items requested")
766 rajveer 233
        try:
234
            items = get_all_items_by_status(itemStatus)
235
            ret_items = []
236
            for item in items:
237
                if item:
238
                    ret_items.append(to_t_item(item))
239
            return ret_items
240
        finally:
241
            close_session()
122 ashish 242
 
243
    def getItemInventory(self, item_id):
244
        """
245
        Parameters:
246
        - item_id
247
        """
248
        log_entry(self, "item inventory requested")
766 rajveer 249
        try:
250
            inventory = get_item_inventoy(item_id)
251
            return to_t_item_inventory(inventory, item_id)
252
        finally:
253
            close_session()
122 ashish 254
 
635 rajveer 255
    def getItemInventoryByItemId(self, item_id):
256
        """
257
        Parameters:
258
         - item_id
259
        """
260
        log_entry(self, "item inventory requested")
766 rajveer 261
        try:
262
            inventory = get_item_inventory_by_item_id(item_id)
263
            return to_t_item_inventory(inventory, item_id)
264
        finally:
265
            close_session()
635 rajveer 266
 
3348 varun.gupt 267
    def getAllBrandsByCategory(self, categoryId):
268
        """
269
        Parameters:
270
         - categoryId
271
        """
272
        try:
273
            return get_all_brands_by_category(categoryId)
274
        finally:
275
            close_session()
276
 
635 rajveer 277
    '''
379 ashish 278
    def getItemInventoryByCatalogId(self, item_id):
279
        """
280
        Parameters:
281
         - item_id
282
        """
383 ashish 283
        log_entry(self, "item inventory requested")
284
        inventory = get_item_inventory_by_catalog_id(item_id)
285
        return to_t_item_inventory(inventory, item_id)
635 rajveer 286
    '''
287
 
3849 chandransh 288
    def getAllItemsInRange(self, offset, limit):
289
        """
290
        Gets at most 'limit' items starting at the given offset. Returns an empty list if there are no more items at the given offset.
291
 
292
        Parameters:
293
         - offset
294
         - limit
295
        """
296
        try:
297
            items = get_all_items(False, offset, limit)
298
            return [to_t_item(item) for item in items]
299
        finally:
300
            close_session()
379 ashish 301
 
3849 chandransh 302
    def getAllItemsByStatusInRange(self, itemStatus, offset, limit):
303
        """
304
        Gets at most 'limit' items starting at the given offset in the given status. Returns an empty list if there are no more items at the given offset.
305
 
306
        Parameters:
307
         - itemStatus
308
         - offset
309
         - limit
310
        """
311
        log_entry(self, "all items requested")
312
        try:
313
            items = get_all_items_by_status(itemStatus, offset, limit)
314
            return [to_t_item(item) for item in items]
315
        finally:
316
            close_session()
317
 
318
    def getItemCountByStatus(self, useStatus, itemStatus):
319
        """
320
        Gets a count of all items by status
321
 
322
        Parameters:
323
         - useStatus
324
         - itemStatus
325
        """
326
        try:
327
            return get_item_count_by_status(useStatus, itemStatus)
328
        finally:
329
            close_session()
330
 
643 chandransh 331
    def getItemAvailabilityAtLocation(self, warehouse_loc, item_id):
332
        """
3355 chandransh 333
        Determines the warehouse that should be used to fulfil an order for the given item.
334
        It first checks all the warehouses which are in the logistics location given by the
335
        warehouse_loc parameter. If none of the warehouses there have any inventory, then the
336
        preferred warehouse for the item is used.
643 chandransh 337
 
3355 chandransh 338
        Returns an ordered list of size 4 with following elements in the given order:
339
        1. Logistics location of the warehouse which was finally picked up to ship the order.
340
        2. Id of the warehouse which was finally picked up.
341
        3. Inventory size in the selected warehouse.
342
        4. Expected delay added by the category manager.
343
 
643 chandransh 344
        Parameters:
345
         - warehouse_loc
346
         - item_id
347
        """
766 rajveer 348
        try:
349
            return get_item_availability_for_location(warehouse_loc, item_id)
350
        finally:
351
            close_session()
352
 
122 ashish 353
    def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):
354
        """
355
        Parameters:
356
         - warehouse_id
357
         - item_id
358
        """
359
        log_entry(self, "item availability at warehouse requested")
766 rajveer 360
        try:
361
            return get_item_availability_for_warehouse(warehouse_id, item_id)
362
        finally:
363
            close_session()
364
 
2080 rajveer 365
    def markItemAsContentComplete(self, entityId, category, brand, modelName, modelNumber):
366
        """
367
        Parameters:
368
         - entityId
369
         - category
370
         - brand
371
         - modelName
372
         - modelNumber
373
        """
374
        try:
375
            return mark_item_as_content_complete(entityId, category, brand, modelName, modelNumber)
376
        finally:
377
            close_session()
2075 rajveer 378
 
379
 
122 ashish 380
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
381
        """
382
        Parameters:
383
         - id
384
         - item_id
385
         - warehouse_id
386
         - from_date
387
         - to_date
388
        """
389
        pass
390
 
391
    def getAllWarehouses(self, isActive):
392
        """
393
        Parameters:
394
        - isActive
395
        """
766 rajveer 396
        try:
397
            if isActive:
398
                warehouses = get_all_warehouses_by_status(status.ACTIVE)
399
            else:
400
                warehouses = get_all_warehouses_by_status(None)
401
 
402
            ret_warehouses = []
403
 
404
            for warehouse in warehouses:
405
                ret_warehouses.append(to_t_warehouse(warehouse))
406
            return ret_warehouses
407
        finally:
408
            close_session()
409
 
122 ashish 410
    def getWarehouse(self, warehouse_id):
411
        """
412
        Parameters:
413
         - warehouse_id
414
        """
415
        log_entry(self, "get warehouse call")
766 rajveer 416
        try:
417
            warehouse = get_Warehouse(warehouse_id)
418
            if warehouse:
419
                return to_t_warehouse(warehouse)
420
            else:
421
                raise InventoryServiceException(101, "no such warehouse")
422
        finally:
423
            close_session()
424
 
122 ashish 425
    def getAllWarehousesForItem(self, item_id):
426
        """
427
        Parameters:
428
         - item_id
429
        """
430
        log_entry(self, "getting all warehouses for item")
766 rajveer 431
        try:
432
            all_warehouses = get_all_warehouses_for_item(item_id)
433
            t_warehouses = []
434
            for warehouse in all_warehouses:
435
                t_warehouses.append(to_t_warehouse(warehouse))
436
            return t_warehouses
437
        finally:
438
            close_session()
439
 
122 ashish 440
    def getAllItemsForWarehouse(self, warehouse_id):
441
        """
442
        Parameters:
443
         - warehouse_id
444
        """
445
        log_entry(self, "getting all items for warehouse")
766 rajveer 446
        try:
447
            all_items = get_all_items_for_warehouse(warehouse_id)
448
            t_items = []
449
            for item in all_items:
450
                t_items.append(to_t_item(item))
451
            return t_items
452
        finally:
453
            close_session()
871 chandransh 454
 
455
    def reserveItemInWarehouse(self, itemId, warehouseId, quantity):
456
        """
457
        Increases the reservation count for an item in a warehouse. Should always succeed normally.
458
 
459
        Parameters:
460
         - itemId
461
         - warehouseId
462
        """
463
        log_entry(self, "reserveItemInWarehouse called")
464
        try:
465
            return reserve_item_in_warehouse(itemId, warehouseId, quantity)
466
        finally:
467
            close_session()
468
 
469
    def reduceReservationCount(self, itemId, warehouseId, quantity):
470
        """
471
        Decreases the reservation count for an item in a warehouse. Should always succeed normally.
472
 
473
        Parameters:
474
         - itemId
475
         - warehouseId
476
        """
477
        log_entry(self, "reduceReservationCount called")
478
        try:
479
            return reduce_reservation_count(itemId, warehouseId, quantity)
480
        finally:
481
            close_session()
766 rajveer 482
 
122 ashish 483
    def updateItem(self, item):
484
        """
485
        Parameters:
486
         - item
487
        """
488
        log_entry(self, "addItem called")
766 rajveer 489
        try:
490
            return update_item(item)
491
        finally:
492
            close_session()
493
 
626 chandransh 494
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
766 rajveer 495
        try:
496
            if total_items is None:
497
                total_items = self.best_sellers_limit
498
            stop_index = start_index + total_items
499
            return get_best_sellers(start_index, stop_index, category)
500
        finally:
501
            close_session()
502
 
1926 rajveer 503
    def getBestSellersCatalogIds(self, start_index, total_items, brand, category=-1):
548 rajveer 504
        """
505
        Parameters:
506
         - beginIndex
507
         - totalItems
508
        """
766 rajveer 509
        try:
510
            if total_items is None:
511
                total_items = self.best_sellers_limit
512
            stop_index = start_index + total_items
1926 rajveer 513
            return get_best_sellers_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 514
        finally:
515
            close_session()
516
 
591 chandransh 517
    def getBestSellersCount(self, ):
766 rajveer 518
        try:
2093 chandransh 519
            return get_best_sellers_count()
766 rajveer 520
        finally:
521
            close_session()
522
 
591 chandransh 523
    def getBestDeals(self,):
766 rajveer 524
        try:
525
            return get_best_deals()
526
        finally:
527
            close_session()
528
 
1926 rajveer 529
    def getBestDealsCatalogIds(self, start_index, total_items, brand,category=-1):
548 rajveer 530
        """
531
        Parameters:
532
         - beginIndex
533
         - totalItems
534
        """
766 rajveer 535
        try:
536
            stop_index = start_index + total_items
1926 rajveer 537
            return get_best_deals_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 538
        finally:
539
            close_session()
540
 
591 chandransh 541
    def getBestDealsCount(self, ):
766 rajveer 542
        try:
543
            return get_best_deals_count()
544
        finally:
545
            close_session()
546
 
591 chandransh 547
    def getLatestArrivals(self,):
766 rajveer 548
        try:
549
            return get_latest_arrivals(self.latest_arrivals_limit)
550
        finally:
551
            close_session()
2975 chandransh 552
 
553
    def getLatestArrivalsCatalogIds(self, beginIndex, totalItems, brand, categories):
548 rajveer 554
        """
2975 chandransh 555
        Returns the list of catalog ids of latest arrivals in the given categories of the given brand.
556
        To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
557
 
548 rajveer 558
        Parameters:
559
         - beginIndex
560
         - totalItems
2975 chandransh 561
         - brand
562
         - categories
548 rajveer 563
        """
766 rajveer 564
        try:
2975 chandransh 565
            if beginIndex > self.latest_arrivals_limit:
766 rajveer 566
                return []
2975 chandransh 567
            stopIndex = beginIndex + totalItems
568
            if stopIndex > self.latest_arrivals_limit:
569
                stopIndex = self.latest_arrivals_limit
570
            return get_latest_arrivals_catalog_ids(beginIndex, stopIndex, brand, categories)
766 rajveer 571
        finally:
572
            close_session()
573
 
591 chandransh 574
    def getLatestArrivalsCount(self, ):
766 rajveer 575
        try:
576
            return get_latest_arrivals_count(self.latest_arrivals_limit)
577
        finally:
578
            close_session()
591 chandransh 579
 
1334 chandransh 580
    def getItemPricing(self, itemId, warehouseId):
581
        """
582
        Returns the pricing information of an item associated with the vendor of the given warehouse.
583
        Raises an exception if either the item, vendor or the associated pricing information can't be found.
584
 
585
        Parameters:
586
         - itemId
587
         - warehouseId
588
        """
1341 chandransh 589
        try:
1347 chandransh 590
            return to_t_vendor_item_pricing(get_item_pricing(itemId, warehouseId))
1341 chandransh 591
        finally:
592
            close_session()
1991 ankur.sing 593
 
594
 
595
    def getAllItemPricing(self, itemId):
596
        """
597
        Returns list of the pricing information of an item associated an item.
598
        Raises an exception if the item can't be found.
599
 
600
        Parameters:
601
         - itemId
602
        """
603
        try:
604
            return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]
605
        finally:
606
            close_session()
1334 chandransh 607
 
1155 rajveer 608
    def generateNewEntityID(self, ):
609
        try:
610
            return generate_new_entity_id()
611
        finally:
612
            close_session()
613
 
635 rajveer 614
    def putCategoryObject(self, object):
615
        """
616
        Parameters:
617
         - object
618
        """
766 rajveer 619
        try:
620
            return put_category_object(object)
621
        finally:
622
            close_session()
623
 
635 rajveer 624
    def getCategoryObject(self, ):
766 rajveer 625
        try:
626
            return get_category_object()
627
        finally:
628
            close_session()
1970 rajveer 629
 
630
    def addCategory(self, category):
631
        """
632
        Parameters:
633
         - category
634
        """
635
        try:
636
            return add_category(category)
637
        finally:
638
            close_session()
639
 
640
    def getCategory(self, id):
641
        """
642
        Parameters:
643
         - id
644
        """
645
        try:
646
            return to_t_category(get_category(id))
647
        finally:
648
            close_session()
649
 
650
    def getAllCategories(self, ):
651
        try:
652
            categories = get_all_categories()
653
            return [to_t_category(category) for category in categories]
654
        finally:
655
            close_session()
656
 
657
 
2116 ankur.sing 658
    def addVendorItemPricing(self, vendorItemPricing):
1991 ankur.sing 659
        """
2116 ankur.sing 660
        Adds vendor prices corresponding to the item. If pricing already exists then updates the prices. 
1991 ankur.sing 661
        Raises an exception if either the item or vendor can't be found corresponding to their ids.
662
 
663
        Parameters:
664
         - vendorItemPricing
665
        """
666
        log_entry(self, "updateVendorItemPricing called")
667
        try:
2116 ankur.sing 668
            return add_vendor_pricing(vendorItemPricing)
1991 ankur.sing 669
        finally:
670
            close_session()
671
 
2065 ankur.sing 672
    def getAllVendors(self, ):
673
        """
674
        Return list of all vendors
675
        """
676
        return [to_t_vendor(v) for v in get_all_vendors()]
2116 ankur.sing 677
 
678
    def itemExists(self, productGroup, brand, modelNumber, color, vendorId, category):
679
        try:
680
            return check_vendor_item_mapping(productGroup, brand, modelNumber, color, vendorId, category)
681
        finally:
682
            close_session()
2065 ankur.sing 683
 
2358 ankur.sing 684
    def addVendorItemMapping(self, key, vendorItemMapping):
2116 ankur.sing 685
        """
2358 ankur.sing 686
        Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.
2116 ankur.sing 687
 
688
        Parameters:
2358 ankur.sing 689
         - key
2116 ankur.sing 690
         - vendorItemMapping
691
        """
692
        log_entry(self, "addVendorItemMapping called")
693
        try:
2358 ankur.sing 694
            return add_vendor_item_mapping(key, vendorItemMapping)
2116 ankur.sing 695
        finally:
696
            close_session()
697
 
698
    def getVendorItemMappings(self, itemId):
699
        """
700
        Returns the list of vendor item mapping corresponding to itemId passed as parameter.
701
        Raises an exception if item not found corresponding to itemId
702
 
703
        Parameters:
704
         - itemId
705
        """
706
        try:
2120 ankur.sing 707
            item_mappings = get_item_mappings(itemId)
708
            return [to_t_vendor_item_mapping(vim) for vim in item_mappings]
2116 ankur.sing 709
        finally:
710
            close_session()
711
 
712
    def checkSimilarItem(self, productGroup, brand, modelNumber, color):
713
        """
714
        Checks if similar item exists (with same ProductGroup, Brand, ModelNumber, Color)
715
        If yes, returns the itemId else returns 0
716
 
717
        Parameters:
718
         - productGroup
719
         - brand
720
         - modelNumber
721
         - color
722
        """
723
        try:
724
            return check_similar_item(productGroup, brand, modelNumber, color)
725
        finally:
726
            close_session()
727
 
2286 ankur.sing 728
    def changeItemRiskyFlag(self, itemId, risky):
729
        """
730
        Marks/Unmarks an item as risky. This flag is used for automatic marking of an item as INACTIVE in case of zero inventory.
731
 
732
        Parameters:
733
         - itemId
734
         - risky
735
        """
736
        try:
737
            change_risky_flag(itemId, risky)
738
        finally:
739
            close_session()
2116 ankur.sing 740
 
2358 ankur.sing 741
    def getItemsByVendorCategory(self, vendorCategory):
742
        """
743
        Return list of items filtered by vendor category.
744
        Raises exception if vendorCategory is null.
745
 
746
        Parameters:
747
         - vendorCategory
748
        """
749
        try:
750
            return [to_t_item(item) for item in get_items_by_vendor_category(vendorCategory)]
751
        finally:
752
            close_session()
753
 
754
    def getItemsByRiskyFlag(self, ):
755
        """
756
        Returns list of items marked as risky.
757
        """
758
        try:
759
            return [to_t_item(item) for item in get_risky_items()]
760
        finally:
761
            close_session()
2809 rajveer 762
 
763
    def getSimilarItemsCatalogIds(self, beginIndex, totalItems, itemId):
764
        """
765
        Returns list of catalog ids of items with same similarity index as of the given itemId
766
 
767
        Parameters:
768
         - beginIndex
769
         - totalItems
770
         - itemId
771
        """
772
        try:
773
            return get_similar_items_catalog_ids(beginIndex, beginIndex+totalItems, itemId)
774
        finally:
775
            close_session()
3079 rajveer 776
 
777
    def addProductNotification(self, itemId, email):
778
        """
779
        Add user requests for out of stock items. Once user will ask for notify me an entry will
780
 
781
        Parameters:
782
        - itemId
783
        - email
784
        """
785
        try:
786
            return add_product_notification(itemId, email)
787
        finally:
788
            close_session()
2358 ankur.sing 789
 
3086 rajveer 790
    def sendProductNotifications(self, ):
791
        """
792
        Send the product notifications to the users for items which has stock.
793
        """
794
        try:
795
            return send_product_notifications()
796
        finally:
797
            close_session()
3557 rajveer 798
 
799
 
800
    def getAllSources(self, ):
801
        """
802
        Return list of all sources
803
        """
804
        try:
805
            return get_all_sources()
806
        finally:
807
            close_session()
808
 
809
    def getItemPricingBySource(self, itemId, sourceId):
810
        """
811
        Returns the pricing information of an item. If no information is found, exception will be thrown.
3376 rajveer 812
 
3557 rajveer 813
        Parameters:
814
         - itemId
815
         - sourceId
816
        """
817
        try:
818
            return to_t_source_item_pricing(get_item_pricing_by_source(itemId, sourceId))
819
        finally:
820
            close_session()
821
 
822
    def addSourceItemPricing(self, sourceItemPricing):
823
        """
824
        Adds prices to be displayed corresponding to the item if user comes from a source.
825
 
826
        Parameters:
827
         - sourceItemPricing
828
        """
829
        try:
830
            add_source_item_pricing(sourceItemPricing)
831
        finally:
832
            close_session()
833
 
834
    def getAllSourcePricing(self, itemId):
835
        """
836
        Returns the list of source pricing information of an item.
837
        Raises an exception if item not found corresponding to itemId
838
 
839
        Parameters:
840
         - itemId
841
        """
842
        try:
843
            return [to_t_source_item_pricing(source_item_pricing) for source_item_pricing in get_all_source_pricing(itemId)]
844
#        return [to_t_item(item) for item in get_risky_items()]
845
        finally:
846
            close_session()
847
 
848
    def getItemForSource(self, item_id, sourceId):
849
        """
850
        Parameters:
851
         - item_id
852
         - sourceId
853
        """
854
        try:
855
            return to_t_item(get_item_for_source(item_id, sourceId))
856
        finally:
857
            close_session()
858
 
3376 rajveer 859
    def isAlive(self, ):
860
        """
861
        For checking weather service is active alive or not. It also checks connectivity with database
862
        """
863
        try:
864
            return is_alive()
865
        finally:
866
            close_session()
867
 
766 rajveer 868
    def closeSession(self, ):
3376 rajveer 869
        """
870
        For closing the open session in sqlalchemy
871
        """
872
        close_session()        
873