Skip to content

Conversation

@erga-odoo
Copy link

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.

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.
@robodoo
Copy link
Contributor

robodoo commented Dec 4, 2025

Pull request status dashboard

@erga-odoo erga-odoo requested a review from deni-odoo December 4, 2025 19:11
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

@aj-fuentes
Copy link
Contributor

I don't think we will add a util to wrap simple queries. ;)

@KangOl
Copy link
Contributor

KangOl commented Dec 5, 2025

upgradeci retry with always only base

@erga-odoo
Copy link
Author

I don't think we will add a util to wrap simple queries. ;)

These functions can be useful though! Some team members or mine and I find myself disabling and reactivating views quite often. Maybe we can put these functions in local_util then? Let me know! :)

@aj-fuentes
Copy link
Contributor

I fail to see any significant improvement in

util.disable_views(cr, [1,2,3])

vs

cr.execute("UPDATE ir_ui_view SET active = False WHERE id = ANY(%s)", [[1, 2, 3]])

We cannot wrap every query that we reuse in a util function. That's not the purpose of the utils. The functions here are meant to wrap more involved behavior. Maybe in local_utils is fine if you esteem that the rate of mistakes in the simple query above is too high. I'd still say that we should make reviewers pay attention to what they review instead ;)

Anyway I don't want to impose my view. @KangOl up to you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants