From 79de643fc1a97ac36cb3d28fbb81060a7e68279d Mon Sep 17 00:00:00 2001 From: Erwan Gaynor Date: Thu, 4 Dec 2025 19:06:41 +0000 Subject: [PATCH] [ADD] util: view helper functions for active tag Helper functions for activating and disabling views. Addition of two functions to simplify the manipulation of the active state of ir.ui.view records. Function call is done through a util.disable_views(cr, (view_ids)), with view_ids being a list. util.activate_views(cr, (view_ids)) works the same way. --- src/util/records.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/util/records.py b/src/util/records.py index c0d1666fa..636f6771e 100644 --- a/src/util/records.py +++ b/src/util/records.py @@ -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]) + + +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"): """