Item total_projected_qty not being updated?


I need to fetch the total projected qty in all warehouses for an item (3 different companies), I tried the custom script below:


It works as expected, but the total is not correct, its like its not being updated.

Any ideas on how can I get this information updated or a better aproach to get the total?

I’m struggling with this, it seems like it only gets updated when delivery note is created (even for the sales with no delivery notes), but when the transaction is deleted the qty remains the same. Is there any better solution?