Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
7827 Prikazi

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?


Avatar
Opusti
Best Answer

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',
Avatar
Opusti
Avtor

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

Avtor

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')],

Avtor

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

Best Answer

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',
}
Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
jul. 18
7380
2
jun. 22
2105
3
nov. 19
17539
2
jul. 18
9696
0
jul. 17
3865