Hi All,
how to update the ordered qty in case of purchase order in Purchline , and order reserve qty in order reserver in case of sales order in salesline.
I have compared the behaviour in standard via the below screen and it does updates the both delivery remainder and the orderedinOurchUnit quantity and also the order reserve in case of sales order.
Please see my code it does updates the delivery remainder properly, but it is not updating the ordered quantity in case of purchase order and not updating the order reserve quantity in case of sales order.
Please suggest what am i doing wrong here
public class CNLHeroPurchCreationDeliveryRemainder{ public static CNLHeroPurchCreationDeliveryRemainder construct() { CNLHeroPurchCreationDeliveryRemainder delRemainder = new CNLHeroPurchCreationDeliveryRemainder(); return delRemainder; } public static void cancelRemainPhysical(PurchLine _purchLine, PurchQty _qty) { CNLHeroPurchCreationDeliveryRemainder deliverRemainder = new CNLHeroPurchCreationDeliveryRemainder(); ttsbegin; PurchQty RemainPurchPhys = _purchLine.RemainPurchPhysical; PurchQty qtyRemain = _purchLine.salesPurchLineInterface().calcSalesPurchQty(_qty); _purchLine.RemainPurchPhysical = qtyRemain; _purchLine.RemainInventPhysical = qtyRemain; if (_purchLine.RemainInventPhysical) { if (!_purchLine.RemainPurchPhysical) { throw error(/@SCM:InventoryQuantityCannotBe0WhenOrderQuantityIs0/); } if (sign(_purchLine.RemainInventPhysical) != sign(_purchLine.RemainPurchPhysical)) { throw error(/@SCM:InventoryQuantityMustHaveSameSignAsOrderQuantity/); } } if (_purchLine.validateWrite() && _purchLine.purchTable().checkUpdate()) { deliverRemainder.updateRemainPhysical(_purchLine,qtyRemain); // Update project commitments when deliver remainder is updated or quantity is canceled. deliverRemainder.updateProjCommitment(_purchLine, RemainPurchPhys); if (_purchLine.PurchStatus == PurchStatus::Canceled && _purchLine.PurchaseType == PurchaseType::ReturnItem && _purchLine.isInterCompanyOrder()) { if (_purchLine.InterCompanyInventTransId) { changecompany(_purchLine.purchTable().InterCompanyCompanyId) { var interCompanySalesLine = SalesLine::findInventTransId(_purchLine.InterCompanyInventTransId); var interCompanySalesTable = SalesTable::find(interCompanySalesLine.SalesId); if (interCompanySalesTable.ReturnStatus == ReturnStatusHeader::Created && !interCompanySalesTable.existRegisteredReceivedInvoicedLines()) { interCompanySalesLine.SalesStatus = SalesStatus::Canceled; interCompanySalesLine.ReturnStatus = ReturnStatusLine::Canceled; interCompanySalesLine.doUpdate(); } interCompanySalesTable.SalesStatus = SalesTableType::construct(interCompanySalesTable).lowestSalesStatus(); if (interCompanySalesTable.SalesStatus == SalesStatus::Canceled) { interCompanySalesTable.ReturnStatus = ReturnStatusHeader::Canceled; interCompanySalesTable.doUpdate(); } } } } } if (_purchLine.purchTable().PurchStatus == PurchStatus::Canceled) { PurchPrepayRemove::reversePrepaymentInvoice(_purchLine.PurchId); } ttscommit; } /// <summary> /// Retrieves the flag controlling which parts of the intercompany update process are skipped. /// </summary> /// <param name = /_callerPurchLine/> /// The caller purchase order line record. /// </param> /// <returns> /// The intercompany skip update flag. /// </returns> [SuppressBpWarning(/BPParameterNotUsed/, /Parameter _callerPurchLine is used by extensions that wrap this method./)] public InterCompanySkipUpdate retrieveInterCompanySkipUpdateFlag(PurchLine _callerPurchLine) { return InterCompanySkipUpdate::No; } public void updateRemainPhysical(PurchLine _callerPurchLine, PurchQty _qtyRemain) { PurchLine purchLineLocal = PurchLine::findRecId(_callerPurchLine.RecId); PurchLine purchlineUpdate; InventQty diffRemainPurchPhysical = purchLineLocal.RemainPurchPhysical - _qtyRemain; InventQty diffRemainInventPhysical = purchLineLocal.RemainInventPhysical - _qtyRemain; PdsCWInventQty diffPdsCWRemainInventPhysical; // = purchLineLocal.PdsCWRemainInventPhysical - _qtyRemain; MCRSalesOrderCancellation mcrSalesOrderCancellation; PurchSalesOrderCancellation purchSalesOrderCancellation = new PurchSalesOrderCancellation(); mcrSalesOrderCancellation = purchSalesOrderCancellation.mcrSalesOrderCancelInit(mcrSalesOrderCancellation, purchLineLocal.InventRefTransId); InterCompanyUpdateRemPhys::synchronize(_callerPurchLine, diffRemainInventPhysical, diffRemainPurchPhysical, this.retrieveInterCompanySkipUpdateFlag(_callerPurchLine), diffPdsCWRemainInventPhysical); if (_callerPurchLine.ItemRefType == InventRefType::Sales && _callerPurchLine.InventRefTransId && _callerPurchLine.isDropShipment()) { ttsbegin; select forupdate purchlineUpdate where purchlineUpdate.RecId == _callerPurchLine.RecId; if (purchlineUpdate.RecId) { purchlineUpdate.RemainPurchPhysical = _qtyRemain; purchlineUpdate.RemainInventPhysical = _qtyRemain; // purchlineUpdate.PdsCWRemainInventPhysical = _qtyRemain; if (_qtyRemain == 0) { purchlineUpdate.PurchStatus = PurchStatus::Canceled; } purchlineUpdate.doUpdate(); } ttscommit; } purchSalesOrderCancellation.mcrSalesOrderCancel(mcrSalesOrderCancellation, purchLineLocal.InventRefTransId); // This part is related to Europe Extension MCRSalesLineDropShipment mcrSalesLineDropShipment; SalesLine salesLine = SalesLine::findInventTransId(purchlineUpdate.InventRefTransId); mcrSalesLineDropShipment = MCRSalesLineDropShipment::findSalesLine(salesLine.RecId, true); if(mcrSalesLineDropShipment) { mcrSalesLineDropShipment.DropShipment = NoYes::No; mcrSalesLineDropShipment.DropShipStatus = MCRDropShipStatus::None; mcrSalesLineDropShipment.update(); } } public void updateProjCommitment(PurchLine _callerPurchLine, PurchQty _remainPurchPhysicalOrig) { if ((_callerPurchLine.RemainPurchPhysical && _remainPurchPhysicalOrig != _callerPurchLine.RemainPurchPhysical) || (!_callerPurchLine.RemainPurchPhysical)) { SourceDocumentLine sourceDocumentLine = SourceDocumentLine::find(_callerPurchLine.SourceDocumentLine); sourceDocumentLineItem sourceDocumentLineItem = sourceDocumentLineItem::newFromSourceDocumentLine(sourceDocumentLine); ProjectCommitmentFacade::updateProjectCommitments(sourceDocumentLineItem); } }}