{"record":{"id":"c4c8ec5fc7a52a2a","repo":"odoo/odoo","slug":"you-do-not-have-the-right-to-perform-this-operatio-c4c8ec","errorCode":null,"errorMessage":"You do not have the right to perform this operation as you do not have access to the following companies: %s.","messagePattern":"You do not have the right to perform this operation as you do not have access to the following companies: (.+?)\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"addons/account/wizard/account_merge_wizard.py","lineNumber":129,"sourceCode":"                    # that its ID doesn't get changed by the merge.\n                    self._action_merge(wizard_lines_group.sorted('account_has_hashed_entries', reverse=True).account_id)\n\n        return {\n            'type': 'ir.actions.client',\n            'tag': 'display_notification',\n            'params': {\n                'type': 'success',\n                'sticky': False,\n                'message': _(\"Accounts successfully merged!\"),\n                'next': {'type': 'ir.actions.act_window_close'},\n            }\n        }\n\n    @api.model\n    def _check_access_rights(self, accounts):\n        accounts.check_access('write')\n        if forbidden_companies := (accounts.sudo().company_ids - self.env.user.company_ids):\n            raise UserError(_(\n                \"You do not have the right to perform this operation as you do not have access to the following companies: %s.\",\n                \", \".join(c.name for c in forbidden_companies)\n            ))\n\n    @api.model\n    def _action_merge(self, accounts):\n        \"\"\" Merge `accounts`:\n            - the first account is extended to each company of the others, keeping their codes and names;\n            - the others are deleted; and\n            - journal items and other references are retargeted to the first account.\n        \"\"\"\n        # Step 1: Keep track of the company_ids and codes we should write on the account.\n        # We will do so only at the end, to avoid triggering the constraint that prevents duplicate codes.\n        company_ids_to_write = accounts.sudo().company_ids\n        code_by_company = self.env.execute_query(SQL(\n            \"\"\"\n            SELECT jsonb_object_agg(key, value)\n              FROM account_account, jsonb_each_text(account_account.code_store)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/account/wizard/account_merge_wizard.py#L111-L147","documentation":"Raised by account.merge.wizard._check_access_rights when any company owning one of the selected accounts is not in the current user's allowed companies. Merging writes to (and deletes) accounts across all their companies, so the user must have write access (checked via check_access('write')) and be granted access to every company involved. The check is done with sudo() because accounts may belong to companies the user cannot even read.","triggerScenarios":"Selecting accounts that span companies (e.g. one from Company A, one from Company B) while the current user's env.user.company_ids does not include Company B. Common in multi-company databases where the Chart of Accounts list shows accounts of companies outside the user's allowed set.","commonSituations":"Multi-company databases where a user has a subset of companies enabled; a shared chart of accounts template where accounts exist under many companies; administrator selects all accounts matching a code filter without noticing they belong to different companies.","solutions":["Enable every company that owns the selected accounts in the user's allowed companies (user form, 'Allowed Companies' field) and retry the merge.","Deselect the accounts that belong to companies you do not manage and merge only accounts within your allowed companies.","Have an administrator with access to all involved companies perform the merge, or add the user to the missing companies first."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"missing = accounts.sudo().company_ids - self.env.user.company_ids\nif missing:\n    raise UserError(_(\n        \"Grant access to these companies first: %s\",\n        ', '.join(missing.mapped('name')),\n    ))\nself.env['account.merge.wizard']._check_access_rights(accounts)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before merging, compare accounts.sudo().company_ids with env.user.company_ids and list the missing companies to the user.","In multi-company DBs, keep merge operations to administrators whose allowed companies cover the whole group."],"tags":["accounting","multi-company","access-rights","merge","odoo"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}