Hi , please i want to know how to open a form view of another model on a new tab of the the browser by clicking on a button and passing it context
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Hi Dilaw Bej ,
It will open a new window or tab with the URL provided in the link. Here is a slightly refined version:
return {
'name': 'Go to New Window',
'res_model': 'ir.actions.act_url', 'type': 'ir.actions.act_url', 'url': link, # Your URL here
'context': context, 'target': 'new', # Opens in a new window/tab }
A few things to note:
- 'res_model': 'ir.actions.act_url' is not needed. The 'type': 'ir.actions.act_url' already specifies that it's a URL action.
- 'context': ctx is not required unless you specifically need to pass context for this URL. If you need it, ensure that ctx is defined beforehand. If not, you can remove this part.
Let me know if you need further modifications!
Thank you
Hi,
Let's say you have a model called model1 and you want to open a form
view of another model model2 in a new tab when a button is clicked. Here
are the steps:
add a button to trigger the action:
<record id="view_my_model_form" model="ir.ui.view">
<field name="name">my.model.form</fie
<field name="model">my.model</field>
<field name="arch" type="xml">
<form>
<!-- Your existing fields go here -->
<footer>
<button string="Open Other Model" class="oe_highlight" type="object" name="open_other_model"/>
</footer>
</form>
</field>
</record>
python :
from odoo import models, fields, api |
Create model 2 Python and xml files
Hope it helps
Hi,
You can open record in new tab with below code if your problem still not fixed.
class YourClass1(models.Model):
_name = 'model1'
def action_open_record_new_tab(self):
record_id = # define your record id to open record
model = 'model2' # Replace with the actual model name
# Construct the URL to open the record in a new tab
url = '/web#id=%s&model=%s' % (record_id, model)
# You Can add context for passing values
context = {
}
# Redirect to the URL
return {
'type': 'ir.actions.act_url',
'url': url,
'target': 'new', # Open in a new tab/window
'context': context,
}
In XML define button for method.
Thanks
if partner has already you can use below code:
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') url = f"{base_url}/web#id={partner_Id}&model=res.partner&view_type=form"
return { 'type': 'ir.actions.act_url', 'url': url, 'target': '_blank' }
here is my code in odoo 17 model res.partner. hope it be can help you!
But in this case it will open the second model as a wizard/pop-up ans not in a browser's new tab
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jan 24
|
2141 | ||
|
1
Jan 24
|
1435 | ||
|
0
Mar 24
|
1669 | ||
|
1
Oct 22
|
3300 | ||
|
0
Aug 22
|
3219 |