Hi Viesturs Silins,
post is old but the same issue is still coming in AX 2012 and 2012 R2.
recently i faced the same issue in AX 2012 R2 CU7 with Those PO's which are Partially GRN, mean each line will have tow records in InventTrans table one with status received another with status ordered which is causing error and deleting entry will delete ordered status where you can't create GRN for remaining Qty.
i went in to details and the error is coming checkLineAfterPosting method of PurchInvoiceJournalPost class.
i was able to solved it by just adding one more condition to ignore Ordered status as well.
Old Code
if (purchLine.RemainPurchFinancial == 0 && purchLine.RemainPurchPhysical == 0)
{
select firstonly RecId from inventTrans
where ((purchLine.PurchQty >= 0
&& inventTrans.StatusReceipt != StatusReceipt::Purchased
&& inventTrans.StatusReceipt != StatusReceipt::None)
|| (purchLine.PurchQty < 0 && inventTrans.StatusIssue != StatusIssue::Sold && inventTrans.StatusIssue != StatusIssue::None))
exists join inventTransOriginPurchLine
where inventTransOriginPurchLine.InventTransOrigin == inventTrans.InventTransOrigin
&& inventTransOriginPurchLine.PurchLineDataAreaId == purchLine.DataAreaId
&& inventTransOriginPurchLine.PurchLineInventTransId == purchLine.InventTransId;
if (inventTrans.RecId)
{
if (purchLine.PurchQty < 0)
{
ok = checkFailed(strFmt("@SYS54028", StatusIssue::Sold));
}
else
{
ok = checkFailed(strFmt("@SYS54028", StatusReceipt::Purchased));
}
ok = checkFailed("@SYS115807");
}
}
New Code
if (purchLine.RemainPurchFinancial == 0 && purchLine.RemainPurchPhysical == 0)
{
select firstonly RecId from inventTrans
where ((purchLine.PurchQty >= 0
&& inventTrans.StatusReceipt != StatusReceipt::Purchased
&& inventTrans.StatusReceipt != StatusReceipt::None
&& inventTrans.StatusReceipt != StatusReceipt::Ordered)
|| (purchLine.PurchQty < 0 && inventTrans.StatusIssue != StatusIssue::Sold && inventTrans.StatusIssue != StatusIssue::None))
exists join inventTransOriginPurchLine
where inventTransOriginPurchLine.InventTransOrigin == inventTrans.InventTransOrigin
&& inventTransOriginPurchLine.PurchLineDataAreaId == purchLine.DataAreaId
&& inventTransOriginPurchLine.PurchLineInventTransId == purchLine.InventTransId;
if (inventTrans.RecId)
{
if (purchLine.PurchQty < 0)
{
ok = checkFailed(strFmt("@SYS54028", StatusIssue::Sold));
}
else
{
ok = checkFailed(strFmt("@SYS54028", StatusReceipt::Purchased));
}
ok = checkFailed("@SYS115807");
}
}