In this article we are looking into how to reserve inventory of SalesLine with batch and without batch, it also focuses on unreserve of inventory in X++.
Use this given method below to reserve partial inventory quantity with batch number for a sales line in X++
/// This method reserves SalesLine record with specific InventBatchId. ///The SalesLine record to reserve. ///Quantity to reserve. ///InventBatchId to reserve against public void reservesalesLineByBatchId(SalesLine _salesLine,
InventQty _reserveQuantity,
InventBatchId _inventBatchId) { InventUpd_Reservation reservation; InventMovement movement;
InventDim inventDimSalesLine, inventDim;
movement = InventMovement::construct(_salesLine); if (_reserveQuantity > 0) { inventDimSalesLine = InventDim::find(_salesLine.InventDimId); inventDim.clear(); inventDim.data(inventDimSalesLine); inventDim.InventBatchId = _inventBatchId;
inventDim = InventDim::findOrCreate(inventDim); reservation = InventUpd_Reservation::newInventDim(movement,
inventDim,
-_reserveQuantity,
false); reservation.updateNow(); } }
Use this given method below to reserve inventory completely for a sales line in X++
/// This method reserves SalesLine record. ///The SalesLine record to reserve. public void reserveInventory(SalesLine _salesLine) { InventUpd_Reservation reservation; InventMovement movement;
movement = InventMovement::construct(_salesLine); real x = abs(movement.transIdSum().reserved()); InventQty reserveQuantity = _salesLine.QtyOrdered - x; if (reserveQuantity > 0) { reservation = InventUpd_Reservation::newMovement( movement, -reserveQuantity, true); reservation.updateNow(); } }
Use this given method below to unreserve inventory completely for a sales line in X++
/// This method unreserves SalesLine record. /// The SalesLine record to unreserve. public void unReserveInventory(SalesLine _salesLine) { InventTrans inventTrans; InventTransOrigin inventTransOrigin; InventMovement inventMovement; InventUpd_Reservation inventUpd_Reservation; SalesLine salesLine; // Remove reservations and markings on a reserved salesorder while select inventTrans where inventTrans.StatusReceipt == StatusReceipt::None && (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) exists join inventTransOrigin where inventTransOrigin.RecId == inventTrans.InventTransOrigin exists join salesLine where salesLine.InventTransId == inventTransOrigin.InventTransId && SalesLine.RecId == _salesLine.RecId { if (inventTrans.MarkingRefInventTransOrigin) { InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true); InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true); } if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) { inventMovement = inventTrans.inventmovement(true); inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement, inventTrans.inventDim(), -1 * inventTrans.Qty, false); inventUpd_Reservation.updatenow(); } } }
Thank you for reading this article hope you find it useful.
Technical Consultant
References:
Microsoft Dynamics CRM is a powerful Customer Relationship Management (CRM) tool that helps businesses manage…
Today we will be going over the steps how to assign owner to specific Team…
Today we will be going over the steps how to set the value of a…
In this article we will see how we can create and post free text invoice…
In this article we will be focusing on confirmation of a sales order using X++…