feat(fusion_accounting_core): add computed coexistence group + recompute hooks

group_fusion_show_when_enterprise_absent has membership = all internal
users iff no Enterprise accounting module is installed. Membership is
recomputed on module install/uninstall via overrides on ir.module.module.
Used by Phase 1 fusion_bank_rec menus to auto-hide when Enterprise is
active and auto-appear after Enterprise uninstall.

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 10:02:19 -04:00
parent 3f4fdeffce
commit 78a481f3f4
8 changed files with 111 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
from . import ir_module_module
from . import res_users
from . import account_move
from . import account_reconcile_model
from . import account_bank_statement_line

View File

@@ -30,3 +30,26 @@ class IrModuleModule(models.Model):
('name', '=', module_name),
('state', '=', 'installed'),
]))
def button_immediate_install(self):
"""Recompute the coexistence group after install state changes."""
result = super().button_immediate_install()
self.env['res.users']._fusion_recompute_coexistence_group()
return result
def button_immediate_uninstall(self):
"""Recompute the coexistence group after uninstall state changes.
The MRO chains into fusion_accounting_migration's override (which runs
the safety guard before calling super); we recompute only after the
whole chain completes.
"""
result = super().button_immediate_uninstall()
self.env['res.users']._fusion_recompute_coexistence_group()
return result
def module_uninstall(self):
"""Recompute the coexistence group after the lower-level uninstall."""
result = super().module_uninstall()
self.env['res.users']._fusion_recompute_coexistence_group()
return result

View File

@@ -0,0 +1,27 @@
"""Coexistence group membership recomputation."""
from odoo import api, models
class ResUsers(models.Model):
_inherit = "res.users"
@api.model
def _fusion_recompute_coexistence_group(self):
"""Set group membership = all internal users iff Enterprise absent.
Called from ir.module.module.button_immediate_install / uninstall
overrides. Idempotent; safe to call multiple times.
"""
group = self.env.ref(
'fusion_accounting_core.group_fusion_show_when_enterprise_absent',
raise_if_not_found=False,
)
if not group:
return
enterprise_installed = self.env['ir.module.module']._fusion_is_enterprise_accounting_installed()
if enterprise_installed:
group.sudo().write({'user_ids': [(5, 0, 0)]})
else:
all_internal = self.sudo().search([('share', '=', False)])
group.sudo().write({'user_ids': [(6, 0, all_internal.ids)]})