Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
94 ashish 1
'''
2
Created on 23-Mar-2010
3
 
4
@author: ashish
5
'''
6
from elixir import *
7
from shop2020.model.v1.catalog.impl import DataService
122 ashish 8
from shop2020.model.v1.catalog.impl.DataService import Item, \
103 ashish 9
    Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
1368 chandransh 10
    ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
11
    VendorItemMapping
122 ashish 12
from shop2020.thriftpy.model.v1.catalog.ttypes import \
13
    InventoryServiceException, status
602 chandransh 14
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
94 ashish 15
import datetime
871 chandransh 16
import sys
602 chandransh 17
from shop2020.utils.Utils import log_entry, to_py_date
621 chandransh 18
from sqlalchemy import desc, asc
94 ashish 19
 
20
 
21
def initialize():
22
    DataService.initialize()
23
 
24
 
103 ashish 25
def get_all_items(is_active):
26
    if is_active:
766 rajveer 27
        items = Item.query.filter_by(status= status.ACTIVE).all()
103 ashish 28
    else:
766 rajveer 29
        items = Item.query.all()
30
    return items
31
 
103 ashish 32
def get_all_items_by_status(status):
33
    if not status:
34
        #return all items
766 rajveer 35
        items = get_all_items(False)
103 ashish 36
    else:
766 rajveer 37
        items = Item.query.filter_by(status=status).all()
38
    return items
103 ashish 39
 
635 rajveer 40
def get_item(item_id):
766 rajveer 41
    item = Item.get_by(id=item_id)
42
    return item
94 ashish 43
 
635 rajveer 44
def get_items_by_catalog_id(catalog_id):
447 rajveer 45
    query = Item.query.filter_by(catalog_item_id=catalog_id)
437 rajveer 46
    try:
635 rajveer 47
        items = query.all()
48
        return get_thrift_item_list(items)
1399 rajveer 49
    except Exception as ex:
50
        print ex
437 rajveer 51
        raise InventoryServiceException(109, "Item not found")
52
 
576 chandransh 53
def is_active(item_id):
54
    try:
635 rajveer 55
        item = get_item(item_id)
576 chandransh 56
        return item.status == status.ACTIVE
57
    except InventoryServiceException:
58
        return False
563 chandransh 59
 
94 ashish 60
def get_Warehouse(warehouse_id):
61
    return Warehouse.get_by(id=warehouse_id)
62
 
122 ashish 63
def get_all_warehouses_by_status(status):
64
    if not status:
766 rajveer 65
        warehouses = Warehouse.query.all()
122 ashish 66
    else:
851 chandransh 67
        warehouses = Warehouse.query.filter_by(status=status).all()
68
    return warehouses
122 ashish 69
 
94 ashish 70
def get_all_warehouses_for_item(item_id):
635 rajveer 71
    item = get_item(item_id)
94 ashish 72
    if not item:
122 ashish 73
        raise InventoryServiceException(108, "Some unforeseen error while obtaining item")
74
    return item.get_all_warehouses
94 ashish 75
 
122 ashish 76
def get_all_items_for_warehouse(warehouse_id):
77
    warehouse = get_Warehouse(warehouse_id)
78
    if not warehouse:
79
        raise InventoryServiceException(108, "bad warehouse")
80
    return warehouse.all_items
81
 
94 ashish 82
def add_warehouse(warehouse):
103 ashish 83
    if not warehouse:
122 ashish 84
        raise InventoryServiceException(108, "Bad warehouse")
103 ashish 85
    if get_Warehouse(warehouse.id):
86
        #warehouse is already present.
122 ashish 87
        raise InventoryServiceException(101, "Warehouse already present")
103 ashish 88
 
94 ashish 89
    ds_warehouse = Warehouse()
90
    ds_warehouse.id = warehouse.id
91
    ds_warehouse.location = warehouse.location
122 ashish 92
    ds_warehouse.status = status.ACTIVE
103 ashish 93
    ds_warehouse.addedOn = datetime.datetime.now()
483 rajveer 94
    ds_warehouse.lastCheckedOn = datetime.datetime.now()
95
    ds_warehouse.tinNumber = warehouse.tinNumber
96
    ds_warehouse.pincode = warehouse.pincode
97
    if warehouse.vendorString:
98
        ds_warehouse.vendorString = warehouse.vendorString
94 ashish 99
    session.commit()
103 ashish 100
    return ds_warehouse.id
94 ashish 101
 
122 ashish 102
def update_item(item):
103
    if not item:
104
        raise InventoryServiceException(108, "Bad item in request")
105
 
106
    if not item.id:
609 chandransh 107
        raise InventoryServiceException(101, "Missing id for update")
122 ashish 108
 
635 rajveer 109
    ds_item = get_item(item.id)
122 ashish 110
 
111
    if not ds_item:
609 chandransh 112
        raise InventoryServiceException(101, "Item missing in our database")
122 ashish 113
 
963 chandransh 114
    if item.productGroup:
115
        ds_item.product_group = item.productGroup 
116
    if item.brand:
117
        ds_item.brand = item.brand
511 rajveer 118
    if item.modelName:
119
        ds_item.model_name = item.modelName
120
    if item.modelNumber:
121
        ds_item.model_number = item.modelNumber
609 chandransh 122
    if item.color:
123
        ds_item.color = item.color
483 rajveer 124
    if item.category:
125
        ds_item.category = item.category
126
    if item.comments:
127
        ds_item.comments = item.comments
511 rajveer 128
 
122 ashish 129
    if item.catalogItemId:
130
        ds_item.catalog_item_id = item.catalogItemId
483 rajveer 131
 
132
    if item.mrp:
133
        ds_item.mrp = item.mrp
134
    if item.mop:
135
        ds_item.mop = item.mop
136
    if item.sellingPrice:
137
        ds_item.sellingPrice = item.sellingPrice
609 chandransh 138
    if item.dealerPrice:
139
        ds_item.dealerPrice = item.dealerPrice
122 ashish 140
    if item.weight:
141
        ds_item.weight = item.weight
511 rajveer 142
    if item.itemStatus:
143
        ds_item.status = item.itemStatus
122 ashish 144
 
511 rajveer 145
    if item.startDate:
146
        ds_item.startDate = item.startDate
147
    if item.retireDate:
148
        ds_item.retireDate = item.retireDate
149
 
122 ashish 150
    if item.featureId:
151
        ds_item.feature_id = item.featureId
152
    if item.featureDescription:
153
        ds_item.feature_description = item.featureDescription
154
 
609 chandransh 155
    if item.bestDealText:
156
        ds_item.bestDealText = item.bestDealText
157
    if item.bestDealValue:
158
        ds_item.bestDealValue = item.bestDealValue
159
 
160
    ds_item.updated_on = datetime.datetime.now()
122 ashish 161
    session.commit();
162
    return ds_item.id
94 ashish 163
 
103 ashish 164
def add_item(item):
165
    if not item:
122 ashish 166
        raise InventoryServiceException(108, "Bad item in request")
635 rajveer 167
    if get_item(item.id):
122 ashish 168
        raise InventoryServiceException(101, "Item already exists")
483 rajveer 169
 
103 ashish 170
    ds_item = Item()
122 ashish 171
    if item.id:
172
        ds_item.id = item.id
963 chandransh 173
    if item.productGroup:
174
        ds_item.product_group = item.productGroup
175
    if item.brand:
176
        ds_item.brand = item.brand
515 rajveer 177
    if item.modelName:
178
        ds_item.model_name = item.modelName
179
    if item.modelNumber:
180
        ds_item.model_number = item.modelNumber
609 chandransh 181
    if item.color:
182
        ds_item.color = item.color
483 rajveer 183
    if item.category:
184
        ds_item.category = item.category
185
    if item.comments:
186
        ds_item.comments = item.comments
187
 
122 ashish 188
    if item.catalogItemId:
189
        ds_item.catalog_item_id = item.catalogItemId
190
    if item.itemStatus:
191
        ds_item.status = item.itemStatus
192
    else: #this is for update calls
193
        ds_item.status = status.IN_PROCESS
103 ashish 194
    ds_item.addedOn = datetime.datetime.now()
609 chandransh 195
    ds_item.updatedOn = datetime.datetime.now()
196
 
483 rajveer 197
    if item.mrp:
198
        ds_item.mrp = item.mrp
199
    if item.mop:
200
        ds_item.mop = item.mop
201
    if item.sellingPrice:
202
        ds_item.sellingPrice = item.sellingPrice
609 chandransh 203
    if item.dealerPrice:
204
        ds_item.dealerPrice = item.dealerPrice
122 ashish 205
    if item.weight:
206
        ds_item.weight = item.weight
207
 
208
    if item.featureId:
209
        ds_item.feature_id = item.featureId
210
    if item.featureDescription:
211
        ds_item.feature_description = item.featureDescription
212
 
103 ashish 213
    if item.otherInfo:
214
        for k,v in item.otherInfo.iteritems():
215
            info = ItemInfo()
216
            info.key = k
217
            info.value = v
218
            ds_item.iteminfo.append(info)
219
    #check if categories present. If yes, add them to system
122 ashish 220
 
609 chandransh 221
    if item.bestDealValue:
222
        ds_item.bestDealValue = item.bestDealValue
223
    if item.bestDealText:
224
        ds_item.bestDealText = item.bestDealText
225
 
103 ashish 226
    session.commit();
609 chandransh 227
    return ds_item.id       
103 ashish 228
 
483 rajveer 229
def update_inventory(warehouse_id, timestamp, availability):
230
    warehouse = get_Warehouse(warehouse_id)
231
    if not warehouse:
232
        raise InventoryServiceException(107, "Warehouse? Where?")
233
 
234
    time = datetime.datetime.now()
235
    warehouse.lastCheckedOn = time
236
    warehouse.vendorString = timestamp
1368 chandransh 237
    vendor = warehouse.vendor
483 rajveer 238
 
1368 chandransh 239
    for item_key, quantity in availability.iteritems():
483 rajveer 240
        try:
1368 chandransh 241
            vendor_item_mapping = VendorItemMapping.query.filter_by(vendor=vendor, item_key=item_key).one();
242
            item = vendor_item_mapping.item
494 rajveer 243
        except:
244
            continue  
245
        try:
483 rajveer 246
            item_inventory_history = ItemInventoryHistory()
247
            item_inventory_history.warehouse = warehouse
248
            item_inventory_history.item = item
249
            item_inventory_history.timestamp = time
250
            item_inventory_history.availibility = quantity
251
 
252
            current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
253
            if not current_inventory_snapshot:
254
                current_inventory_snapshot = CurrentInventorySnapshot()
255
                current_inventory_snapshot.item = item
256
                current_inventory_snapshot.warehouse = warehouse
257
                current_inventory_snapshot.availibility = 0
871 chandransh 258
                current_inventory_snapshot.reserved = 0
483 rajveer 259
            # added the difference in the current inventory    
260
            current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
261
        except:
262
            raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
263
    session.commit() 
264
 
94 ashish 265
def get_item_inventoy(item_id):
266
 
267
    inventory = Item.get_by(id=item_id).currentInventory
268
    if not inventory:
122 ashish 269
        raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
94 ashish 270
    return inventory
271
 
635 rajveer 272
def get_item_inventory_by_item_id(item_id):
273
    inventory = Item.get_by(id=item_id).currentInventory
379 ashish 274
    if not inventory:
275
        raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
276
    return inventory
277
 
103 ashish 278
 
279
def retire_warehouse(warehouse_id):
280
    if not warehouse_id:
122 ashish 281
        raise InventoryServiceException(101, "Bad warehouse id")
103 ashish 282
    warehouse = get_Warehouse(warehouse_id)
283
    if not warehouse:
122 ashish 284
        raise InventoryServiceException(108, "warehouse id not present")
285
    warehouse.status = status.DELETED;
103 ashish 286
    session.commit()
287
 
288
def retire_item(item_id):
289
    if not item_id:
122 ashish 290
        raise InventoryServiceException(101, "bad item id")
635 rajveer 291
    item = get_item(item_id)
103 ashish 292
    if not item:
122 ashish 293
        raise InventoryServiceException(108, "item id not present")
294
    item.status = status.PHASED_OUT
295
    item.retireDate = datetime.datetime.now()
103 ashish 296
    session.commit()
122 ashish 297
 
298
#need to implement threads based solution here
103 ashish 299
def start_item_on(item_id, timestamp):
300
    if not item_id:
122 ashish 301
        raise InventoryServiceException(101, "bad item id")
635 rajveer 302
    item = get_item(item_id)
103 ashish 303
    if not item:
122 ashish 304
        raise InventoryServiceException(108, "item id not present")
103 ashish 305
 
122 ashish 306
    item.status = status.ACTIVE
307
    item.startDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
308
    add_status_change_log(item, status.ACTIVE)
103 ashish 309
    session.commit()
310
 
122 ashish 311
#need to implement threads here
103 ashish 312
def retire_item_on(item_id, timestamp):
313
    if not item_id:
122 ashish 314
        raise InventoryServiceException(101, "bad item id")
635 rajveer 315
    item = get_item(item_id)
103 ashish 316
    if not item:
122 ashish 317
        raise InventoryServiceException(108, "item id not present")
103 ashish 318
 
122 ashish 319
    item.status = status.PHASED_OUT
320
    item.retireDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
321
    add_status_change_log(item, status.PHASED_OUT)
103 ashish 322
    session.commit()
323
 
324
def add_status_change_log(item, new_status):
325
    item_change_log = ItemChangeLog()
326
    item_change_log.new_status = new_status
327
    item_change_log.old_status = item.status
328
    item_change_log.timestamp = datetime.datetime.now()
329
    item_change_log.item = item
330
    session.commit()
331
 
332
def change_item_status(item_id, new_status):
333
    if not item_id:
122 ashish 334
        raise InventoryServiceException(101, "bad item id")
635 rajveer 335
    item = get_item(item_id)
103 ashish 336
    if not item:
122 ashish 337
        raise InventoryServiceException(108, "item id not present")
103 ashish 338
 
122 ashish 339
    item.status = new_status
340
    add_status_change_log(item, new_status)
103 ashish 341
    session.commit()
342
 
343
def get_item_availability_for_warehouse(warehouse_id, item_id):
344
    if not warehouse_id:
122 ashish 345
        raise InventoryServiceException(101, "bad warehouse_id")
103 ashish 346
    if not item_id:
122 ashish 347
        raise InventoryServiceException(101, "bad item_id")
103 ashish 348
 
349
    warehouse = get_Warehouse(warehouse_id)
350
    if not warehouse:
122 ashish 351
        raise InventoryServiceException(108, "warehouse does not exist")
635 rajveer 352
    item = get_item(item_id)
504 rajveer 353
 
103 ashish 354
    if not item:
766 rajveer 355
        raise InventoryServiceException(108, "item does not exist")
122 ashish 356
 
494 rajveer 357
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id)
504 rajveer 358
    query = query.filter_by(item_id = item.id)
494 rajveer 359
    try:
360
        current_inventory_snapshot = query.one()
871 chandransh 361
        return current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
494 rajveer 362
    except:
363
        return 0
364
    """
365
    current_inventory_snapshot = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id == warehouse_id, CurrentInventorySnapshot.item_id == item_id).one()
103 ashish 366
    if not current_inventory_snapshot:
367
        return 0
368
    else:
369
        return current_inventory_snapshot.availibility
494 rajveer 370
    """
643 chandransh 371
 
871 chandransh 372
def reserve_item_in_warehouse(item_id, warehouse_id, quantity):    
373
    if not warehouse_id:
374
        raise InventoryServiceException(101, "bad warehouse_id")
375
    if not item_id:
376
        raise InventoryServiceException(101, "bad item_id")
377
 
378
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
379
    try:
380
        current_inventory_snapshot = query.one()
381
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved + quantity
382
        session.commit()
383
        return True
384
    except:
385
        print "Unexpected error:", sys.exc_info()[0]
386
        return False
387
 
388
def reduce_reservation_count(item_id, warehouse_id, quantity):
389
    if not warehouse_id:
390
        raise InventoryServiceException(101, "bad warehouse_id")
391
    if not item_id:
392
        raise InventoryServiceException(101, "bad item_id")
393
 
394
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
395
    try:
396
        current_inventory_snapshot = query.one()
397
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
398
        session.commit()
399
        return True
400
    except:
401
        print "Unexpected error:", sys.exc_info()[0]
402
        return False
403
 
723 chandransh 404
def mark_item_as_content_complete(entity_id):
405
    content_complete_status = status.CONTENT_COMPLETE
1294 chandransh 406
    items = Item.query.filter_by(catalog_item_id=entity_id, status=status.IN_PROCESS).all()
723 chandransh 407
    current_timestamp = datetime.datetime.now()
408
    for item in items:
409
        item_change_log = ItemChangeLog()
410
        item_change_log.old_status = item.status
411
        item_change_log.new_status = content_complete_status
412
        item_change_log.timestamp = current_timestamp
413
        item_change_log.item = item
414
 
415
        item.status = content_complete_status
416
        item.updatedOn = current_timestamp
417
    session.commit()
418
    return True
1294 chandransh 419
 
643 chandransh 420
def get_item_availability_for_location(warehouse_loc, item_id):
421
    if warehouse_loc is None:
422
        raise InventoryServiceException(101, "Bad Warehouse Location")
423
    if not item_id:
424
        raise InventoryServiceException(101, "Bas Item id")
425
 
426
    warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
427
    warehouse_ids = [warehouse.id for warehouse in warehouses]
428
    warehouse_retid = -1
429
    global_availability = 0
430
    for warehouse_id in warehouse_ids:
785 rajveer 431
        try:
871 chandransh 432
            current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one()
433
            availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
785 rajveer 434
        except:
435
            availability = 0    
643 chandransh 436
        if availability > global_availability:
437
            warehouse_retid = warehouse_id
438
            global_availability = availability
439
    if warehouse_retid == -1:
759 chandransh 440
        # This is the case when all warehouses have exhausted their
441
        # inventory of this item or no warehouse is available in this
442
        # location.
643 chandransh 443
        #TODO: Change 1 to be a constant read from the Config client.
444
        warehouse_retid = 1
445
    return [warehouse_retid, global_availability]
446
 
122 ashish 447
def get_warehouses_for_item(item_id):
643 chandransh 448
 
122 ashish 449
    if not item_id:
450
        raise InventoryServiceException(101, "bad item_id")
635 rajveer 451
    item = get_item(item_id)
122 ashish 452
 
453
    if not item:
454
        raise InventoryServiceException(101, "bad item")
455
 
483 rajveer 456
    warehouses = item.currentInventory.warehouse
501 rajveer 457
    return warehouses
458
 
626 chandransh 459
def get_best_sellers(start_index, stop_index, category=-1):
621 chandransh 460
    query = get_best_sellers_query(category)
1098 chandransh 461
    best_sellers = query.all()[start_index:stop_index]
621 chandransh 462
    return get_thrift_item_list(best_sellers)
463
 
464
def get_best_sellers_count(category):
1120 rajveer 465
    count = get_best_sellers_query(category).count()
466
    if count is None:
467
        count = 0
766 rajveer 468
    return count
621 chandransh 469
 
626 chandransh 470
def get_best_sellers_catalog_ids(start_index, stop_index, category=-1):
621 chandransh 471
    query = get_best_sellers_query(category)
1098 chandransh 472
    best_sellers = query.all()[start_index:stop_index]
621 chandransh 473
    return [item.catalog_item_id for item in best_sellers]
501 rajveer 474
 
621 chandransh 475
def get_best_sellers_query(category):
1098 chandransh 476
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
626 chandransh 477
    if category != -1:
621 chandransh 478
        query = query.filter_by(category=category)
1098 chandransh 479
    query = query.order_by(asc(Item.bestSellingRank))
621 chandransh 480
    return query
609 chandransh 481
 
1098 chandransh 482
def get_best_deals(category=-1):
483
    query = get_best_deals_query(category)
484
    items = query.all()
609 chandransh 485
    return get_thrift_item_list(items)
486
 
1098 chandransh 487
def get_best_deals_count(category=-1):
1120 rajveer 488
    count = get_best_deals_query(category).count()
489
    if count is None:
490
        count = 0
766 rajveer 491
    return count
501 rajveer 492
 
626 chandransh 493
def get_best_deals_catalog_ids(start_index, stop_index, category=-1):
1098 chandransh 494
    query = get_best_deals_query(category)
495
    best_deal_items = query.all()[start_index:stop_index]
496
    return [item.catalog_item_id for item in best_deal_items]
497
 
498
def get_best_deals_query(category):
499
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
626 chandransh 500
    if category != -1:
621 chandransh 501
        query = query.filter_by(category=category)
1098 chandransh 502
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
503
    return query
609 chandransh 504
 
1098 chandransh 505
def get_latest_arrivals(limit, category=-1):
506
    query = get_latest_arrivals_query(category)
507
    items = query.all()[0:limit]
609 chandransh 508
    return get_thrift_item_list(items)
598 chandransh 509
 
1098 chandransh 510
def get_latest_arrivals_count(limit, category=-1):
1120 rajveer 511
    count = get_latest_arrivals_query(category).count()
512
    if count is None:
513
        count = 0
514
    count = min(count, limit)
766 rajveer 515
    return count
602 chandransh 516
 
626 chandransh 517
def get_latest_arrivals_catalog_ids(start_index, stop_index, category=-1):
1098 chandransh 518
    query = get_latest_arrivals_query(category)
519
    latest_arrivals = query.all()[start_index:stop_index]
520
    return [item.catalog_item_id for item in latest_arrivals]
521
 
522
def get_latest_arrivals_query(category):
523
    query = Item.query.filter_by(status=status.ACTIVE)
626 chandransh 524
    if category != -1:
621 chandransh 525
        query = query.filter_by(category=category)
1098 chandransh 526
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
527
    return query
609 chandransh 528
 
529
def get_thrift_item_list(items):
1098 chandransh 530
    return [to_t_item(item) for item in items if item != None]
635 rajveer 531
 
1155 rajveer 532
def generate_new_entity_id():
533
    generator =  EntityIDGenerator.query.one()
534
    id = generator.id + 1
535
    generator.id = id
536
    session.commit()
537
    return id
538
 
635 rajveer 539
def put_category_object(object):
540
    category = Category.get_by(id=1)
541
    if category is None:
542
        category = Category()
543
    category.object = object    
544
    session.commit()
545
    return True
546
 
547
def get_category_object():
766 rajveer 548
    object = Category.get_by(id=1).object
549
    return object
550
 
1341 chandransh 551
def get_item_pricing(item_id, warehouse_id):
552
    item = Item.query.filter_by(id=item_id).first()
553
    if item is None:
554
        raise InventoryServiceException(101, "Bad Item")
555
 
556
    warehouse = get_Warehouse(warehouse_id)
557
    if not warehouse:
558
        raise InventoryServiceException(108, "Bad Warehouse")
559
    vendor = warehouse.vendor
560
 
561
    try:
562
        item_pricing = VendorItemPricing.query.filter_by(vendor=vendor, item=item).one()
1347 chandransh 563
        return item_pricing
1341 chandransh 564
    except sqlalchemy.orm.exc.MultipleResultsFound:
565
        raise InventoryServiceException(110, "Multiple pricing information present for Vendor: " + vendor.name + " and Item: " + str(item_id))
566
    except sqlalchemy.orm.exc.NoResultFound:
567
        raise InventoryServiceException(111, "Missing pricing information for Vendor: " + vendor.name + " and Item: " + str(item_id))
568
 
766 rajveer 569
def close_session():
570
    if session.is_active:
571
        print "session is active. closing it."
1399 rajveer 572
        session.close()