Files
gsinghpal 9ebf89bde2 changes
2026-05-16 13:18:52 -04:00

87 lines
3.6 KiB
Python

"""Coexistence tests: fusion_accounting_bank_rec menus only visible
when Enterprise's account_accountant is absent.
Strategy: mock the install state by toggling the group's user list directly,
then verify the recompute method aligns it with module presence."""
from unittest.mock import patch
from odoo.tests.common import TransactionCase, tagged
@tagged('post_install', '-at_install')
class TestCoexistence(TransactionCase):
def setUp(self):
super().setUp()
self.group = self.env.ref(
'fusion_accounting_core.group_fusion_show_when_enterprise_absent')
def _account_accountant_installed(self):
return bool(self.env['ir.module.module'].sudo().search([
('name', '=', 'account_accountant'),
('state', '=', 'installed'),
]))
def test_group_exists(self):
self.assertTrue(self.group, "Coexistence group must exist")
def test_recompute_when_enterprise_present(self):
"""When account_accountant is installed, group should be empty."""
if not self._account_accountant_installed():
self.skipTest(
"Local DB doesn't have account_accountant installed; "
"this test only meaningful in Enterprise-present scenario"
)
self.env['res.users']._fusion_recompute_coexistence_group()
self.assertEqual(
len(self.group.user_ids), 0,
"Coexistence group should be empty when Enterprise is installed",
)
def test_recompute_when_enterprise_absent(self):
"""When account_accountant is uninstalled, all internal users get the group."""
if self._account_accountant_installed():
# Simulate by mocking the enterprise-installed check.
with patch.object(
type(self.env['ir.module.module']),
'_fusion_is_enterprise_accounting_installed',
return_value=False,
):
self.env['res.users']._fusion_recompute_coexistence_group()
internal_users = self.env['res.users'].search([
('share', '=', False),
])
self.assertGreater(
len(self.group.user_ids & internal_users), 0,
"Coexistence group should contain internal users when "
"Enterprise is absent",
)
else:
self.env['res.users']._fusion_recompute_coexistence_group()
internal = self.env['res.users'].search([('share', '=', False)])
self.assertGreater(len(self.group.user_ids & internal), 0)
def test_menu_has_coexistence_group(self):
"""The fusion bank-rec root menu must have the coexistence group attached."""
menu = self.env.ref(
'fusion_accounting_bank_rec.menu_fusion_bank_rec_root',
raise_if_not_found=False,
)
if not menu:
self.skipTest("Menu not yet loaded — Task 42 must run first")
# Odoo 19 renamed ir.ui.menu.groups_id -> group_ids; tolerate either.
groups_field = getattr(menu, 'group_ids', None) or menu.groups_id
self.assertIn(
self.group, groups_field,
"Menu must require the coexistence group",
)
def test_engine_works_regardless_of_coexistence(self):
"""The reconcile engine must work even when Enterprise is installed
(it's the AI tools/menu that gate; the engine is always available)."""
self.assertIn(
'fusion.reconcile.engine', self.env.registry,
"Engine must always be available when fusion_accounting_bank_rec "
"is installed",
)