Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
651 Visualizzazioni

Hi there, I'm new to Odoo and need some help. I accidentally created a product along with some associated stock moves. Now, I'm trying to delete the product to clean up the database, but Odoo only allows me to archive it—deletion is blocked.

When I attempt to delete the product, I receive the following error:

Validation Error: The operation cannot be completed.  Model: 'Stock Move' (stock.move),  Foreign Key:'Product' (product_id)

So I went to the Inventory module to delete the related stock move, but that too is blocked. The error message says:

Invalid Operation: You cannot delete product moves if the picking is done. You can only correct the done quantities.

I’d really like to remove this product entirely and start with a clean database. Could anyone guide me on how to safely delete the product and its related records, even if the stock move is in a "done" state?

Thanks in advance for your help!

Avatar
Abbandona
Autore

Hi Himani, Can you please explain further. Pretty new to Odoo, not sure how to do this.


Risposta migliore

Hi,

In Odoo, you cannot directly delete a product if there are related stock moves, especially if the moves are in a “done” state, because this would break the integrity of your inventory and accounting records. The system enforces this via foreign key constraints on the stock.move model. For stock moves that are done, Odoo only allows correction of quantities, not deletion. Essentially, the available options for a stock move in this situation are:


    Correct the done quantities: Adjust the move via an inventory adjustment or a reversal to set the stock levels back to zero.

    Cancel future moves: Only moves that are not done can be canceled or deleted.

    Archive the product: While this does not remove it from the database, it prevents it from being used in future transactions.


If you need a clean database, the safest approach is either to revert the done stock moves using inventory adjustments and then delete the product (only possible if all related moves are undone) or, in a development/testing environment, manually remove the records via a database script. In a production environment, directly deleting done moves is strongly discouraged because it can corrupt stock and accounting data.



Hope it helps.

Avatar
Abbandona
Risposta migliore

You can delete it by sql query

Avatar
Abbandona