Inventory Dimension Not Considered in Stock Validation (Delivery Note, Stock Entry, etc.)

We’ve noticed that ERPNext is not validating stock availability correctly when using Inventory Dimensions (such as Project, Cost Center, etc.).

Currently, the system seems to validate the available quantity in a warehouse using the qty_after_transaction field from the last Stock Ledger Entry (SLE). However, this field only reflects the total quantity per warehouse, not filtered by inventory dimensions.

As a result, a Delivery Note or Stock Entry can be submitted even when the available stock for a specific project (or other inventory dimension) is insufficient — as long as the warehouse overall has enough stock.

Steps to Reproduce:

  1. Enable an Inventory Dimension (e.g., Project) with “Affects Stock” = :white_check_mark:.
  2. Make a stock-in entry (e.g., Purchase Receipt) for Item A, Warehouse X, Project P1 (say 10 qty).
  3. Make another stock-in entry for the same item and warehouse, but for Project P2 (say 5 qty).
  4. Try creating a Delivery Note for 15 qty from Warehouse X, and assign Project P2.
  5. ERPNext allows submission, even though Project P2 only has 05 qty.