Skip to content

Commit c47b904

Browse files
KangOlnseinletaj-fuentes
committed
[IMP] util.uninstall_module: handle order of remval of records
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]>
1 parent 30a83e5 commit c47b904

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/util/modules.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ def uninstall_module(cr, module):
143143
)
144144

145145
# delete data
146-
model_ids, field_ids, menu_ids, server_action_ids = [], [], [], []
146+
model_ids, field_ids, menu_ids = [], [], []
147+
148+
# some models' data needs to be remove before or after others.
149+
firsts = ["ir.rule"]
150+
lasts = ["ir.actions.server"]
151+
147152
cr.execute(
148153
"""
149154
SELECT model, res_id
@@ -156,9 +161,11 @@ def uninstall_module(cr, module):
156161
AND module != d.module)
157162
AND module = %s
158163
AND model != 'ir.module.module'
159-
ORDER BY id DESC
164+
ORDER BY array_position(%s::text[], model::text) NULLS LAST,
165+
array_position(%s::text[], model::text) NULLS FIRST,
166+
id DESC
160167
""",
161-
[module],
168+
[module, firsts, lasts],
162169
)
163170
to_group = []
164171
for model, res_id in cr.fetchall():
@@ -168,8 +175,6 @@ def uninstall_module(cr, module):
168175
field_ids.append(res_id)
169176
elif model == "ir.ui.menu":
170177
menu_ids.append(res_id)
171-
elif model == "ir.actions.server":
172-
server_action_ids.append(res_id)
173178
else:
174179
to_group.append((model, res_id))
175180

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

185188
if menu_ids:
186189
remove_menus(cr, menu_ids)

0 commit comments

Comments
 (0)