Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to return a view from the method in new API v8?

By
Sairam Bandaru
on 12/8/15, 5:47 AM 661 views

Hi

I want to return a view from the button (object type) I written following code,but its not working 

@api.one

def generate_report(self):

return {

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

'res_model': 'leave.csv.report',

'view_mode': 'form',

'view_type': 'form',

'res_id': self.id,

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

'target': 'new',

}

Please help me out

1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 12/8/15, 7:12 AM

Change @api.one to @api.multi 

@api.one can NOT be used here, as it iterates automatically over "ids" recordset and puts result of each iteration into the python list, finally the list is returned. so in your case, what is really returned from your function because of @api.one, that is: 

[ {

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

'res_model': 'leave.csv.report',

'view_mode': 'form',

'view_type': 'form',

'res_id': self.id,

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

'target': 'new',

} ]

that's why it does not work. you can get it worked either with @api.multi or @api.model,

@api.multi will still work, as self.id will take id of the first record from recordset, so you have NOT to change function body:

@api.multi

def generate_report(self):

return {

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

'res_model': 'leave.csv.report',

'view_mode': 'form',

'view_type': 'form',

'res_id': self.id,

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

'target': 'new',

}


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/8/15, 5:47 AM
Seen: 661 times
Last updated: 12/8/15, 8:08 AM