Hi folks
I have spent 1 day digging for solution...
In my case, I didnt had refounding system activated but still, I encountered similar situations like you (the quantities from Product -> Quantities was different than qty from Advanced stock Management)
After many hours of digging through database, changing some classes in /classes/stock folder, I have found that the difference (Product->Qty reported 5 items less comparing with advanced stock management; more specific, product qty show 14 when AMS show 19 items) is coming from some old cancelled orders !
In StockManagerInterface.php says:
" /**
* For a given product, returns its real quantity
* If the given product has combinations and $id_product_attribute is null, returns the sum for all combinations
* Real quantity : (physical_qty + supply_orders_qty - client_orders_qty)
* If $usable is defined, real quantity: usable_qty + supply_orders_qty - client_orders_qty
*
....
*/
public function getProductRealQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false);
"
I REACH HERE starting from StockAvailable.php, where it write:
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
so I checked the $client_orders_qty variable from file mentioned bellow.
In StockManager.php, it says:
==========
...
public function getProductRealQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false)
...
$client_orders_qty += ($row['product_quantity'] - $row['product_quantity_refunded']);
...
$qty = $this->getProductPhysicalQuantities($id_product, $id_product_attribute, $ids_warehouse, $usable);
...
return ($qty - $client_orders_qty + $supply_orders_qty);
==========
This means that from quantities which he found on table ps_stock for an specific product/combination (in my case 19), it substract what he found on tables with orders (products received back and not added automatically in stock by ASM) and add eventual orders to suppliers. Finally, the script pushes in my ps_stock_available table the value "14" and this means on table with orders, 5 of them are not seen as products came back in stock after unsuccessful order... Like CANCELLED...
Looking very careful to "$client_orders_qty += ($row['product_quantity'] - $row['product_quantity_refunded']);" from file StockManager.php I decided to add the missing value (difference in my case between 19 and 14) to last row in column product_quantity_refunded, from table ps_order_details
And WOW, problem solved, now quantities are the same, in Product->Quantities and ASM.
But this is an trick. And can be solved only altering table ps_order_details in database.
Normally, in my opinion, PrestaShop must do itself, I mean when an order receive status "cancelled" to bring back in stock the products from that order... But from what I have seen, when adding/modifying statuses in BO, there is no such option regarding add back in stock.
I am on PS 1.6.1.18
have fun !