per each (product + asi) MStorageOnHand keep one record QtyOnHand != 0 and multi record with QtyOnHand = 0
MStorageOnHand.getDateMaterialPolicy return record have QtyOnHand = 0 on below condition, let issue "Negative inventory disallowed in this warehouse"
1. make "Disallow Negative Inventory" of "HQ Warehouse" is true
2. create material receipt for product PChair with a new ASI called asi_new and QtyOnHand = 100
3. choose "Movement Date" = "06/22/2017"
4. complete this document, we get a record M_StorageOnHand with QtyOnHand = 100
5. do "Reverse correction" this document so we get record M_StorageOnHand with QtyOnHand = 0
6. create a new material receipt document for PChair and re-select asi = asi_new, set QtyOnHand = 10
7. choose "Movement Date" = "06/23/2017"
8. complete this document, we get a new record of M_StorageOnHand
9. create a "Internal Use Inventory" document for PChair, also choose asi = asi_new
set "Internal Use Qty" <= 10
10. complete this document we get error message "Negative inventory disallowed in this warehouse"
MStorageOnHand.getDateMaterialPolicy return record with QtyOnHand = 0 at step 5.
query without order let posgresql return record with random order, in my case it return record by order older touch first.
filter out record with QtyOnHand = 0
I think it should be Order by QtyOnHand Desc instead. Filter out record with QtyOnHand = 0 could break use cases that need to update existing ASI with onhand = 0.