Skip to Content
Menu
This question has been flagged
4 Replies
28493 Views

In V10 enterprise, For some models there's an archive function, but not for company. If I have multiple companies but then I have a company that is out of business, how can I disable or archive this company so that it does not appear in all modules? It seems that once a company is created even if I don't have any transactions yet, I cannot delete it because I get an error of referential integrity in the database and the archive function is not available for companies. Please help.

Avatar
Discard
Best Answer

Did you try removing access to that Company for all users?

Avatar
Discard
Best Answer

I know it's an old post, but as deleting a company is not addressed anywhere and this was the first hit when I googled it, I figured I could add a suggestion here on how to delete a company.


As Dheeraj pointed out, to delete a record you must first delete all records in other tables that relate to it. As almost everything in Odoo relates to a company, it is probably going to be quite a tedious and time consuming job to do that through the UI. So, an easier approach to do this is through the database. 


1. Check which Id the company has by querying the companies table:


select * from res_company rc;


2. Execute the following update


update res_company rc set resource_calendar_id = null where id = 123; -- Replace 123 with the id of your company


3. Execute the following select to generate a bunch of delete statements to delete all data related to the company:


SELECT 'delete from ' || columns.table_name || ' where ' || columns.column_name || '= 123;' -- Replace 123 with the id of your company
FROM information_schema.columns
join information_schema.tables t on columns.table_catalog = t.table_catalog and columns.table_schema = t.table_schema and columns.table_name = t.table_name
where (column_name = 'res_company_id' or column_name = 'company_id' or (t.table_name = 'res_company' and column_name = 'id')) and t.table_type = 'BASE TABLE';

4. Now execute the delete statements.


Depending on your exact situation, you may get some constraint violations when executing the delete statements. You'll have to resolve those in the appropriate way:

  • Reorder the statements to first delete items referencing another table

  • Set foreign key fields to null in case of circular dependencies (step 2 is an example)

I also found that some tables do not reference res_company directly. For example, account_payment does not reference res_company. So you have to derive the company from a related table. For example:

delete from account_payment ap where journal_id in (select id from account_journal aj where company_id = 123);


In my database I also found records of company A referencing records of company B, but let's not dwell on that :)


It goes without saying that the above advice comes without any guarantee whatsoever and a big warning: BE CAREFULL

  • Make sure you have a backup before you start

  • Try on a test-database first

  • Only do this when you understand what you are doing. Don't just execute these statements blindly.

If you end up with an empty production-database: too bad for you :)


(For some reason this text editor keeps screwing-up my text. I really struggled to get the queries above in, so it's possible some space or character ended up dropping off)

Avatar
Discard
Best Answer

As per my knowledge,  you have to remove that company details from everywhere than only you can be able to delete the company. Let's say if a company is used in some accounting than you have to delete the accounting first and then delete the company

Avatar
Discard
Best Answer

You can inherit 'res.company' model and add Boolean 'active' field , then in this company make active = False

Avatar
Discard
Related Posts Replies Views Activity
2
Apr 22
179
1
Aug 19
1743
3
Aug 18
2265
0
Mar 15
2803
0
Mar 15
3191