odoo/odoo · error · UserError

You do not have the right to perform this operation as you d

Error message

You do not have the right to perform this operation as you do not have access to the following companies: %s.

What it means

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.

Source

Thrown at addons/account/wizard/account_merge_wizard.py:129

                    # that its ID doesn't get changed by the merge.
                    self._action_merge(wizard_lines_group.sorted('account_has_hashed_entries', reverse=True).account_id)

        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'type': 'success',
                'sticky': False,
                'message': _("Accounts successfully merged!"),
                'next': {'type': 'ir.actions.act_window_close'},
            }
        }

    @api.model
    def _check_access_rights(self, accounts):
        accounts.check_access('write')
        if forbidden_companies := (accounts.sudo().company_ids - self.env.user.company_ids):
            raise UserError(_(
                "You do not have the right to perform this operation as you do not have access to the following companies: %s.",
                ", ".join(c.name for c in forbidden_companies)
            ))

    @api.model
    def _action_merge(self, accounts):
        """ Merge `accounts`:
            - the first account is extended to each company of the others, keeping their codes and names;
            - the others are deleted; and
            - journal items and other references are retargeted to the first account.
        """
        # Step 1: Keep track of the company_ids and codes we should write on the account.
        # We will do so only at the end, to avoid triggering the constraint that prevents duplicate codes.
        company_ids_to_write = accounts.sudo().company_ids
        code_by_company = self.env.execute_query(SQL(
            """
            SELECT jsonb_object_agg(key, value)
              FROM account_account, jsonb_each_text(account_account.code_store)

View on GitHub (pinned to 1e661df964)

Solutions

  1. Enable every company that owns the selected accounts in the user's allowed companies (user form, 'Allowed Companies' field) and retry the merge.
  2. Deselect the accounts that belong to companies you do not manage and merge only accounts within your allowed companies.
  3. Have an administrator with access to all involved companies perform the merge, or add the user to the missing companies first.
Defensive patterns

Strategy: validation

Validate before calling

missing = accounts.sudo().company_ids - self.env.user.company_ids
if missing:
    raise UserError(_(
        "Grant access to these companies first: %s",
        ', '.join(missing.mapped('name')),
    ))
self.env['account.merge.wizard']._check_access_rights(accounts)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15). Data as JSON: /api/errors/c4c8ec5fc7a52a2a. Report an issue: GitHub.