OpernERP deletes partner with dependent orders
I am wondering how I can remove the partner from OpenERP
and remove all dependencies. For example, orders
, sales
, invoice
etc.
I tried to open partner view and click delete button. The partner is deleted, but the related orders are not deleted. It also raises an error because this partner does not currently exist in the database. How to remove a partner and affect all addictions?
source to share
I can tell you how to find all of its dependencies, but I'll leave it to you to decide how you want to remove them. I wrote this SQL script to find the dependencies of any recordset in any table. You put the table name on the last line and then replace (1234)
with the set of record IDs whose children you want to find.
When you run your query, it will generate a large SQL statement that you can then run to see all the child records. You just need to uninstall the latter UNION ALL
before running it. This only shows direct child records, not indirect records. It also won't tell you about wacky relationships like those found in workflow tables, ir_values
or ir_model_data
.
SELECT 'SELECT ''' || tc.table_name ||
''' as tabname, ''' || kcu.column_name ||
''' as colname, ' || kcu.column_name ||
' as id, count(*) FROM ' || tc.table_name ||
' as cnt WHERE ' || kcu.column_name || ' IN (1234) ' ||
' GROUP BY ' || kcu.column_name || ' UNION ALL '
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
AND ccu.table_name = 'res_partner';
source to share