Files
Odoo-Modules/fusion_accounting_migration/models/ir_module_module.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

73 lines
2.6 KiB
Python

"""Safety guard: blocks Odoo Enterprise accounting uninstall until migration runs.
For each Enterprise accounting module the user attempts to uninstall, the
guard checks an ir.config_parameter flag named:
fusion_accounting.migration.<module_name>.completed
If the flag is False/unset and the module is currently installed, the guard
raises UserError pointing the user to Settings -> Fusion Accounting ->
Migrate from Enterprise.
The migration wizard sets the flag to True after a successful migration run
for that module.
"""
from odoo import _, api, models
from odoo.exceptions import UserError
GUARDED_MODULES = (
'account_accountant',
'account_reports',
'accountant',
'account_followup',
'account_asset',
'account_budget',
'account_loans',
)
class IrModuleModule(models.Model):
_inherit = "ir.module.module"
@api.model
def _fusion_check_uninstall_guard(self, module_names):
"""Verify it's safe to uninstall the given modules.
Returns True if all checks pass; raises UserError otherwise.
"""
Param = self.env['ir.config_parameter'].sudo()
for name in module_names:
if name not in GUARDED_MODULES:
continue
installed = self.sudo().search_count([
('name', '=', name), ('state', '=', 'installed'),
])
if not installed:
continue
flag_key = f'fusion_accounting.migration.{name}.completed'
if Param.get_param(flag_key, default='False').lower() != 'true':
raise UserError(_(
"Cannot uninstall %s: the Fusion Accounting migration "
"for this module has not run yet. Please open\n"
" Settings -> Fusion Accounting -> Migrate from Enterprise\n"
"and run the migration before uninstalling. Once the "
"migration has completed, the safety guard will allow "
"uninstall.\n\n"
"If you genuinely want to uninstall WITHOUT migrating "
"(data will be lost), set the parameter %s to True manually.",
name, flag_key,
))
return True
def button_immediate_uninstall(self):
"""Override to invoke the safety guard before allowing uninstall."""
self._fusion_check_uninstall_guard(self.mapped('name'))
return super().button_immediate_uninstall()
def module_uninstall(self):
"""Override the lower-level uninstall path too (CLI / API uninstall)."""
self._fusion_check_uninstall_guard(self.mapped('name'))
return super().module_uninstall()