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