Skip to Content
Menu
This question has been flagged
2 Replies
2007 Views

How can I show form view in new tab when click on tree view. that means I want to show a form view in new tab by clicking on tree view item. Please help.

Avatar
Discard
Best Answer

With the "ir.actions.act_url" you can open the view in a new tab by forming a URL of the view.

url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
url += '/web#id=%s&&model=sale.order&view_type=form' % self.id
return {
'type': 'ir.actions.act_url',
'target': 'new',
'url': url,
}


Avatar
Discard
Author

where I put this code? I create a new function called open_new_window and put this code in here. but its not working. here the code:
from odoo import models, fields, api, _

class Admission(models.Model):
_inherit = 'op.admission'

def open_new_window(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
url += '/web#id=%s&&model=op.admission&view_type=form' % self.id
return {
'type': 'ir.actions.act_url',
'target': 'new',
'url': url,
}

Not working means nothing happens when you click on a button or you are getting an error.

Author

I want to show form view from dashboard. the dashboard showing list view. If i click any list item the form view needs to show in another tab. cause when the form view showing the group by expand option are closed in dashboard. thats why I want to show the form view in new tab

Best Answer

The simplest way i can think of is to add a button in list view. 
when you click on this button you render a form view ( or a popup ) displaying all data you need.

your button's action must return smth like this: 

return {
"name": _("your text"),
"type": 'ir.actions.act_window',
'view_mode': 'form' "res_model": 'your model',
'view_id': ref to your form view id,
"views": [[False, "form"]],
"target": 'new',
"context": {
context if necessary
},
}


Avatar
Discard