Question says all. I've created SQL tree view that displays some data. When I click on one of the rows, it doesn't redirect me to the form view. The view fields are just Many2ones that reference main model.
This question has been flagged
Hi,
The issue is that clicking a row in a tree view redirects to the form view of that same model. If your tree is built on a custom SQL view/model, Odoo looks for a form view on that model; which doesn't exist, so nothing happens.
To redirect to the form view of the main model (the one the Many2one points to), you have two options:
Option 1; Add open_rec method on the SQL model:
def open_record(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'your.main.model',
'view_mode': 'form',
'res_id': self.main_model_id.id,
'target': 'current',
}
Then add a button in the tree view that calls it.
Option 2; Use optional Many2one column with built-in redirect:
In your tree view XML, make the Many2one field clickable by ensuring it's a proper many2one widget; clicking it natively opens the related record's form view:
<field name="main_model_id" />
Clicking the Many2one value in the list will open the linked record's form directly; no extra code needed.
Option 2 is the simplest if you just need the user to navigate to the related record.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up| Related Posts | Replies | Views | Activity | |
|---|---|---|---|---|
|
|
1
Sep 23
|
6609 | ||
|
|
1
Oct 16
|
12553 | ||
|
|
1
Mar 15
|
7191 | ||
|
|
3
Mar 24
|
19981 | ||
|
|
2
Jun 22
|
5701 |
Will this help ? https://www.youtube.com/watch?v=GYn1J80xZh8