Hello,
I don know where to publish this, it is a bug in original code, discovered by accident.
On one of our client database (Dynamics NAV 2016 CU 13) we have noticed that procedure Adjust cost – Item Entries posts new cost even if on new cost had been added to entry, it has posted milions already.
We recreated the condition on newest on-prem Bustiness Central W1 edition (CU 04 Dynamics 365 Business Central Spring 19 Update W1), and noticed that the bug is in this version also.
Bug is created when you correct more than a half production journal consumption, of one item, that has consumption that has been outputted in the same production order, and you have to have item tracking on consumed item.
Production output and consumption ticks Applied Entry to Adjust field in Item Ledger Entry that causes wrong entry to process when Adjusting Cost, and adding non-existing cost. Cost adjustment post new cost, when item Cost is Adjusted field is false, in Value Entry every time even if no new cost has been added to entry.
My opinion is that the bug appears in CU 99000830 Create Reserv. Entry Function TransferReservEntry.
Code:
//……
IF UseQtyToHandle THEN BEGIN // Used when handling Item Tracking
QtyToHandleThisLine := OldReservEntry."Qty. to Handle (Base)";
QtyToInvoiceThisLine := OldReservEntry."Qty. to Invoice (Base)";
IF ABS(TransferQty) > ABS(QtyToHandleThisLine) THEN
TransferQty := QtyToHandleThisLine;
IF UseQtyToInvoice THEN BEGIN // Used when posting sales and purchase
IF ABS(TransferQty) > ABS(QtyToInvoiceThisLine) THEN
TransferQty := QtyToInvoiceThisLine;
END;
END ELSE
QtyToHandleThisLine := OldReservEntry."Quantity (Base)";
……//
In part in red we presume that both TransferQty and QtyToHandleThisLine have the same sign.
But when we post correction of the consumption TransferQty is positive and QtyToHandleThisLine is negative,
and with absolute comparison TransferQty becomes negative, and it creates wrong Item application Entry, that creates wrong postings.