Files
Odoo-Modules/fusion_accounting_migration/tests/test_safety_guard.py
gsinghpal db90b1ad5b feat(fusion_accounting_migration): add Enterprise uninstall safety guard + wizard skeleton
Phase 0 Task 17. Installs a safety guard on ir.module.module that blocks
uninstall of Odoo Enterprise accounting modules (account_accountant,
account_reports, accountant, account_followup, account_asset,
account_budget, account_loans) until the per-module migration flag
fusion_accounting.migration.<name>.completed is set to True. Guard
covers both button_immediate_uninstall (UI) and module_uninstall
(CLI/API) paths, raising UserError with a pointer to the migration
wizard and an escape hatch config parameter.

Also ships a TransientModel fusion.migration.wizard as a shell: it
detects installed Enterprise modules via GUARDED_MODULES and exposes
action_run_migration for sub-modules to extend in later phases. No
per-feature migrations are registered yet -- Phase 1+ sub-modules will
hook in their own steps.

Tests: TestSafetyGuard x2 pass (blocked-when-pending verified with
account_accountant installed; not-blocked-when-completed verified by
setting the flag).

Made-with: Cursor
2026-04-19 00:36:09 -04:00

32 lines
1.5 KiB
Python

from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase, tagged
@tagged('post_install', '-at_install')
class TestSafetyGuard(TransactionCase):
"""Verify the safety guard blocks Enterprise uninstall when migration hasn't run."""
def test_uninstall_not_blocked_when_migration_completed(self):
"""If the per-module migration flag is set, uninstall is allowed."""
self.env['ir.config_parameter'].sudo().set_param(
'fusion_accounting.migration.account_accountant.completed', 'True'
)
guard = self.env['ir.module.module']._fusion_check_uninstall_guard(['account_accountant'])
self.assertTrue(guard, "Guard should pass when migration flag is set")
def test_uninstall_blocked_when_migration_pending(self):
"""If account_accountant is installed and migration not run, raise."""
self.env['ir.config_parameter'].sudo().set_param(
'fusion_accounting.migration.account_accountant.completed', 'False'
)
Module = self.env['ir.module.module'].sudo()
installed = Module.search_count([
('name', '=', 'account_accountant'),
('state', '=', 'installed'),
])
if not installed:
self.skipTest("account_accountant not installed in this DB")
with self.assertRaises(UserError) as ctx:
Module._fusion_check_uninstall_guard(['account_accountant'])
self.assertIn('migration', str(ctx.exception).lower())