| Line 571... |
Line 571... |
| 571 |
|
571 |
|
| 572 |
#First try all warehouses in the suggested location.
|
572 |
#First try all warehouses in the suggested location.
|
| 573 |
warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
|
573 |
warehouses = Warehouse.query.filter_by(logisticsLocation=warehouse_loc).all()
|
| 574 |
warehouse_ids = [warehouse.id for warehouse in warehouses]
|
574 |
warehouse_ids = [warehouse.id for warehouse in warehouses]
|
| 575 |
warehouse_retid = -1
|
575 |
warehouse_retid = -1
|
| - |
|
576 |
max_availability = 0
|
| 576 |
global_availability = 0
|
577 |
total_availability = 0
|
| 577 |
for warehouse_id in warehouse_ids:
|
578 |
for warehouse_id in warehouse_ids:
|
| 578 |
try:
|
579 |
try:
|
| 579 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one()
|
580 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one()
|
| 580 |
availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
581 |
availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
| 581 |
except:
|
582 |
except:
|
| 582 |
availability = 0
|
583 |
availability = 0
|
| 583 |
if availability > global_availability:
|
584 |
if availability > max_availability:
|
| 584 |
warehouse_retid = warehouse_id
|
585 |
warehouse_retid = warehouse_id
|
| 585 |
global_availability = availability
|
586 |
max_availability = availability
|
| - |
|
587 |
total_availability = total_availability + availability
|
| 586 |
|
588 |
|
| 587 |
#If no warehouse could be found, use the preferred warehouse for this item
|
589 |
#If no warehouse could be found, use the preferred warehouse for this item
|
| 588 |
if warehouse_retid == -1:
|
590 |
if warehouse_retid == -1:
|
| 589 |
# This is the case when all warehouses have exhausted their
|
591 |
# This is the case when all warehouses have exhausted their
|
| 590 |
# inventory of this item or no warehouse is available in this
|
592 |
# inventory of this item or no warehouse is available in this
|
| 591 |
# location.
|
593 |
# location.
|
| 592 |
warehouse_retid = int(item.preferredWarehouse)
|
594 |
warehouse_retid = int(item.preferredWarehouse)
|
| 593 |
warehouse = Warehouse.get_by(id=warehouse_retid)
|
595 |
warehouse = Warehouse.get_by(id=warehouse_retid)
|
| 594 |
try:
|
596 |
try:
|
| 595 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_retid, item_id = item_id).one()
|
597 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_retid, item_id = item_id).one()
|
| 596 |
global_availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
598 |
max_availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
| 597 |
except:
|
599 |
except:
|
| 598 |
global_availability = 0
|
600 |
max_availability = 0
|
| - |
|
601 |
total_availability = max_availability
|
| 599 |
|
602 |
|
| 600 |
return [warehouse.logisticsLocation, warehouse_retid, global_availability, item.expectedDelay]
|
603 |
return [warehouse.logisticsLocation, warehouse_retid, total_availability, item.expectedDelay]
|
| 601 |
|
604 |
|
| 602 |
def get_warehouses_for_item(item_id):
|
605 |
def get_warehouses_for_item(item_id):
|
| 603 |
|
606 |
|
| 604 |
if not item_id:
|
607 |
if not item_id:
|
| 605 |
raise InventoryServiceException(101, "bad item_id")
|
608 |
raise InventoryServiceException(101, "bad item_id")
|