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

Call a report from a button

By
Milwell Sia
on 4/7/16, 6:24 AM 497 views

I'm using odoo8.  I have a Transient Model used in a Dialog Form.

The view has a button:

<button name="summary_report" type="object" string="Invoice Summary"/>

summary_report is defined in the transient model: mil.sales_report

 @api.one
def summary_report(self):
datas = {}
invoices = self.env['account.invoice'].search([
('company_id', '=', self.company_id.id)
])
context = dict({}, active_ids=invoices, active_model='account.invoice')
'''
datas = {
'ids':invoices,
'model':'account.invoice',
#'form':,
'context':self._context
}
'''
return {
'type': 'ir.actions.report.xml',
'report_name': 'mil_sales_report.invoice_summary_template',
'context': context
               }

I am trying to query the account.invoice model and pass the results to report 'mil_sales_report.invoice_summary_template'.
When I press the button widow closes and nothing happens.


0
Milwell Sia
On 4/8/16, 8:10 PM

It now works.  I changed the code to:

#needed for calling function from wizard, api.one will not work
 @api.multi
#function definition is in odoo v8 format
def summary_report(self):
#ensure that self contains only one record
self.ensure_one()
#get the model to query
invoiceModel = self.env['account.invoice']
#query the model
invoices = invoiceModel.search([
('company_id', '=', self.company_id.id)
])
#set the data
#ids is the list of ids, so have to pass <model>._ids
#model is the model name <model>._name or string literal
#form is the field list, I use <model>.read() to get all fields, read() can have parameter to only read specific fields
datas = {
'ids': invoices._ids,
'model': invoiceModel._name,
'form': invoiceModel.read(),
'context':self._context
}
#call the report
return {
'type': 'ir.actions.report.xml',
'report_name': 'mil_sales_report.invoice_summary_template',
'datas': datas
               }



0

Parikshit

--Parikshit--
939
| 6 3 8
Ahmedabad, India
--Parikshit--

Working as an OpenERP/Odoo developer both experience in web and addons. you can contact me at:

E-mail : parikshitvaghasiya@gmail.com

Blog : parikshitvaghasiya.blogspot.in

Stackoverflow : http://stackoverflow.com/users/5089106/parikshit-vaghasiya

Parikshit
On 4/7/16, 8:46 AM

def summary_report(self, cr, uid, ids, data, context=None):

if context is None:

context = {} #yourCode

return self.pool['report'].get_action(cr, uid, [], 'mil_sales_report.invoice_summary_template', data=datas, context=context)

 hope this will help you !

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: 4/7/16, 6:24 AM
Seen: 497 times
Last updated: 4/8/16, 8:11 PM