refactor(fusion_accounting): move security groups to _core, add multi-company session rule

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 00:14:36 -04:00
parent 10140a6968
commit 7ac01991e5
13 changed files with 237 additions and 151 deletions

View File

@@ -61,7 +61,31 @@ AI_NAME_LIKE = (
)
# Group/category/privilege xml-ids that moved from 'fusion_accounting' to
# 'fusion_accounting_core' in Phase 0 (Task 16). Both _core and _ai
# post-migrations run this same UPDATE — whichever runs first wins, the other
# is a no-op. We reassign these here too so that if _ai happens to upgrade
# first (before _core's own post-migration has had a chance to run) the groups
# are still rehomed correctly.
CORE_SECURITY_NAMES = (
'module_category_fusion_accounting',
'res_groups_privilege_fusion_accounting',
'group_fusion_accounting_user',
'group_fusion_accounting_manager',
'group_fusion_accounting_admin',
)
def migrate(cr, version):
# Step 0: Reassign security groups/category/privilege to fusion_accounting_core.
cr.execute("""
UPDATE ir_model_data
SET module = 'fusion_accounting_core'
WHERE module = 'fusion_accounting'
AND name = ANY(%s)
""", (list(CORE_SECURITY_NAMES),))
moved_to_core = cr.rowcount
# Step 1: Delete orphan rows that conflict with an already-existing row in
# fusion_accounting_ai (data-load artifact). The new row is the survivor.
cr.execute("""
@@ -76,7 +100,7 @@ def migrate(cr, version):
""", (list(AI_MODEL_PREFIXES), list(AI_NAME_LIKE)))
deleted_conflicts = cr.rowcount
# Step 2: Reassign the non-conflicting orphans.
# Step 2: Reassign the non-conflicting orphans to fusion_accounting_ai.
cr.execute("""
UPDATE ir_model_data
SET module = 'fusion_accounting_ai'
@@ -86,12 +110,14 @@ def migrate(cr, version):
OR name LIKE ANY(%s)
)
""", (list(AI_MODEL_PREFIXES), list(AI_NAME_LIKE)))
moved = cr.rowcount
moved_to_ai = cr.rowcount
_logger.info(
"fusion_accounting_ai post-migration: deleted %d conflicting orphans, "
"reassigned %d ir_model_data rows from module='fusion_accounting' "
"to module='fusion_accounting_ai'",
"fusion_accounting_ai post-migration: reassigned %d security rows to "
"fusion_accounting_core, deleted %d conflicting AI orphans, reassigned "
"%d ir_model_data rows from module='fusion_accounting' to "
"module='fusion_accounting_ai'",
moved_to_core,
deleted_conflicts,
moved,
moved_to_ai,
)