Subversion Repositories SmartDukaan

Rev

Rev 7718 | Rev 7972 | 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, \
7968 amar.kumar 31
    add_or_update_amazon_inventory_for_item, update_reservation_for_order
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()
7968 amar.kumar 262
 
5944 mandeep.dh 263
 
7968 amar.kumar 264
    def updateReservationForOrder(self, itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity):
265
        """
266
        Increases the reservation count for an item in a warehouse. Should always succeed normally.
267
 
268
        Parameters:
269
         - itemId
270
         - warehouseId
271
        """
272
        log_entry(self, "reserveItemInWarehouse called")
273
        try:
274
            return update_reservation_for_order(itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity)
275
        finally:
276
            close_session()
277
 
5966 rajveer 278
    def reduceReservationCount(self, itemId, warehouseId, sourceId, orderId, quantity):
5944 mandeep.dh 279
        """
280
        Decreases the reservation count for an item in a warehouse. Should always succeed normally.
281
 
282
        Parameters:
283
         - itemId
284
         - warehouseId
285
        """
286
        log_entry(self, "reduceReservationCount called")
287
        try:
5966 rajveer 288
            return reduce_reservation_count(itemId, warehouseId, sourceId, orderId, quantity)
5944 mandeep.dh 289
        finally:
290
            close_session()
291
 
292
    def getItemPricing(self, itemId, vendorId):
293
        """
294
        Returns the pricing information of an item associated with the vendor of the given warehouse.
295
        Raises an exception if either the item, vendor or the associated pricing information can't be found.
296
 
297
        Parameters:
298
         - itemId
299
         - warehouseId
300
        """
301
        try:
302
            return to_t_vendor_item_pricing(get_item_pricing(itemId, vendorId))
303
        finally:
304
            close_session()
305
 
306
 
307
    def getAllItemPricing(self, itemId):
308
        """
309
        Returns list of the pricing information of an item associated an item.
310
        Raises an exception if the item can't be found.
311
 
312
        Parameters:
313
         - itemId
314
        """
315
        try:
316
            return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]
317
        finally:
318
            close_session()
319
 
320
    def addVendorItemPricing(self, vendorItemPricing):
321
        """
322
        Adds vendor prices corresponding to the item. If pricing already exists then updates the prices. 
323
        Raises an exception if either the item or vendor can't be found corresponding to their ids.
324
 
325
        Parameters:
326
         - vendorItemPricing
327
        """
328
        log_entry(self, "updateVendorItemPricing called")
329
        try:
330
            return add_vendor_pricing(vendorItemPricing)
331
        finally:
332
            close_session()
333
 
334
    def getVendor(self, vendorId):
335
        """
336
        Return a vendor for id
337
        """
338
        try:
339
            return to_t_vendor(get_vendor(vendorId))
340
        finally:
341
            close_session()
342
 
343
 
344
    def getAllVendors(self, ):
345
        """
346
        Return list of all vendors
347
        """
348
        try:
349
            return [to_t_vendor(v) for v in get_all_vendors()]
350
        finally:
351
            close_session()
352
 
353
    def addVendorItemMapping(self, key, vendorItemMapping):
354
        """
355
        Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.
356
 
357
        Parameters:
358
         - key
359
         - vendorItemMapping
360
        """
361
        log_entry(self, "addVendorItemMapping called")
362
        try:
363
            return add_vendor_item_mapping(key, vendorItemMapping)
364
        finally:
365
            close_session()
366
 
367
    def getVendorItemMappings(self, itemId):
368
        """
369
        Returns the list of vendor item mapping corresponding to itemId passed as parameter.
370
        Raises an exception if item not found corresponding to itemId
371
 
372
        Parameters:
373
         - itemId
374
        """
375
        try:
376
            item_mappings = get_item_mappings(itemId)
377
            return [to_t_vendor_item_mapping(vim) for vim in item_mappings]
378
        finally:
379
            close_session()
380
 
381
    def isAlive(self, ):
382
        """
383
        For checking weather service is active alive or not. It also checks connectivity with database
384
        """
385
        try:
386
            return is_alive()
387
        finally:
388
            close_session()
389
 
390
    def closeSession(self, ):
391
        """
392
        For closing the open session in sqlalchemy
393
        """
394
        close_session()
395
 
396
    def addVendor(self, vendor):
397
        """
398
        add a new vendor
399
        """
400
        try:
401
            return add_vendor(vendor)
402
        finally:
403
            close_session()
404
 
405
    def getWarehouses(self, warehouseType, inventoryType, vendorId, billingWarehouseId, shippingWarehouseId):
406
        """
407
        This method returns all warehouses for a given warehosueType, inventoryType, vendor, billingWarehouse and shippingWarehouse.
408
        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
409
        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
410
        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
411
        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
412
 
413
        Parameters:
414
         - warehouseType
415
         - inventoryType
416
         - vendorId
417
         - billingWarehouseId
418
         - shippingWarehouseId
419
        """
420
        try:
421
            query = Warehouse.query
422
            if warehouseType is not None:
423
                query = query.filter_by(warehouseType = WarehouseType._VALUES_TO_NAMES[warehouseType])
424
            if inventoryType is not None:
425
                query = query.filter_by(inventoryType = InventoryType._VALUES_TO_NAMES[inventoryType])
426
            if vendorId:
427
                query = query.filter_by(vendor_id = vendorId)
428
            if billingWarehouseId:
429
                query = query.filter_by(billingWarehouseId = billingWarehouseId)
430
            if shippingWarehouseId:
431
                query = query.filter_by(shippingWarehouseId = shippingWarehouseId)
432
 
433
            return [to_t_warehouse(w) for w in query.all()]
434
        finally:
435
            close_session()
436
 
437
    def getItemKeysToBeProcessed(self, warehouseId):
438
        """
439
        Returns the list of item keys which need to be processed for a given warehouse.
440
        This is currently used by Support application to send item keys whose inventory needs
441
        to be updated from PLB
442
 
443
        Parameters:
444
         - warehouseId
445
        """
446
        try:
447
            return get_item_keys_to_be_processed(warehouseId)
448
        finally:
449
            close_session()
450
 
451
    def markMissedInventoryUpdatesAsProcessed(self, itemKey, warehouseId):
452
        """
453
        Marks/Deletes missed inventory updates for a given key and warehouse.
454
        This generally happens when updates from PLB are applied on the currentinventorysnapshot for an item
455
 
456
        Parameters:
457
         - itemKey
458
         - warehouseId
459
        """
460
        try:
461
            mark_missed_inventory_updates_as_processed(itemKey, warehouseId)
462
        finally:
463
            close_session()
464
 
465
    def resetAvailability(self, itemKey, vendorId, quantity, warehouseId):
466
        """
467
        Resets availability of an item to the quantity mentioned in a warehouse.
468
 
469
        Parameters:
470
         - itemKey
471
         - vendorId
472
         - quantity
473
         - warehouseId
474
        """
475
        try:
476
            reset_availability(itemKey, vendorId, quantity, warehouseId)
477
        finally:
478
            close_session()
479
 
480
    def resetAvailabilityForWarehouse(self, warehouseId):
481
        """
482
        Resets availability of a warehouse to zero.
483
 
484
        Parameters:
485
         - warehouseId
486
        """
487
        try:
488
            reset_availability_for_warehouse(warehouseId)
489
        finally:
490
            close_session()
491
 
492
    def getIgnoredItemKeys(self, ):
493
        """
494
        Returns all the item key mappings that have been ignored until date. Value of map has the warehouse id
495
        and the timestamp from where alert was raised.
496
        """
497
        try:
498
            itemKeysMap = {}
499
            for key in MissedInventoryUpdate.query.filter_by(isIgnored = 1).all():
500
                itemKeysMap[key.itemKey] = { key.warehouseId : to_java_date(key.timestamp) }
501
 
502
            return itemKeysMap
503
        finally:
504
            close_session()
505
 
506
    def addBadInventory(self, itemId, warehouseId, quantity):
507
        """
508
        Add the BAD type inventory to existing stock.
509
 
510
        Parameters:
511
         - itemId
512
         - warehouseId
513
         - quantity
514
        """
515
        try:
516
            add_bad_inventory(itemId, warehouseId, quantity)
517
        finally:
518
            close_session()
519
 
520
    def getShippingLocations(self, ):
521
        """
522
        Returns all shipping locations
523
        """
524
        try:
525
            return [to_t_warehouse(w) for w in get_shipping_locations()]
526
        finally:
527
            close_session()
528
 
529
    def getAllVendorItemMappings(self, ):
530
        """
531
        Fetches all the vendor item mappings present.
532
        """
533
        try:
534
            return [to_t_vendor_item_mapping(m) for m in VendorItemMapping.query.all()]
535
        finally:
536
            close_session()
537
 
538
    def getInventorySnapshot(self, warehouseId):
539
        """
540
        Gets items' inventory for a warehouse
541
        If warehouse is passed as zero, items' inventory across all warehouses is sent
542
 
543
        Parameters:
544
         - warehouseId
545
        """
546
        try:
547
            resultMap = {}
548
            itemInventoryMap = get_inventory_snapshot(warehouseId)
549
            for key, value in itemInventoryMap.items():
550
                resultMap[key] = to_t_item_inventory(value, key)
551
 
552
            return resultMap
553
        finally:
554
            close_session()
555
 
556
    def clearItemAvailabilityCache(self, ):
557
        """
558
        Clear item availability cache.
559
        """
560
        try:
561
            clear_item_availability_cache()
562
        finally:
563
            close_session()
5957 mandeep.dh 564
 
6096 amit.gupta 565
    def clearItemAvailabilityCacheForItem(self, item_id):
566
        """
567
        Clear item availability cache.
568
        """
569
        try:
570
            clear_item_availability_cache(item_id)
571
        finally:
572
            close_session()
573
 
5957 mandeep.dh 574
    def getPendingOrdersInventory(self, vendorId):
575
        """
576
        Returns a list of inventory stock for items for which there are pending orders for the given vendor.
577
        """
578
        try:
579
            pending_items_inventory = get_pending_orders_inventory(vendorId)
580
            return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in pending_items_inventory]
581
        finally:
582
            close_session()
583
 
5944 mandeep.dh 584
    def updateVendorString(self, warehouseId, vendorString):
585
        """
586
        Parameters:
587
         - warehouseId
588
         - vendorString
589
        """
590
        try:
591
            update_vendor_string(warehouseId, vendorString)
592
        finally:
593
            close_session()
7718 amar.kumar 594
    def getOurWarehouseIdForVendor(self, vendorId, billingWarehouseId):
6467 amar.kumar 595
        """
596
        Returns warehouseId for our warehouse for a vendor
597
        """    
598
        try:
7718 amar.kumar 599
            return get_our_warehouse_id_for_vendor(vendorId, billingWarehouseId)
6467 amar.kumar 600
        finally:
6531 vikram.rag 601
            close_session()
602
    def getMonitoredWarehouseForVendors(self, vendorIds):
603
        """
604
        Returns monitored warehouse ids for vendors
605
        """    
606
        try:
607
            return get_monitored_warehouses_for_vendors(vendorIds)
608
        finally:
609
            close_session()
610
    def getIgnoredWarehouseidsAndItemids(self):
611
        """
612
        Returns list of itemid and warehouseId for ignored inventory update
613
        """    
614
        try:
615
            return get_ignored_warehouseids_and_itemids()
616
        finally:
617
            close_session()
618
 
619
    def insertItemtoIgnoreInventoryUpdatelist(self,item_id,warehouse_id):
620
        """
621
        Returns list of itemid and warehouseId for ignored inventory update
622
        """
623
        try:
6532 amit.gupta 624
            return insert_item_to_ignore_inventory_update_list(item_id,warehouse_id)
6531 vikram.rag 625
        finally:
626
            close_session()     
627
    def deleteItemFromIgnoredInventoryUpdateList(self,item_id,warehouse_id):
628
        """
629
        Deletes warehouse and item entry from inventory update ignore list
630
        """
631
        try:
632
            return delete_item_from_ignore_inventory_update_list(item_id,warehouse_id)
633
        finally:
634
            close_session()
635
    def getAllIgnoredInventoryupdateItemsCount(self):
636
        """
637
        Returns all ignored inventory update item count
638
        """
6833 amar.kumar 639
        try:
640
            return get_all_ignored_inventoryupdate_items_count()
641
        finally:
642
            close_session()
6531 vikram.rag 643
 
644
 
645
    def getIgnoredInventoryUpdateItemids(self,offset,limit):
646
        """
647
        Returns all ignored inventory update items
648
        """
6833 amar.kumar 649
        try:
650
            return get_ignored_inventoryupdate_itemids(offset,limit)
651
        finally:
652
            close_session()
6821 amar.kumar 653
    def updateItemStockPurchaseParams(self, item_id, numOfDaysStock, minStockLevel):
654
        """
655
        Update/Add parameters required for heuristic purchase of Items 
6833 amar.kumar 656
        """ 
657
        try:               
658
            update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel)
659
        finally:
660
            close_session()
661
 
6821 amar.kumar 662
    def getItemStockPurchaseParams(self, item_id):
663
        """
664
        Get parameters required for heuristic purchase of Items 
6833 amar.kumar 665
        """ 
666
        try:               
667
            return to_t_item_stock_purchase_params(get_item_stock_purchase_params(item_id))
668
        finally:
669
            close_session()
670
 
6821 amar.kumar 671
    def addOosStatusForItem(self, oosStatusMap, date):
672
        """
673
        Add OOS status for Item 
674
        """
6833 amar.kumar 675
        try:
676
            add_oos_status_for_item(oosStatusMap, date)
677
        finally:
678
            close_session()
679
 
6832 amar.kumar 680
    def getOosStatusesForXDaysForItem(self, itemId, days):
681
        """
682
        Get OOSStatus Objects for "days" number of days 
683
        """
6833 amar.kumar 684
        try:
685
            return [to_t_oos_status(oos) for oos in get_oos_statuses_for_x_days_for_item(itemId, days)]
686
        finally:
6857 amar.kumar 687
            close_session()
688
 
689
    def getNonZeroItemStockPurchaseParams(self):
690
        """
691
        Get All ItemStockPurchaseParam objects where either minStockLevel or minNumOfDaysOfStock is zero 
692
        """
693
        try:
694
            return [to_t_item_stock_purchase_params(ispp) for ispp in get_non_zero_item_stock_purchase_params()]
695
        finally:
7149 amar.kumar 696
            close_session()
697
    def getBillableInventoryAndPendingOrders(self):
698
        """
699
        Returns a list of inventory stock for items for which there are pending orders or have 
700
        billable inventory.
701
        """
702
        try:
703
            items_inventory = get_billable_inventory_and_pending_orders()
704
            return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in items_inventory]
705
        finally:
7281 kshitij.so 706
            close_session()
707
 
708
    def getWarehouseName(self,warehouseId):
709
        try:
710
            name = get_warehouse_name(warehouseId)
711
            return name
712
        finally:
713
            close_session()
714
 
715
    def getAmazonInventoryForItem(self, amazonItemId):
7316 kshitij.so 716
        result = []
7281 kshitij.so 717
        try:
718
            result = get_amazon_inventory_for_item(amazonItemId)
719
            if result is not None:
720
                result = to_t_amazon_inventory_snapshot(result)
721
        except:
7316 kshitij.so 722
            return result
7281 kshitij.so 723
        finally:
724
            close_session()
725
            return result
726
 
727
    def getAllAmazonInventory(self):
728
        try:
729
            amazoninventory = []
730
            all_inventory = get_all_amazon_inventory()
731
            for inventory in all_inventory:
732
                amazoninventory.append(to_t_amazon_inventory_snapshot((inventory)))
733
            return amazoninventory                                           
734
        finally:
735
            close_session() 
736
 
737
    def addOrUpdateAmazonInventoryForItem(self, amazoninvetorysnapshot):
738
        try:
739
            return add_or_update_amazon_inventory_for_item(amazoninvetorysnapshot)
740
        finally:
6833 amar.kumar 741
            close_session()