Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
6146 Lượt xem

Hello,

I implemented a function in my model to show all attachments. While the function yields the correct result, I aim to open the output in a new tab. How can I achieve this?

def test_button(self):
​return {
​'type': 'ir.actions.act_window',
​'res_model': 'ir.attachment',
​'view_mode': 'kanban',
​ 'target': '_blank',
​ 'domain': [('res_model', '=', self._name), ('res_id', '=', self.id)],
​}

XML :




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Fabien,

In Odoo, the act_window action provides several targets such as current, new, inline, fullscreen, and main. You can try each of these targets, and if none of them meet your requirements for redirecting to a new tab, you can use the following approach:

python
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
record_url = base_url + '/web#id=' + str(self.id) + '&view_type=form&model=WWW&menu_id=XXX&action=YYY'

client_action = {
    'type': 'ir.actions.act_url',
    'name': 'ZZZ',
    'target': 'new',
    'url': record_url,
}

This code constructs a URL for the record based on its ID and other parameters, and then creates a client action of type ir.actions.act_url with a target set to new to open the URL in a new tab.

Hope it helps

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you for your reply. 

I attempted to modify the target attribute to "new," but this action still opens the results in the same window within a new pop-up. 

However, my intention is to have the results open in a new tab.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi

Hope everything is good 

you can try like below

def test_button(self):
​return {
​'type': 'ir.actions.act_window',
​'res_model': 'ir.attachment',
​'view_mode': 'kanban',
​ 'target': 'new',
​ 'domain': [('res_model', '=', self._name), ('res_id', '=', self.id)],
​}


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
9
thg 12 18
10379
5
thg 5 23
15906
1
thg 1 24
14843
2
thg 12 23
6070
1
thg 5 22
3071