public IEnumerable<InventoryRecord> QueryInventoriesByEntryCode(string code)
{
var inventoryService = ServiceLocator.Current.GetInstance<IInventoryService>();
return inventoryService.QueryByEntry(new [] { code });
}
public InventoryRecord GetInventoryByEntryCodeAndWarehouseCode(string code, string warehouseCode)
{
var inventoryService = ServiceLocator.Current.GetInstance<IInventoryService>();
return inventoryService.Get(code, warehouseCode);
}
Here's an example of how to convert a WarehouseInventory to an InventoryRecord:
private InventoryRecord InventoryToRecord(IWarehouseInventory source, DateTime purchaseAvailableUtc) { var existRecord = _storage.GetInventory(source.CatalogKey.CatalogEntryCode) .FirstOrDefault(i => i.WarehouseCode.Equals(source.WarehouseCode, StringComparison.OrdinalIgnoreCase)); var result = new InventoryRecord( catalogEntryCode: source.CatalogKey.CatalogEntryCode, warehouseCode: source.WarehouseCode, isTracked: source.InventoryStatus == InventoryTrackingStatus.Enabled, purchaseAvailableQuantity: source.InStockQuantity - source.ReservedQuantity, preorderAvailableQuantity: Math.Max(source.PreorderQuantity, 0), backorderAvailableQuantity: Math.Max(source.AllowBackorder ? source.BackorderQuantity : 0, 0), purchaseRequestedQuantity: existRecord?.PurchaseRequestedQuantity ?? 0, preorderRequestedQuantity: existRecord?.PreorderRequestedQuantity ?? 0, backorderRequestedQuantity: existRecord?.BackorderRequestedQuantity ?? 0, purchaseAvailableUtc: purchaseAvailableUtc, preorderAvailableUtc: source.AllowPreorder ? (source.PreorderAvailabilityDate ?? _safeBeginningOfTime) : _safeBeginningOfTime, backorderAvailableUtc: source.BackorderAvailabilityDate ?? purchaseAvailableUtc, additionalQuantity: source.ReservedQuantity, reorderMinQuantity: source.ReorderMinQuantity); return result; }
Thanks,
I'm still not sure though - what is the correct way to check "AllowPreorder" and "AllowBackorder" on an InventoryRecord?
We have old logic that is using "AllowPreorder" and "AllowBackorder"... I must refactor it to use InventoryRecord but I'm not sure how.
public static bool AllowPreOrder(this InventoryRecord record) { return record.PreorderAvailableUtc > new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc) && record.PreorderAvailableUtc < record.PurchaseAvailableUtc ; } public static bool AllowBackOrder(this InventoryRecord record) { return record.BackorderAvailableQuantity > 0; }
Awesome, thanks Mark.
BTW, we met in Vegas - I'm with the Turn5 guys. Hope you've been doing well!
- Ken
Hi all,
I'm recfactoring some old code that uses IWarehouseInventory.
I'd like to use InventoryRecord instead (..because IWarehouseInventory is deprecated. So I'll use IInventoryService which returns InventoryRecord.)
My old code looked like this:
How can I get those same values using InventoryRecord?
InventoryRecord record = ....;
var inventoryStatus = ????;
var allowPreorder = ????;
var allowBackorder = ????;
var inStockQuantity = ????;
var reservedQuantity = ????;