. . . //this is standard code IF "Job No." <> '' THEN BEGIN ItemLedgEntry."Job No." := "Job No."; ItemLedgEntry."Job Task No." := "Job Task No."; END; //my code starts here IF ((ItemLedgEntry."Entry Type" IN [ItemLedgEntry."Entry Type"::"Negative Adjmt.", ItemLedgEntry."Entry Type"::Sale,ItemLedgEntry."Entry Type"::Purchase ]) AND (ItemLedgEntry.Quantity <0) )THEN BEGIN lItem.GET(ItemLedgEntry."Item No."); lItem.SETFILTER("Location Filter",ItemLedgEntry."Location Code"); lItem.CALCFIELDS(Inventory); END; IF (lItem.Inventory < ABS(ItemLedgEntry.Quantity)) THEN ERROR(Error0001, lItem."No.",ABS(ItemLedgEntry.Quantity),lItem.Inventory); END; //my code ends here //this is standard code ItemLedgEntry.INSERT; InsertItemReg(ItemLedgEntry."Entry No.",0,0,0); END;With this code, I get the error message and the posting stops, but when I look at table 32 (Item Ledger entry), I find that the two lines (with no negative inventory) have been posted.
Comments
my change is in the same function:
The trick is not to check on negative inventory for the item, but to use the code that's already there:
- ILE is still open after application
- Quantity of ILE is negative
----> can only be negative stock.
Now force the exceptions which standard NAV allows to be disabled, and you're done.
with best regards
Jens
My question is: if in my order, the first two lines are ok (positive stock), and the 3rd line has negative stock, does your "trick" prevent the insertion of the first two lines??? I don't think so, but correct me if I am wrong....
My issue is to prevent the insertion of all the lines if there is some lines with negative stock...
with best regards
Jens
:thumbsup:
I think that testing actual inventory is not enough to prevent negative inventory. In standard NAV it is possible to post entries to the past and these entries can lead to negative inventory in the entries tree. So, you have to test negative inventory for each already posted entries with posting date after actual entry.
with best regards
Jens