Odoo Help

0

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

By
Sairam Bandaru
on 12/8/15, 5:47 AM 985 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--
2932
| 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',

}


About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

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