| Line 439... |
Line 439... |
| 439 |
warehouses = {}
|
439 |
warehouses = {}
|
| 440 |
ourGoodWarehouses = {}
|
440 |
ourGoodWarehouses = {}
|
| 441 |
thirdpartyWarehouses = {}
|
441 |
thirdpartyWarehouses = {}
|
| 442 |
preferredThirdpartyWarehouses = {}
|
442 |
preferredThirdpartyWarehouses = {}
|
| 443 |
for warehouse in Warehouse.query.all():
|
443 |
for warehouse in Warehouse.query.all():
|
| 444 |
if warehouse.id in ignoredWhs:
|
- |
|
| 445 |
continue
|
- |
|
| 446 |
if (warehouse.inventoryType == InventoryType._VALUES_TO_NAMES[InventoryType.BAD]):
|
444 |
if (warehouse.inventoryType == InventoryType._VALUES_TO_NAMES[InventoryType.BAD]):
|
| 447 |
continue
|
445 |
continue
|
| 448 |
warehouses[warehouse.id] = warehouse
|
446 |
warehouses[warehouse.id] = warehouse
|
| 449 |
if warehouse.warehouseType == WarehouseType._VALUES_TO_NAMES[WarehouseType.OURS]:
|
447 |
if warehouse.warehouseType == WarehouseType._VALUES_TO_NAMES[WarehouseType.OURS]:
|
| 450 |
if warehouse.inventoryType == InventoryType._VALUES_TO_NAMES[InventoryType.GOOD]:
|
448 |
if warehouse.inventoryType == InventoryType._VALUES_TO_NAMES[InventoryType.GOOD]:
|
| Line 455... |
Line 453... |
| 455 |
preferredThirdpartyWarehouses[warehouse.id] = warehouse
|
453 |
preferredThirdpartyWarehouses[warehouse.id] = warehouse
|
| 456 |
|
454 |
|
| 457 |
warehouse_retid = -1
|
455 |
warehouse_retid = -1
|
| 458 |
total_availability = 0
|
456 |
total_availability = 0
|
| 459 |
|
457 |
|
| 460 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_price(ourGoodWarehouses, item_id, item_pricing, False)
|
458 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_price(ourGoodWarehouses, ignoredWhs, item_id, item_pricing, False)
|
| 461 |
if warehouse_retid == -1:
|
459 |
if warehouse_retid == -1:
|
| 462 |
if item.preferredVendor and item.isWarehousePreferenceSticky:
|
460 |
if item.preferredVendor and item.isWarehousePreferenceSticky:
|
| 463 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_delay(preferredThirdpartyWarehouses, item_id, item_pricing)
|
461 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_delay(preferredThirdpartyWarehouses, ignoredWhs, item_id, item_pricing)
|
| 464 |
if warehouse_retid == -1:
|
462 |
if warehouse_retid == -1:
|
| 465 |
warehouse_retid = preferredThirdpartyWarehouses.keys()[0]
|
463 |
warehouse_retid = preferredThirdpartyWarehouses.keys()[0]
|
| 466 |
else:
|
464 |
else:
|
| 467 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_delay(thirdpartyWarehouses, item_id, item_pricing)
|
465 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_delay(thirdpartyWarehouses, ignoredWhs, item_id, item_pricing)
|
| 468 |
if warehouse_retid == -1:
|
466 |
if warehouse_retid == -1:
|
| 469 |
if item.preferredVendor:
|
467 |
if item.preferredVendor:
|
| 470 |
warehouse_retid = preferredThirdpartyWarehouses.keys()[0]
|
468 |
warehouse_retid = preferredThirdpartyWarehouses.keys()[0]
|
| 471 |
else:
|
469 |
else:
|
| 472 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_price(thirdpartyWarehouses, item_id, item_pricing, True)
|
470 |
[warehouse_retid, total_availability] = __get_warehouse_with_min_transfer_price(thirdpartyWarehouses, ignoredWhs, item_id, item_pricing, True)
|
| 473 |
|
471 |
|
| 474 |
warehouse = warehouses[warehouse_retid]
|
472 |
warehouse = warehouses[warehouse_retid]
|
| 475 |
billingWarehouseId = warehouse.billingWarehouseId
|
473 |
billingWarehouseId = warehouse.billingWarehouseId
|
| 476 |
|
474 |
|
| 477 |
# Fetching billing warehouse of a Good billable warehouse corresponding to the virtual one
|
475 |
# Fetching billing warehouse of a Good billable warehouse corresponding to the virtual one
|
| Line 509... |
Line 507... |
| 509 |
item_availability_cache.billingWarehouseId = billingWarehouseId
|
507 |
item_availability_cache.billingWarehouseId = billingWarehouseId
|
| 510 |
item_availability_cache.sellingPrice = item.sellingPrice
|
508 |
item_availability_cache.sellingPrice = item.sellingPrice
|
| 511 |
item_availability_cache.totalAvailability = total_availability
|
509 |
item_availability_cache.totalAvailability = total_availability
|
| 512 |
session.commit()
|
510 |
session.commit()
|
| 513 |
|
511 |
|
| 514 |
def __get_warehouse_with_min_transfer_price(warehouses, item_id, item_pricing, ignoreAvailability):
|
512 |
def __get_warehouse_with_min_transfer_price(warehouses, ignoredWhs, item_id, item_pricing, ignoreAvailability):
|
| 515 |
warehouse_retid = -1
|
513 |
warehouse_retid = -1
|
| 516 |
minTransferPrice = None
|
514 |
minTransferPrice = None
|
| 517 |
total_availability = 0
|
515 |
total_availability = 0
|
| 518 |
availabilityForBillingWarehouses = {}
|
516 |
availabilityForBillingWarehouses = {}
|
| 519 |
warehousesAvailability = {}
|
517 |
warehousesAvailability = {}
|
| Line 523... |
Line 521... |
| 523 |
if not ignoreAvailability:
|
521 |
if not ignoreAvailability:
|
| 524 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
522 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
| 525 |
#if entry.availability > entry.reserved:
|
523 |
#if entry.availability > entry.reserved:
|
| 526 |
warehousesAvailability[entry.warehouse_id] = entry
|
524 |
warehousesAvailability[entry.warehouse_id] = entry
|
| 527 |
|
525 |
|
| - |
|
526 |
if len(ignoredWhs) > 0:
|
| - |
|
527 |
for whid in ignoredWhs:
|
| - |
|
528 |
if warehousesAvailability.has_key(whid):
|
| - |
|
529 |
warehousesAvailability[whid].availability = 0
|
| - |
|
530 |
|
| 528 |
for warehouse in warehouses.values():
|
531 |
for warehouse in warehouses.values():
|
| 529 |
if not ignoreAvailability:
|
532 |
if not ignoreAvailability:
|
| 530 |
#TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
533 |
#TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
| 531 |
if warehouse.id not in warehousesAvailability:
|
534 |
if warehouse.id not in warehousesAvailability:
|
| 532 |
continue
|
535 |
continue
|
| Line 556... |
Line 559... |
| 556 |
else:
|
559 |
else:
|
| 557 |
availability = total_availability
|
560 |
availability = total_availability
|
| 558 |
|
561 |
|
| 559 |
return [warehouse_retid, availability]
|
562 |
return [warehouse_retid, availability]
|
| 560 |
|
563 |
|
| 561 |
def __get_warehouse_with_min_transfer_delay(warehouses, item_id, item_pricing):
|
564 |
def __get_warehouse_with_min_transfer_delay(warehouses, ignoredWhs, item_id, item_pricing):
|
| 562 |
minTransferDelay = None
|
565 |
minTransferDelay = None
|
| 563 |
minTransferDelayWarehouses = {}
|
566 |
minTransferDelayWarehouses = {}
|
| 564 |
total_availability = 0
|
567 |
total_availability = 0
|
| 565 |
|
568 |
|
| 566 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
569 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
| Line 573... |
Line 576... |
| 573 |
if minTransferDelay != transferDelay:
|
576 |
if minTransferDelay != transferDelay:
|
| 574 |
minTransferDelayWarehouses = {}
|
577 |
minTransferDelayWarehouses = {}
|
| 575 |
minTransferDelayWarehouses[warehouse.id] = warehouse
|
578 |
minTransferDelayWarehouses[warehouse.id] = warehouse
|
| 576 |
minTransferDelay = transferDelay
|
579 |
minTransferDelay = transferDelay
|
| 577 |
|
580 |
|
| 578 |
return [__get_warehouse_with_min_transfer_price(minTransferDelayWarehouses, item_id, item_pricing, False)[0], total_availability]
|
581 |
return [__get_warehouse_with_min_transfer_price(minTransferDelayWarehouses, ignoredWhs, item_id, item_pricing, False)[0], total_availability]
|
| 579 |
|
582 |
|
| 580 |
def __get_warehouse_with_max_availability(warehouse_ids, item_id):
|
583 |
def __get_warehouse_with_max_availability(warehouse_ids, item_id):
|
| 581 |
warehouse_retid = -1
|
584 |
warehouse_retid = -1
|
| 582 |
max_availability = 0
|
585 |
max_availability = 0
|
| 583 |
total_availability = 0
|
586 |
total_availability = 0
|