Fix: replenish.php: no virtual stock shown for warehouses that have no physical stock #29396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Currently, the replenish page can be filtered by warehouse. If you use this filter in the "virtual stock" mode, it shows a column with the virtual stock of every product for the selected warehouse.
However, when the product doesn't currently have any physical stock in that warehouse, the virtual stock is not computed even though it might be non-zero (for instance if the warehouse is the default warehouse for this product and there are supplier orders for that product, or if you allow negative stock and there are future shipments with lines referring to this warehouse and this product).
This is because
load_virtual_stock()
loops over keys of$this->stock_warehouses
(an array indexed by warehouse), whose keys are initialized when computing the physical stock. Therefore, warehouses with no physical stock don't have a key in this array and are not considered for virtual stock computation.Proposed solution
This fix initializes the array
$this->stock_warehouses
with empty objects for every warehouse.An alternative solution would be, in
load_virtual_stock()
, to loop over all warehouses instead of those listed as keys of$this->stock_warehouses
. It would have a smaller memory footprint (no need to keep an array of mostly empty values for possibly thousands of warehouses) but this might be harder to read.