Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,34 @@ def remove_view(cr, xml_id=None, view_id=None, silent=False, key=None):
remove_records(cr, "ir.ui.view", [view_id])


def disable_views(cr, view_ids):
"""
Disable views with a query.

:param view_ids: a list of view ids or a singular view id.
"""
if not view_ids:
return
if isinstance(view_ids, int):
cr.execute("UPDATE ir_ui_view SET active='f' WHERE id = %s", [view_ids])
else:
cr.execute("UPDATE ir_ui_view SET active='f' WHERE id IN %s", [view_ids])
Copy link

@deni-odoo deni-odoo Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions ->

  • there should probably also be a instance check for list/tuple in case of multiple view_ids
  • both cases of single/multiple views can be handled with the IN operator, something like
Suggested change
cr.execute("UPDATE ir_ui_view SET active='f' WHERE id IN %s", [view_ids])
if isinstance(view_ids, int):
views_to_update = list(view_ids)
if isinstance(view_ids,list):
views_to_update = view_ids
if views_to_update:
cr.execute("UPDATE ir_ui_view SET active='f' WHERE id IN %s", [tuple(view_ids)])
  • same comment for activate



def activate_views(cr, view_ids):
"""
Activate views with a query.

:param view_ids: a list of view ids or a singular view id.
"""
if not view_ids:
return
if isinstance(view_ids, int):
cr.execute("UPDATE ir_ui_view SET active='t' WHERE id = %s", [view_ids])
else:
cr.execute("UPDATE ir_ui_view SET active='t' WHERE id IN %s", [view_ids])


@contextmanager
def edit_view(cr, xmlid=None, view_id=None, skip_if_not_noupdate=True, active="auto"):
"""
Expand Down