Subversion Repositories SmartDukaan

Rev

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

Rev 3348 Rev 3355
Line 539... Line 539...
539
        item.updatedOn = current_timestamp
539
        item.updatedOn = current_timestamp
540
    session.commit()
540
    session.commit()
541
    return True
541
    return True
542
 
542
 
543
def get_item_availability_for_location(warehouse_loc, item_id):
543
def get_item_availability_for_location(warehouse_loc, item_id):
-
 
544
    """
-
 
545
    Determines the warehouse that should be used to fulfil an order for the given item.
-
 
546
    It first checks all the warehouses which are in the logistics location given by the
-
 
547
    warehouse_loc parameter. If none of the warehouses there have any inventory, then the
-
 
548
    preferred warehouse for the item is used.
-
 
549
    
-
 
550
    Returns an ordered list of size 4 with following elements in the given order:
-
 
551
    1. Logistics location of the warehouse which was finally picked up to ship the order.
-
 
552
    2. Id of the warehouse which was finally picked up.
-
 
553
    3. Inventory size in the selected warehouse.
-
 
554
    4. Expected delay added by the category manager.
-
 
555
    
-
 
556
    Parameters:
-
 
557
     - warehouse_loc
-
 
558
     - item_id
-
 
559
    """
544
    if warehouse_loc is None:
560
    if warehouse_loc is None:
545
        raise InventoryServiceException(101, "Bad Warehouse Location")
561
        raise InventoryServiceException(101, "Bad Warehouse Location")
546
    if not item_id:
562
    if not item_id:
547
        raise InventoryServiceException(101, "Bad Item id")
563
        raise InventoryServiceException(101, "Bad Item id")
548
    
564
    
549
    item = Item.get_by(id=item_id)
565
    item = Item.get_by(id=item_id)
-
 
566
    
-
 
567
    #First try all warehouses in the suggested location.
550
    warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
568
    warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
551
    warehouse_ids = [warehouse.id for warehouse in warehouses]
569
    warehouse_ids = [warehouse.id for warehouse in warehouses]
552
    warehouse_retid = -1
570
    warehouse_retid = -1
553
    global_availability = 0
571
    global_availability = 0
554
    for warehouse_id in warehouse_ids:
572
    for warehouse_id in warehouse_ids:
Line 559... Line 577...
559
            availability = 0    
577
            availability = 0    
560
        if availability > global_availability:
578
        if availability > global_availability:
561
            warehouse_retid = warehouse_id
579
            warehouse_retid = warehouse_id
562
            global_availability = availability
580
            global_availability = availability
563
    
581
    
-
 
582
    #If no warehouse could be found, use the preferred warehouse for this item
564
    if warehouse_retid == -1:
583
    if warehouse_retid == -1:
565
        # This is the case when all warehouses have exhausted their
584
        # This is the case when all warehouses have exhausted their
566
        # inventory of this item or no warehouse is available in this
585
        # inventory of this item or no warehouse is available in this
567
        # location.
586
        # location.
568
        warehouse_retid = int(item.preferredWarehouse)
587
        warehouse_retid = int(item.preferredWarehouse)
Line 571... Line 590...
571
            current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_retid, item_id = item_id).one()
590
            current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_retid, item_id = item_id).one()
572
            global_availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
591
            global_availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
573
        except:
592
        except:
574
            global_availability = 0
593
            global_availability = 0
575
 
594
 
576
    return [warehouse.logisticsLocation, warehouse_retid, global_availability]
595
    return [warehouse.logisticsLocation, warehouse_retid, global_availability, item.expectedDelay]
577
 
596
 
578
def get_warehouses_for_item(item_id):
597
def get_warehouses_for_item(item_id):
579
    
598
    
580
    if not item_id:
599
    if not item_id:
581
        raise InventoryServiceException(101, "bad item_id")
600
        raise InventoryServiceException(101, "bad item_id")