Skip to Content

Contributors

Re: stock: Retroactively removing lots from incompatible products in stock move history


On 1/7/22 10:47 AM, Carmen Bianca Bakker wrote:
I have also verified that the quantities in
the inventory have correctly added up (the quantities of bottles that
previously had lots are added to the lot-less bottles).

I think at least for the stock_quant table, this is all you had to verify, and you have, so that's fine.

As for the modification that you did in "stock_move_line", I'm less sure - you're changing history there. I'm also not sure if doing that was really necessary to achieve your goal to make the inventory work again.

If you want to be sure, I would revert the stock move line table to a recent backup, and then do some more testing in a test database if that modification is really necessary.


by Tom Blauwendraat - 11:06 - 7 Jan 2022

Reference

  • stock: Retroactively removing lots from incompatible products in stock move history
    Hi all,
    
    I'm a little bit new to Odoo, so please bear with me if I don't get
    everything right, but I've been told that I have struck a difficult
    bug.
    
    TL:DR: Having removed the lot_id from certain rows (products that are
    incompatible with that lot) in stock_move_line and stock_quant, how do
    I know I haven't broken something?
    
    
    I have a database that was migrated from Odoo 9 to Odoo 12. Before the
    migration, there was a bug that assigned lots to by-products of a
    dismantling operation (in this case, empty bottles were assigned the
    lots of full bottles of wine).
    
    As a result, during inventory on Odoo 12, the error message from
    StockMoveLine._check_lot_product() shows up, correctly identifying that
    these various lots are incompatible with empty bottles, then aborting
    the validation.
    
    Because these lots were added in error, I want to remove them from all
    past stock moves. This cannot be done through the UI, so I've made
    these SQL statements to get it done:
    
    ```
    update stock_move_line 
    set lot_id = null, lot_name = null
    where product_id in (67, 38, 29) and lot_id is not null;
    
    update stock_quant
    set lot_id = null
    where product_id in (67, 38, 29) and lot_id is not null;
    ```
    
    (the product_ids here are empty bottles)
    
    Having run the above on a test/staging database, I can now do the
    inventory without troubles. I have also verified that the quantities in
    the inventory have correctly added up (the quantities of bottles that
    previously had lots are added to the lot-less bottles). The quantities
    on the `product.product` view have remained the same, which makes sense
    to me. I have also triggered `_compute_quantities()` for
    'product.product', and nothing has changed.
    
    Although everything works and my problems seem to have disappeared, the
    problem is that I do not know whether I have inadvertently corrupted
    the (test!) database. I've been reading the source code of the stock
    module to find interactions with lot_id and lot_name, but I've not
    really found anything troubling.
    
    Does my approach make sense? Is there anything I can do to verify the
    integrity of what I've done?
    
    Many thanks and best regards,
    
    Carmen Bianca Bakker
    Coop IT Easy
    

    by Carmen Bianca Bakker - 10:46 - 7 Jan 2022