Subversion Repositories SmartDukaan

Rev

Rev 7149 | Rev 7316 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5944 mandeep.dh 1
'''
2
Created on 27-Apr-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.config.client.ConfigClient import ConfigClient
7
from shop2020.model.v1.inventory.impl import DataService
5957 mandeep.dh 8
from shop2020.model.v1.inventory.impl.Convertors import to_t_item_inventory, \
6821 amar.kumar 9
    to_t_warehouse, to_t_vendor_item_pricing, to_t_vendor, to_t_vendor_item_mapping, \
7281 kshitij.so 10
    to_t_item_stock_purchase_params, to_t_oos_status, to_t_amazon_inventory_snapshot
5944 mandeep.dh 11
from shop2020.model.v1.inventory.impl.DataAcessors import add_warehouse, \
12
    update_inventory, retire_warehouse, get_item_availability_for_warehouse, \
13
    get_item_availability_for_location, get_all_warehouses_by_status, get_Warehouse, \
5957 mandeep.dh 14
    get_all_items_for_warehouse, close_session, add_vendor, \
15
    get_item_inventory_by_item_id, reserve_item_in_warehouse, \
16
    reduce_reservation_count, get_all_item_pricing, add_vendor_pricing, \
17
    get_item_pricing, get_all_vendors, get_item_mappings, add_vendor_item_mapping, \
18
    update_inventory_history, is_alive, add_inventory, add_bad_inventory, \
19
    mark_missed_inventory_updates_as_processed, update_vendor_string, \
20
    get_item_keys_to_be_processed, reset_availability, get_shipping_locations, \
5944 mandeep.dh 21
    initialize, get_inventory_snapshot, clear_item_availability_cache, \
5987 rajveer 22
    reset_availability_for_warehouse, get_vendor, get_pending_orders_inventory, \
6531 vikram.rag 23
    is_order_billable, get_our_warehouse_id_for_vendor, \
24
    get_item_availability_for_our_warehouses, get_monitored_warehouses_for_vendors, \
25
    get_ignored_warehouseids_and_itemids,insert_item_to_ignore_inventory_update_list, \
26
    delete_item_from_ignore_inventory_update_list,get_all_ignored_inventoryupdate_items_count, \
6821 amar.kumar 27
    get_ignored_inventoryupdate_itemids, update_item_stock_purchase_params, \
6857 amar.kumar 28
    get_item_stock_purchase_params, add_oos_status_for_item, \
7149 amar.kumar 29
    get_oos_statuses_for_x_days_for_item, get_non_zero_item_stock_purchase_params, \
7281 kshitij.so 30
    get_billable_inventory_and_pending_orders,get_warehouse_name,get_amazon_inventory_for_item,get_all_amazon_inventory, \
31
    add_or_update_amazon_inventory_for_item
5944 mandeep.dh 32
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
33
    MissedInventoryUpdate, VendorItemMapping
5957 mandeep.dh 34
from shop2020.thriftpy.model.v1.inventory.ttypes import \
35
    InventoryServiceException, WarehouseType, InventoryType, \
36
    AvailableAndReservedStock
5944 mandeep.dh 37
from shop2020.utils.Utils import log_entry, to_java_date
38
 
39
class InventoryServiceHandler:
40
    '''
41
    classdocs
42
    '''
43
 
44
    def __init__(self, dbname='catalog', db_hostname='localhost'):
45
        '''
46
        Constructor
6532 amit.gupta 47
u        '''
5944 mandeep.dh 48
        initialize(dbname, db_hostname)
49
        try:
50
            config_client = ConfigClient()
51
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
52
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
53
        except:
54
            self.latest_arrivals_limit = 50
55
            self.best_sellers_limit = 50
56
 
57
    def addWarehouse(self, warehouse):
58
        """
59
        Parameters:
60
         - warehouse
61
        """
62
        log_entry(self, "addWarehouse called")
63
        try:
64
            return add_warehouse(warehouse)
65
        finally:
66
            close_session()
67
 
68
    def updateInventoryHistory(self, warehouse_id, timestamp, availability):
69
        """
70
        Stores the incremental warehouse updates of items.
71
 
72
        Parameters:
73
         - warehouse_id
74
         - timestamp
75
         - availability
76
        """
77
        try:
78
            return update_inventory_history(warehouse_id, timestamp, availability)
79
        finally:
80
            close_session()
81
 
82
    def updateInventory(self, warehouse_id, timestamp, availability):
83
        """
84
        Parameters:
85
         - warehouse_id
86
         - timestamp
87
         - availability
88
        """
89
        log_entry(self, "update Inventory called")
90
        try:
91
            return update_inventory(warehouse_id, timestamp, availability)
92
        finally:
93
            close_session()
94
 
95
    def addInventory(self, itemId, warehouseId, quantity):
96
        """
97
        Add the inventory to existing stock.
98
 
99
        Parameters:
100
         - itemId
101
         - warehouseId
102
         - quantity
103
        """
104
        log_entry(self, "add Inventory called")
105
        try:
106
            return add_inventory(itemId, warehouseId, quantity)
107
        finally:
108
            close_session()
109
 
110
    def retireWarehouse(self, warehouse_id):
111
        """
112
        Parameters:
113
         - warehouse_id
114
        """
115
        log_entry(self, "retire warehouse called")
116
        try:
117
            return retire_warehouse(warehouse_id)
118
        finally:
119
            close_session()
120
 
121
 
122
    def getItemInventoryByItemId(self, item_id):
123
        """
124
        Parameters:
125
         - item_id
126
        """
127
        log_entry(self, "item inventory requested")
128
        try:
129
            inventory = get_item_inventory_by_item_id(item_id)
130
            return to_t_item_inventory(inventory, item_id)
131
        finally:
132
            close_session()
133
 
5978 rajveer 134
    def getItemAvailabilityAtLocation(self, itemId, sourceId):
5944 mandeep.dh 135
        """
136
        Determines the warehouse that should be used to fulfil an order for the given item.
137
        It first checks all the warehouses which are in the logistics location given by the
138
        warehouse_loc parameter. If none of the warehouses there have any inventory, then the
139
        preferred warehouse for the item is used.
140
 
141
        Returns an ordered list of size 4 with following elements in the given order:
142
        1. Logistics location of the warehouse which was finally picked up to ship the order.
143
        2. Id of the warehouse which was finally picked up.
144
        3. Inventory size in the selected warehouse.
145
        4. Expected delay added by the category manager.
146
 
147
        Parameters:
148
         - itemId
5978 rajveer 149
         - sourceId
5944 mandeep.dh 150
        """
151
        try:
5978 rajveer 152
            return get_item_availability_for_location(itemId, sourceId)
5944 mandeep.dh 153
        finally:
154
            close_session()
155
 
156
    def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):
157
        """
158
        Parameters:
159
         - warehouse_id
160
         - item_id
161
        """
162
        log_entry(self, "item availability at warehouse requested")
163
        try:
164
            return get_item_availability_for_warehouse(warehouse_id, item_id)
165
        finally:
166
            close_session()
6484 amar.kumar 167
 
168
    def getItemAvailabilitiesAtOurWarehouses(self, item_ids):
169
        try:   
170
            return get_item_availability_for_our_warehouses(item_ids)
171
        finally:
172
            close_session()
5944 mandeep.dh 173
 
174
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
175
        """
176
        Parameters:
177
         - id
178
         - item_id
179
         - warehouse_id
180
         - from_date
181
         - to_date
182
        """
183
        pass
184
 
185
    def getAllWarehouses(self, isActive):
186
        """
187
        Parameters:
188
        - isActive
189
        """
190
        try:
191
            if isActive:
192
                warehouses = get_all_warehouses_by_status(3)
193
            else:
194
                warehouses = get_all_warehouses_by_status(None)
195
 
196
            ret_warehouses = []
197
 
198
            for warehouse in warehouses:
199
                ret_warehouses.append(to_t_warehouse(warehouse))
200
            return ret_warehouses
201
        finally:
202
            close_session()
203
 
204
    def getWarehouse(self, warehouse_id):
205
        """
206
        Parameters:
207
         - warehouse_id
208
        """
209
        log_entry(self, "get warehouse call")
210
        try:
211
            warehouse = get_Warehouse(warehouse_id)
212
            if warehouse:
213
                return to_t_warehouse(warehouse)
214
            else:
215
                raise InventoryServiceException(101, "no such warehouse: " + str(warehouse_id))
216
        finally:
217
            close_session()
218
 
219
    def getAllItemsForWarehouse(self, warehouse_id):
220
        """
221
        Parameters:
222
         - warehouse_id
223
        """
224
        log_entry(self, "getting all items for warehouse")
225
        try:
226
            all_items = get_all_items_for_warehouse(warehouse_id)
227
            t_items = []
228
            for item in all_items:
229
                t_items.append(item.id)
230
            return t_items
231
        finally:
232
            close_session()
233
 
5966 rajveer 234
    def isOrderBillable(self, itemId, warehouseId, sourceId, orderId):
5944 mandeep.dh 235
        """
5966 rajveer 236
        Depending on reservation in the table, verify if we can bill this order or not.
237
 
238
        Parameters:
239
         - itemId
240
         - warehouseId
241
         - sourceId
242
         - orderId
243
        """
244
        try:
245
            return is_order_billable(itemId, warehouseId, sourceId, orderId)
246
        finally:
247
            close_session()
248
 
249
    def reserveItemInWarehouse(self, itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity):
250
        """
5944 mandeep.dh 251
        Increases the reservation count for an item in a warehouse. Should always succeed normally.
252
 
253
        Parameters:
254
         - itemId
255
         - warehouseId
256
        """
257
        log_entry(self, "reserveItemInWarehouse called")
258
        try:
5966 rajveer 259
            return reserve_item_in_warehouse(itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity)
5944 mandeep.dh 260
        finally:
261
            close_session()
262
 
5966 rajveer 263
    def reduceReservationCount(self, itemId, warehouseId, sourceId, orderId, quantity):
5944 mandeep.dh 264
        """
265
        Decreases the reservation count for an item in a warehouse. Should always succeed normally.
266
 
267
        Parameters:
268
         - itemId
269
         - warehouseId
270
        """
271
        log_entry(self, "reduceReservationCount called")
272
        try:
5966 rajveer 273
            return reduce_reservation_count(itemId, warehouseId, sourceId, orderId, quantity)
5944 mandeep.dh 274
        finally:
275
            close_session()
276
 
277
    def getItemPricing(self, itemId, vendorId):
278
        """
279
        Returns the pricing information of an item associated with the vendor of the given warehouse.
280
        Raises an exception if either the item, vendor or the associated pricing information can't be found.
281
 
282
        Parameters:
283
         - itemId
284
         - warehouseId
285
        """
286
        try:
287
            return to_t_vendor_item_pricing(get_item_pricing(itemId, vendorId))
288
        finally:
289
            close_session()
290
 
291
 
292
    def getAllItemPricing(self, itemId):
293
        """
294
        Returns list of the pricing information of an item associated an item.
295
        Raises an exception if the item can't be found.
296
 
297
        Parameters:
298
         - itemId
299
        """
300
        try:
301
            return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]
302
        finally:
303
            close_session()
304
 
305
    def addVendorItemPricing(self, vendorItemPricing):
306
        """
307
        Adds vendor prices corresponding to the item. If pricing already exists then updates the prices. 
308
        Raises an exception if either the item or vendor can't be found corresponding to their ids.
309
 
310
        Parameters:
311
         - vendorItemPricing
312
        """
313
        log_entry(self, "updateVendorItemPricing called")
314
        try:
315
            return add_vendor_pricing(vendorItemPricing)
316
        finally:
317
            close_session()
318
 
319
    def getVendor(self, vendorId):
320
        """
321
        Return a vendor for id
322
        """
323
        try:
324
            return to_t_vendor(get_vendor(vendorId))
325
        finally:
326
            close_session()
327
 
328
 
329
    def getAllVendors(self, ):
330
        """
331
        Return list of all vendors
332
        """
333
        try:
334
            return [to_t_vendor(v) for v in get_all_vendors()]
335
        finally:
336
            close_session()
337
 
338
    def addVendorItemMapping(self, key, vendorItemMapping):
339
        """
340
        Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.
341
 
342
        Parameters:
343
         - key
344
         - vendorItemMapping
345
        """
346
        log_entry(self, "addVendorItemMapping called")
347
        try:
348
            return add_vendor_item_mapping(key, vendorItemMapping)
349
        finally:
350
            close_session()
351
 
352
    def getVendorItemMappings(self, itemId):
353
        """
354
        Returns the list of vendor item mapping corresponding to itemId passed as parameter.
355
        Raises an exception if item not found corresponding to itemId
356
 
357
        Parameters:
358
         - itemId
359
        """
360
        try:
361
            item_mappings = get_item_mappings(itemId)
362
            return [to_t_vendor_item_mapping(vim) for vim in item_mappings]
363
        finally:
364
            close_session()
365
 
366
    def isAlive(self, ):
367
        """
368
        For checking weather service is active alive or not. It also checks connectivity with database
369
        """
370
        try:
371
            return is_alive()
372
        finally:
373
            close_session()
374
 
375
    def closeSession(self, ):
376
        """
377
        For closing the open session in sqlalchemy
378
        """
379
        close_session()
380
 
381
    def addVendor(self, vendor):
382
        """
383
        add a new vendor
384
        """
385
        try:
386
            return add_vendor(vendor)
387
        finally:
388
            close_session()
389
 
390
    def getWarehouses(self, warehouseType, inventoryType, vendorId, billingWarehouseId, shippingWarehouseId):
391
        """
392
        This method returns all warehouses for a given warehosueType, inventoryType, vendor, billingWarehouse and shippingWarehouse.
393
        getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 1 for billing warehouse 7 and shipping warehouse 7
394
        getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7
395
        getWarehouses(null, null, 3, 7, 7) would return all type warehouses with all type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7
396
        getWarehouses(null, null, 0, 0, 7) would return all type warehouses with all type inventory for all vendors for all billing warehouses at shipping warehouse 7
397
 
398
        Parameters:
399
         - warehouseType
400
         - inventoryType
401
         - vendorId
402
         - billingWarehouseId
403
         - shippingWarehouseId
404
        """
405
        try:
406
            query = Warehouse.query
407
            if warehouseType is not None:
408
                query = query.filter_by(warehouseType = WarehouseType._VALUES_TO_NAMES[warehouseType])
409
            if inventoryType is not None:
410
                query = query.filter_by(inventoryType = InventoryType._VALUES_TO_NAMES[inventoryType])
411
            if vendorId:
412
                query = query.filter_by(vendor_id = vendorId)
413
            if billingWarehouseId:
414
                query = query.filter_by(billingWarehouseId = billingWarehouseId)
415
            if shippingWarehouseId:
416
                query = query.filter_by(shippingWarehouseId = shippingWarehouseId)
417
 
418
            return [to_t_warehouse(w) for w in query.all()]
419
        finally:
420
            close_session()
421
 
422
    def getItemKeysToBeProcessed(self, warehouseId):
423
        """
424
        Returns the list of item keys which need to be processed for a given warehouse.
425
        This is currently used by Support application to send item keys whose inventory needs
426
        to be updated from PLB
427
 
428
        Parameters:
429
         - warehouseId
430
        """
431
        try:
432
            return get_item_keys_to_be_processed(warehouseId)
433
        finally:
434
            close_session()
435
 
436
    def markMissedInventoryUpdatesAsProcessed(self, itemKey, warehouseId):
437
        """
438
        Marks/Deletes missed inventory updates for a given key and warehouse.
439
        This generally happens when updates from PLB are applied on the currentinventorysnapshot for an item
440
 
441
        Parameters:
442
         - itemKey
443
         - warehouseId
444
        """
445
        try:
446
            mark_missed_inventory_updates_as_processed(itemKey, warehouseId)
447
        finally:
448
            close_session()
449
 
450
    def resetAvailability(self, itemKey, vendorId, quantity, warehouseId):
451
        """
452
        Resets availability of an item to the quantity mentioned in a warehouse.
453
 
454
        Parameters:
455
         - itemKey
456
         - vendorId
457
         - quantity
458
         - warehouseId
459
        """
460
        try:
461
            reset_availability(itemKey, vendorId, quantity, warehouseId)
462
        finally:
463
            close_session()
464
 
465
    def resetAvailabilityForWarehouse(self, warehouseId):
466
        """
467
        Resets availability of a warehouse to zero.
468
 
469
        Parameters:
470
         - warehouseId
471
        """
472
        try:
473
            reset_availability_for_warehouse(warehouseId)
474
        finally:
475
            close_session()
476
 
477
    def getIgnoredItemKeys(self, ):
478
        """
479
        Returns all the item key mappings that have been ignored until date. Value of map has the warehouse id
480
        and the timestamp from where alert was raised.
481
        """
482
        try:
483
            itemKeysMap = {}
484
            for key in MissedInventoryUpdate.query.filter_by(isIgnored = 1).all():
485
                itemKeysMap[key.itemKey] = { key.warehouseId : to_java_date(key.timestamp) }
486
 
487
            return itemKeysMap
488
        finally:
489
            close_session()
490
 
491
    def addBadInventory(self, itemId, warehouseId, quantity):
492
        """
493
        Add the BAD type inventory to existing stock.
494
 
495
        Parameters:
496
         - itemId
497
         - warehouseId
498
         - quantity
499
        """
500
        try:
501
            add_bad_inventory(itemId, warehouseId, quantity)
502
        finally:
503
            close_session()
504
 
505
    def getShippingLocations(self, ):
506
        """
507
        Returns all shipping locations
508
        """
509
        try:
510
            return [to_t_warehouse(w) for w in get_shipping_locations()]
511
        finally:
512
            close_session()
513
 
514
    def getAllVendorItemMappings(self, ):
515
        """
516
        Fetches all the vendor item mappings present.
517
        """
518
        try:
519
            return [to_t_vendor_item_mapping(m) for m in VendorItemMapping.query.all()]
520
        finally:
521
            close_session()
522
 
523
    def getInventorySnapshot(self, warehouseId):
524
        """
525
        Gets items' inventory for a warehouse
526
        If warehouse is passed as zero, items' inventory across all warehouses is sent
527
 
528
        Parameters:
529
         - warehouseId
530
        """
531
        try:
532
            resultMap = {}
533
            itemInventoryMap = get_inventory_snapshot(warehouseId)
534
            for key, value in itemInventoryMap.items():
535
                resultMap[key] = to_t_item_inventory(value, key)
536
 
537
            return resultMap
538
        finally:
539
            close_session()
540
 
541
    def clearItemAvailabilityCache(self, ):
542
        """
543
        Clear item availability cache.
544
        """
545
        try:
546
            clear_item_availability_cache()
547
        finally:
548
            close_session()
5957 mandeep.dh 549
 
6096 amit.gupta 550
    def clearItemAvailabilityCacheForItem(self, item_id):
551
        """
552
        Clear item availability cache.
553
        """
554
        try:
555
            clear_item_availability_cache(item_id)
556
        finally:
557
            close_session()
558
 
5957 mandeep.dh 559
    def getPendingOrdersInventory(self, vendorId):
560
        """
561
        Returns a list of inventory stock for items for which there are pending orders for the given vendor.
562
        """
563
        try:
564
            pending_items_inventory = get_pending_orders_inventory(vendorId)
565
            return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in pending_items_inventory]
566
        finally:
567
            close_session()
568
 
5944 mandeep.dh 569
    def updateVendorString(self, warehouseId, vendorString):
570
        """
571
        Parameters:
572
         - warehouseId
573
         - vendorString
574
        """
575
        try:
576
            update_vendor_string(warehouseId, vendorString)
577
        finally:
578
            close_session()
6467 amar.kumar 579
    def getOurWarehouseIdForVendor(self, vendorId):
580
        """
581
        Returns warehouseId for our warehouse for a vendor
582
        """    
583
        try:
584
            return get_our_warehouse_id_for_vendor(vendorId)
585
        finally:
6531 vikram.rag 586
            close_session()
587
    def getMonitoredWarehouseForVendors(self, vendorIds):
588
        """
589
        Returns monitored warehouse ids for vendors
590
        """    
591
        try:
592
            return get_monitored_warehouses_for_vendors(vendorIds)
593
        finally:
594
            close_session()
595
    def getIgnoredWarehouseidsAndItemids(self):
596
        """
597
        Returns list of itemid and warehouseId for ignored inventory update
598
        """    
599
        try:
600
            return get_ignored_warehouseids_and_itemids()
601
        finally:
602
            close_session()
603
 
604
    def insertItemtoIgnoreInventoryUpdatelist(self,item_id,warehouse_id):
605
        """
606
        Returns list of itemid and warehouseId for ignored inventory update
607
        """
608
        try:
6532 amit.gupta 609
            return insert_item_to_ignore_inventory_update_list(item_id,warehouse_id)
6531 vikram.rag 610
        finally:
611
            close_session()     
612
    def deleteItemFromIgnoredInventoryUpdateList(self,item_id,warehouse_id):
613
        """
614
        Deletes warehouse and item entry from inventory update ignore list
615
        """
616
        try:
617
            return delete_item_from_ignore_inventory_update_list(item_id,warehouse_id)
618
        finally:
619
            close_session()
620
    def getAllIgnoredInventoryupdateItemsCount(self):
621
        """
622
        Returns all ignored inventory update item count
623
        """
6833 amar.kumar 624
        try:
625
            return get_all_ignored_inventoryupdate_items_count()
626
        finally:
627
            close_session()
6531 vikram.rag 628
 
629
 
630
    def getIgnoredInventoryUpdateItemids(self,offset,limit):
631
        """
632
        Returns all ignored inventory update items
633
        """
6833 amar.kumar 634
        try:
635
            return get_ignored_inventoryupdate_itemids(offset,limit)
636
        finally:
637
            close_session()
6821 amar.kumar 638
    def updateItemStockPurchaseParams(self, item_id, numOfDaysStock, minStockLevel):
639
        """
640
        Update/Add parameters required for heuristic purchase of Items 
6833 amar.kumar 641
        """ 
642
        try:               
643
            update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel)
644
        finally:
645
            close_session()
646
 
6821 amar.kumar 647
    def getItemStockPurchaseParams(self, item_id):
648
        """
649
        Get parameters required for heuristic purchase of Items 
6833 amar.kumar 650
        """ 
651
        try:               
652
            return to_t_item_stock_purchase_params(get_item_stock_purchase_params(item_id))
653
        finally:
654
            close_session()
655
 
6821 amar.kumar 656
    def addOosStatusForItem(self, oosStatusMap, date):
657
        """
658
        Add OOS status for Item 
659
        """
6833 amar.kumar 660
        try:
661
            add_oos_status_for_item(oosStatusMap, date)
662
        finally:
663
            close_session()
664
 
6832 amar.kumar 665
    def getOosStatusesForXDaysForItem(self, itemId, days):
666
        """
667
        Get OOSStatus Objects for "days" number of days 
668
        """
6833 amar.kumar 669
        try:
670
            return [to_t_oos_status(oos) for oos in get_oos_statuses_for_x_days_for_item(itemId, days)]
671
        finally:
6857 amar.kumar 672
            close_session()
673
 
674
    def getNonZeroItemStockPurchaseParams(self):
675
        """
676
        Get All ItemStockPurchaseParam objects where either minStockLevel or minNumOfDaysOfStock is zero 
677
        """
678
        try:
679
            return [to_t_item_stock_purchase_params(ispp) for ispp in get_non_zero_item_stock_purchase_params()]
680
        finally:
7149 amar.kumar 681
            close_session()
682
    def getBillableInventoryAndPendingOrders(self):
683
        """
684
        Returns a list of inventory stock for items for which there are pending orders or have 
685
        billable inventory.
686
        """
687
        try:
688
            items_inventory = get_billable_inventory_and_pending_orders()
689
            return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in items_inventory]
690
        finally:
7281 kshitij.so 691
            close_session()
692
 
693
    def getWarehouseName(self,warehouseId):
694
        try:
695
            name = get_warehouse_name(warehouseId)
696
            return name
697
        finally:
698
            close_session()
699
 
700
    def getAmazonInventoryForItem(self, amazonItemId):
701
        result = None
702
        try:
703
            result = get_amazon_inventory_for_item(amazonItemId)
704
            if result is not None:
705
                result = to_t_amazon_inventory_snapshot(result)
706
 
707
        except:
708
            return None
709
        finally:
710
            close_session()
711
            return result
712
 
713
    def getAllAmazonInventory(self):
714
        try:
715
            amazoninventory = []
716
            all_inventory = get_all_amazon_inventory()
717
            for inventory in all_inventory:
718
                amazoninventory.append(to_t_amazon_inventory_snapshot((inventory)))
719
            return amazoninventory                                           
720
        finally:
721
            close_session() 
722
 
723
    def addOrUpdateAmazonInventoryForItem(self, amazoninvetorysnapshot):
724
        try:
725
            return add_or_update_amazon_inventory_for_item(amazoninvetorysnapshot)
726
        finally:
6833 amar.kumar 727
            close_session()