My company has multiple warehouses. I have added custom code in a SalesOrderEntry Extension to find the closest warehouse that has a requested item, if it isn’t available at the customer’s default warehouse. If there isn’t enough inventory at any of our locations, a line is created to add the short quantity to the item default warehouse (where the item is manufactured).
The code works if there is enough inventory to fill the item, but if there isn’t enough I get a line type error. Our item classes are set to allow negative quantities. I have manually entered the lines the way the code does it and it works manually. In debug all fields are filled in, including line type.
Example:
Customer orders 200 widgets from location X
Inventory gets checked and 61 widgets are available in default warehouse Y
New line is created for the 61 widgets
Another new line is created for the remaining 139 widgets
Original line is deleted
Line Type Error occurs when the screen is saved
Code:
var tagLine = createSOLineSplit(row, defaultSiteID, requiredAmount);
public SOLine createSOLineSplit(SOLine oldObject, int? siteID, decimal? orderQty)
{
SOLine newObj = (SOLine)Base.Transactions.Insert(new SOLine()
{
InventoryID = oldObject.InventoryID,
BranchID = oldObject.BranchID,
SiteID = siteID,
IsFree = oldObject.IsFree,
ManualDisc = oldObject.ManualDisc,
LineType = oldObject.LineType,
Operation = oldObject.Operation,
AutoCreateIssueLine = oldObject.AutoCreateIssueLine,
});
newObj.OrderQty = orderQty;
return (SOLine)Base.Transactions.Cache.Update(newObj);
}
Trace:
Thank-you for any direction you can give me.