dolibarr icon indicating copy to clipboard operation
dolibarr copied to clipboard

Fix: replenish.php: no virtual stock shown for warehouses that have no physical stock

Open atm-florianm opened this issue 10 months ago • 2 comments

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.

atm-florianm avatar Apr 18 '24 16:04 atm-florianm

The solution hurt me becasse it change code int product.class.php when it should fix by changing code into the incriminated page so product/stock/replenish.php

Can't you try to add a fix inside this page ?

eldy avatar May 24 '24 16:05 eldy

Sorry for not replying for a long time. I haven't spent time on that issue for weeks, so I forgot many of the specificities.

I will try to book some time in the next few weeks to help move this PR forwards.

atm-florianm avatar Jun 19 '24 15:06 atm-florianm