How to replace IWarehouseInventory with InventoryRecord?

Vote:
 

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:

            IWarehouseInventory warehouseInventory = ....;
            var inventoryStatus = warehouseInventory.InventoryStatus;
            var allowPreorder = warehouseInventory.AllowPreorder;
            var allowBackorder = warehouseInventory.AllowBackorder;
            var inStockQuantity = warehouseInventory.InStockQuantity;
            var reservedQuantity = warehouseInventory.ReservedQuantity;


How can I get those same values using InventoryRecord?

            InventoryRecord record = ....;
            var inventoryStatus = ????;
            var allowPreorder = ????;
            var allowBackorder = ????;
            var inStockQuantity = ????;
            var reservedQuantity = ????;

#180752
Jul 25, 2017 0:17
Vote:
 

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);
}

#180753
Jul 25, 2017 9:30
Vote:
 

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;
        }
#180758
Jul 25, 2017 14:41
Vote:
 

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.

#180765
Jul 25, 2017 16:22
Vote:
 
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;
}
#180773
Jul 26, 2017 0:48
Vote:
 

Awesome, thanks Mark. 

BTW, we met in Vegas - I'm with the Turn5 guys.  Hope you've been doing well!

 - Ken

#180813
Jul 26, 2017 22:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.