Hello Adam,
Resetting an Odoo database to remove all test transactions while keeping the basic configuration intact can indeed be achieved by running SQL queries, but this should be done carefully.
Here's a comprehensive guide to help you safely reset your database:
Odoo stores transactional data in several tables, such as:
- Sales Orders: sale_order and sale_order_line
- Purchases: purchase_order and purchase_order_line
- Inventory Transactions: stock_picking, stock_move, stock_quant, etc.
- Accounting: account_move, account_move_line, account_invoice, etc.
You need to delete related records in the correct order to maintain data integrity. Odoo uses a lot of foreign key constraints, so you may need to cascade deletions.
Here's a general SQL script to reset transactional data:
DELETE FROM sale_order_line;
DELETE FROM sale_order;
-- Clear Purchase Orders
DELETE FROM purchase_order_line;
DELETE FROM purchase_order;
-- Clear Inventory Transactions
DELETE FROM stock_move_line;
DELETE FROM stock_move;
DELETE FROM stock_picking;
-- Clear Stock Quant
DELETE FROM stock_quant;
-- Clear Accounting Entries
DELETE FROM account_move_line;
DELETE FROM account_move;
-- Clear CRM Data (if applicable)
DELETE FROM crm_lead;
To delete specific records from Odoo's database using SQL queries, it's crucial to use appropriate WHERE clauses. This approach ensures that only the targeted data is removed, leaving other records untouched.
Example: Removing Test Records
If you want to remove only test records created by a specific user or within a specific date range, you can add these conditions to the WHERE clause:
DELETE FROM sale_order_line
WHERE order_id IN (SELECT id FROM sale_order WHERE id = 5);
DELETE FROM sale_order
WHERE id = 5;
-- Delete records created after a specific date
DELETE FROM purchase_order
WHERE create_date >= '2024-01-01';
Thanks & Regards,
CandidRoot Solutions Pvt. Ltd.
Mobile: (+91) 8849036209
Email: info@candidroot.com