Subversion Repositories SmartDukaan

Rev

Rev 635 | Rev 723 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 635 Rev 643
Line 369... Line 369...
369
    if not current_inventory_snapshot:
369
    if not current_inventory_snapshot:
370
        return 0
370
        return 0
371
    else:
371
    else:
372
        return current_inventory_snapshot.availibility
372
        return current_inventory_snapshot.availibility
373
    """
373
    """
-
 
374
    
-
 
375
def get_item_availability_for_location(warehouse_loc, item_id):
-
 
376
    if warehouse_loc is None:
-
 
377
        raise InventoryServiceException(101, "Bad Warehouse Location")
-
 
378
    if not item_id:
-
 
379
        raise InventoryServiceException(101, "Bas Item id")
-
 
380
    
-
 
381
    warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
-
 
382
    warehouse_ids = [warehouse.id for warehouse in warehouses]
-
 
383
    warehouse_retid = -1
-
 
384
    global_availability = 0
-
 
385
    for warehouse_id in warehouse_ids:
-
 
386
        availability = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one().availibility
-
 
387
        if availability > global_availability:
-
 
388
            warehouse_retid = warehouse_id
-
 
389
            global_availability = availability
-
 
390
    if warehouse_retid == -1:
-
 
391
        #This is the case when all warehouses have exhausted their inventory of this item.
-
 
392
        #TODO: Change 1 to be a constant read from the Config client.
-
 
393
        warehouse_retid = 1
-
 
394
    return [warehouse_retid, global_availability]
-
 
395
 
374
def get_warehouses_for_item(item_id):
396
def get_warehouses_for_item(item_id):
-
 
397
    
375
    if not item_id:
398
    if not item_id:
376
        raise InventoryServiceException(101, "bad item_id")
399
        raise InventoryServiceException(101, "bad item_id")
377
    item = get_item(item_id)
400
    item = get_item(item_id)
378
    
401
    
379
    if not item:
402
    if not item: