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.
Câu hỏi này đã bị gắn cờ
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.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký| Bài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
|---|---|---|---|---|
|
|
1
thg 9 23
|
6717 | ||
|
|
1
thg 10 16
|
12618 | ||
|
|
1
thg 3 15
|
7230 | ||
|
|
3
thg 3 24
|
20024 | ||
|
|
2
thg 6 22
|
5783 |
Will this help ? https://www.youtube.com/watch?v=GYn1J80xZh8