From b637723c6a6df134cf1140f7c8f400a1d2004dc6 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Sat, 18 Apr 2026 23:46:44 -0400 Subject: [PATCH] feat(fusion_accounting_core): add _fusion_is_enterprise_accounting_installed helper Made-with: Cursor --- fusion_accounting_core/models/__init__.py | 2 +- .../models/ir_module_module.py | 32 +++++++++++++++++++ fusion_accounting_core/tests/__init__.py | 2 +- .../tests/test_enterprise_detection.py | 20 ++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 fusion_accounting_core/models/ir_module_module.py create mode 100644 fusion_accounting_core/tests/test_enterprise_detection.py diff --git a/fusion_accounting_core/models/__init__.py b/fusion_accounting_core/models/__init__.py index 154f21c2..8e2d2d1b 100644 --- a/fusion_accounting_core/models/__init__.py +++ b/fusion_accounting_core/models/__init__.py @@ -1 +1 @@ -# Models populated in Tasks 8-12 (shared-field-ownership, helpers) +from . import ir_module_module diff --git a/fusion_accounting_core/models/ir_module_module.py b/fusion_accounting_core/models/ir_module_module.py new file mode 100644 index 00000000..27e02076 --- /dev/null +++ b/fusion_accounting_core/models/ir_module_module.py @@ -0,0 +1,32 @@ +from odoo import api, models + + +# Modules considered "Odoo Enterprise accounting" for the purpose of feature gating. +# A client is "on Enterprise" if any of these are installed; fusion_accounting_* +# replacement modules will hide their menus when Enterprise is present (replace mode +# vs. augment mode is configurable in Settings). +ENTERPRISE_ACCOUNTING_MODULES = ( + 'account_accountant', + 'account_reports', + 'accountant', +) + + +class IrModuleModule(models.Model): + _inherit = "ir.module.module" + + @api.model + def _fusion_is_enterprise_accounting_installed(self): + """True if any Odoo Enterprise accounting module is installed in this DB.""" + return bool(self.sudo().search_count([ + ('name', 'in', list(ENTERPRISE_ACCOUNTING_MODULES)), + ('state', '=', 'installed'), + ])) + + @api.model + def _fusion_is_module_installed(self, module_name): + """True if a specific module is installed.""" + return bool(self.sudo().search_count([ + ('name', '=', module_name), + ('state', '=', 'installed'), + ])) diff --git a/fusion_accounting_core/tests/__init__.py b/fusion_accounting_core/tests/__init__.py index 55610b70..f1a2b5c5 100644 --- a/fusion_accounting_core/tests/__init__.py +++ b/fusion_accounting_core/tests/__init__.py @@ -1 +1 @@ -# Tests populated in Tasks 8-12 +from . import test_enterprise_detection diff --git a/fusion_accounting_core/tests/test_enterprise_detection.py b/fusion_accounting_core/tests/test_enterprise_detection.py new file mode 100644 index 00000000..4f2a72c7 --- /dev/null +++ b/fusion_accounting_core/tests/test_enterprise_detection.py @@ -0,0 +1,20 @@ +from odoo.tests.common import TransactionCase, tagged + + +@tagged('post_install', '-at_install') +class TestEnterpriseDetection(TransactionCase): + """Verify the helper that detects Odoo Enterprise accounting installs.""" + + def test_helper_returns_bool(self): + result = self.env['ir.module.module']._fusion_is_enterprise_accounting_installed() + self.assertIsInstance(result, bool) + + def test_helper_matches_actual_state(self): + """Helper should return True iff one of the known Enterprise modules is installed.""" + installed = self.env['ir.module.module'].sudo().search_count([ + ('name', 'in', ['account_accountant', 'account_reports', 'accountant']), + ('state', '=', 'installed'), + ]) + expected = bool(installed) + actual = self.env['ir.module.module']._fusion_is_enterprise_accounting_installed() + self.assertEqual(actual, expected)