Skip to content

Commit

Permalink
[IMP] util.uninstall_module: handle order of remval of records
Browse files Browse the repository at this point in the history
Due to the SQL constraints (`ON DELETE RESTRICT`), some records needs to
be remove before others.

closes #148

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Nicolas Seinlet <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
  • Loading branch information
3 people committed Oct 28, 2024
1 parent 30a83e5 commit c47b904
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/util/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ def uninstall_module(cr, module):
)

# delete data
model_ids, field_ids, menu_ids, server_action_ids = [], [], [], []
model_ids, field_ids, menu_ids = [], [], []

# some models' data needs to be remove before or after others.
firsts = ["ir.rule"]
lasts = ["ir.actions.server"]

cr.execute(
"""
SELECT model, res_id
Expand All @@ -156,9 +161,11 @@ def uninstall_module(cr, module):
AND module != d.module)
AND module = %s
AND model != 'ir.module.module'
ORDER BY id DESC
ORDER BY array_position(%s::text[], model::text) NULLS LAST,
array_position(%s::text[], model::text) NULLS FIRST,
id DESC
""",
[module],
[module, firsts, lasts],
)
to_group = []
for model, res_id in cr.fetchall():
Expand All @@ -168,8 +175,6 @@ def uninstall_module(cr, module):
field_ids.append(res_id)
elif model == "ir.ui.menu":
menu_ids.append(res_id)
elif model == "ir.actions.server":
server_action_ids.append(res_id)
else:
to_group.append((model, res_id))

Expand All @@ -179,8 +184,6 @@ def uninstall_module(cr, module):
remove_view(cr, view_id=res_id, silent=True)
else:
remove_records(cr, model, [it[1] for it in group])
if server_action_ids:
remove_records(cr, "ir.actions.server", server_action_ids)

if menu_ids:
remove_menus(cr, menu_ids)
Expand Down

0 comments on commit c47b904

Please sign in to comment.