Skip to Content
Menu
This question has been flagged
1 Reply
524 Views

We are in v15 .sh.

We have maintained branches as separate companies in our current v15 as we did not have a branch option or cost center option.

Now when we upgrade to v17 how to convert the companies we have created in v15 which are actually a branches/cost center to branches in v17?

Which is the best way to handle this?

Avatar
Discard
Best Answer

We don't support converting branches to companies, we actually prevent changing the hierarchy via a blocking message in the code:

https://github.com/odoo/odoo/blob/19.0/odoo/addons/base/models/res_company.py#L341

def write(self, vals):
    if 'parent_id' in vals:
        raise UserError(self.env._("The company hierarchy cannot be changed."))


The only option is to use SQL to update the parent_id field and then call _parent_store_compute() to update the computed fields.

Note: Odoo does not support or recommend making changes to your Odoo database with SQL. Odoo Support cannot assist you resolving any issues that arise from making database changes with SQL. If you run into any issues, you will need to purchase a Success Pack so that a Consultant can bill all hours spent troubleshooting and repairing your database.


If you are prepared to rigorously test a potential conversion and resolve any issues yourself, example code for a Server Action would be something like this:

# assuming the ID of your original company is 1 and the ID of the parent is 2
# this will make company 1 a branch under company 2

env.cr.execute("UPDATE res_company SET parent_id = 2 WHERE id = 1;")
env['res.company']._parent_store_compute()




Avatar
Discard