Contributors mailing list archives

Browse archives


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

Coop IT Easy SC agréée, Carmen Bianca Bakker
- 07/01/2022 10:45:21
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

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