# -*- coding: utf-8 -*- """Group wiring for the Accounting application. Odoo 20 Community stops the accounting group chain early: group_account_manager -> group_account_invoice which leaves a full accounting *administrator* without ``group_account_readonly`` (needed by every report action and most Accounting menu entries) and without ``group_account_basic`` (needed by the dashboard). Enterprise repairs it across `accountant` and `account_accountant`. We do the same in one place below, so the reports installed by this suite are actually reachable by the person who installed them. """ import logging from odoo import api, models _logger = logging.getLogger(__name__) class ResGroups(models.Model): _inherit = "res.groups" @api.model def _dn_ensure_accounting_feature_groups(self): """Make every accounting administrator a full accounting user. ``implied_ids`` is normally enough: Odoo resolves group membership transitively through ``all_implied_ids``, so a user in ``group_account_manager`` automatically benefits from the groups it now implies. This method additionally *materialises* the membership for users who already existed before the upgrade, which keeps ``res_groups_users_rel`` consistent for anything that reads it directly (ACLs, record rules, some reports) instead of going through the ORM cache. """ manager = self.env.ref("account.group_account_manager", raise_if_not_found=False) user_group = self.env.ref("account.group_account_user", raise_if_not_found=False) if not manager or not user_group: return # Repair the chain if a later module re-broke it. if user_group not in manager.implied_ids: manager.write({"implied_ids": [(4, user_group.id)]}) users = manager.user_ids missing = users - user_group.user_ids if missing: user_group.write({"user_ids": [(4, uid) for uid in missing.ids]}) _logger.info( "DN Accounting Menu: granted full accounting features to %s user(s): %s", len(missing), ", ".join(missing.mapped("login")), )