Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
322 Visualizações

Where do i hard code that for example: when in the URL "model=res.partner" and "id=8", it should skip "id=8" and go to "id=9" instead.

this because you can manually change id's in the URL and i want to skip a certain one.


Thanks in advance!

Avatar
Cancelar
Melhor resposta

Hello odoonewbie ,

I believe the best approach to skip specific record IDs when accessed via the URL is to override the web controller responsible for handling record views and implement a redirection mechanism.

Solution: Override the Web Controller

from odoo import http from odoo.http import request class SkipRecordController(http.Controller): @http.route('/web', type='http', auth="user") def web_client(self, **kw): """ Redirect users to skip specific record IDs when accessed via the URL. """ model = kw.get('model') current_id = kw.get('id') # Convert ID to an integer if present if current_id: try: current_id = int(current_id) except ValueError: return request.redirect('/web') # List of IDs to be skipped skip_ids = [8] # Add additional IDs as needed if current_id in skip_ids: next_id = current_id + 1 # Define the next valid record ID kw['id'] = next_id # Update the ID parameter new_url = f"/web?model={model}&id={next_id}" return request.redirect(new_url) # Redirect to the next available record return request.render('web.webclient_bootstrap', kw)

If this helps, please upvote! 🚀 Let me know if you need any modifications. :)

Avatar
Cancelar
Autor

Hello Sujata,
this code provides me with an empty page when loading odoo. kindly advice :)
thank you in advance!