Skip to Content
Menu
This question has been flagged
2 Replies
9969 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.


Avatar
Discard
Author Best Answer

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
               }



Avatar
Discard
Best Answer

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 !

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 22
4634
1
Mar 16
4752
2
Mar 15
6351
0
Oct 24
165
0
Aug 24
167