跳至内容
菜单
此问题已终结
2 回复
7841 查看

Hi,

I'm trying to open a treeview from an action button. I can see the view ok but the create button doesn't work.

This is my code:

    @api.multi
def gestionar_adjuntos(self):
self.ensure_one()
empresas = self.env['empresas.onerate'].search([('vat', '=', self.vat)])
empresa_cli = empresas[0].id
result = {
'name': 'Gestionar archivos adjuntos',
'res_model': 'archivos.onerate',
'view_type': 'list',
'view_mode': 'list',
'type': 'ir.actions.act_window',
'domain': [('cliente_id', '=',empresa_cli)],
'flags': {'action_buttons': True},
'target':'main',
}
return result

What is wrong? Any idea?


形象
丢弃
最佳答案

It is because you have passed list in the view_type.

Try again by passing tree as follow:

'view_type': 'tree',
'view_mode': 'tree, form',
形象
丢弃
编写者

Thank you! i've already tried with this code but the view which is opened by default is the form instead of the tree

Pass your tree view in the return action as follow:

'view_id': self.env.ref('module_name.xml_id_of_tree').id

编写者

If i add the line whith the reference i get the errror:

TypeError: this.view_order[0] is undefined

I've tried too with view_id and i get the same error

ok then try with the following. I hope that will work.

tree_view_id = self.env.ref('module_name.xml_id_of_tree').id

form_view_id = self.env.ref('module_name.xml_id_of_form').id

'views': [(tree_view_id, 'tree'), (form_view_id, 'form')],

编写者

Thank you very much!! Finally I got it

The code which works is:

@api.multi

def gestionar_adjuntos(self):

self.ensure_one()

empresas = self.env['or.empresas'].search([('vat', '=', self.vat)])

empresa_cli = empresas[0].id

result = {

'name': 'Gestionar archivos adjuntos',

'res_model': 'or.archivos',

'type': 'ir.actions.act_window',

'views': [(False, 'tree'), (False, 'form')],

'domain': [('cliente_id', '=',empresa_cli)],

}

return result

最佳答案

You just need do below

return {
'name': _('test'),
'view_type': 'tree',
'view_mode': 'tree',
'view_id': self.env.ref('account.invoice_tree').id,
'res_model': 'account.invoice',
'context': "{'type':'out_invoice'}",
'type': 'ir.actions.act_window',
'target': 'new',
}
形象
丢弃
相关帖文 回复 查看 活动
2
7月 18
7387
2
6月 22
2110
3
11月 19
17545
2
7月 18
9704
0
7月 17
3867