Supply Orders > Pending receipt. Bug associated to the front office.



  • Hello.

    I want to share with you a bug that I have detected.

    [Conditions]

    • Advanced Stock Management: Activated.

    To reproduce the bug just follow the steps:

    1. Create a supply order. Add a product with quantity equal 0 and choose for example order 2 new products.
      Current instant state: Physical quantity = 0 | Usable quantity = 0 | Real quantity = 0
    2. Change the status to Order Validated.
      Current instant state: Physical quantity = 0 | Usable quantity = 0 | Real quantity = 0
    3. Change the status to Pending Receipt.
      Current instant state: Physical quantity = 0 | Usable quantity = 0 | Real quantity = 2
      0_1489175062741_upload-b28121e7-8c59-4236-9126-839b3a441a1a
    4. Go to the front office. You can see that there are 2 items to be ordered when you haven’t received the products:
      0_1489175125523_upload-2f008731-2f50-4230-baa5-56426b3c37bf

    I guess is a heritated bug from Prestashop. But I think can produce severe problems in many stores. If the supplier needs 5 days to deliver your order, you can be in serious troubles with your customers :)

    I have been taking a look in the code, and I think the problem must be in the AdminSupplyOrdersController.php line 1223:

      // create stock entry if not exist when order is in pending_receipt
                                        if ($new_state->pending_receipt) {
                                            $supply_order_details = $supply_order->getEntries();
                                            foreach ($supply_order_details as $supply_order_detail) {
                                                $is_present = Stock::productIsPresentInStock($supply_order_detail['id_product'], $supply_order_detail['id_product_attribute'], $supply_order->id_warehouse);
                                                if (!$is_present) {
                                                    $stock = new Stock();
    
                                                    $stock_params = array(
                                                        'id_product_attribute' => $supply_order_detail['id_product_attribute'],
                                                        'id_product' => $supply_order_detail['id_product'],
                                                        'physical_quantity' => 0,
                                                        'price_te' => $supply_order_detail['price_te'],
                                                        'usable_quantity' => 0,
                                                        'id_warehouse' => $supply_order->id_warehouse
                                                    );
    
                                                    // saves stock in warehouse
                                                    $stock->hydrate($stock_params);
                                                    $stock->add();
                                                }
                                            }
    

    I hope this can help to fix the bug.

    Thank you very much and regards.


  • administrators


  • administrators

    Looks like the real quantity calculation is broken, it’s always off by 2


  • administrators

    And it looks like the AdminSupplyOrdersController does the right thing, so the bug must be somewhere else.


  • administrators

    Real quantity is designed to include pending supply orders, but I’m not sure if the Front Office should be using the real quantity.

    The purpose of the usable quantity field is to show the quantity available for sale.


  • administrators

    The Front Office value should be 0. The quantity field in the product, product_shop and stock_available database tables should be 0, which is what I am seeing in my case.

    Could it have been a caching issue in your case and what quantities do you see in your database?


Log in to reply
 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.