Odoo Help


How to get value from data variable in the report paser class?

Pascal Tremblay
on 2/16/16, 5:57 PM 1,743 views

Hello all,

I'm in Odoo 8.

Thanks to help

My wizard class send data variable like this to the report. I know it works because I see it in the log.

class create_deposit_wizard(models.Model):
   _name = 'create.deposit.wizard'
    _description = 'Create a new deposit'
    journal_id = fields.Many2one('account.journal', string='Journal du depot')
    date_from =  fields.Datetime("Start Date")
    date_to = fields.Datetime("End Date")
    def print_report(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
        data = {}
        data['form'] = self.read(cr, uid, ids, ['journal_id', 'date_to', 'date_from'], context=context)[0]

        _logger.error("print_report in create_deposit_wizard BEGIN")
        _logger.error("ids :: " + str(ids))
        _logger.error("data :: " + str(data))
        _logger.error("context :: " + str(context))
        return self.pool['report'].get_action(cr, uid, [], 'sale_lapagept.report_create_deposit_cf', data=data, context=context)

But I'm not able to recup the data variable in the report parser. What is wrong?

class create_deposit_cf(report_sxw.rml_parse):     
     def __init__(self, cr, uid, name, context):
          super(create_deposit_cf, self).__init__(cr, uid, name, context=context)
          _logger.error("context :: %s", str(context))
               'prout': 'prout',
               'liness': 'lines',
          _logger.error("data", str(data['form']))

I get this error :

  File "/home/odoo-test/addons_pt/sale_lapagept/report/report_create_deposit_cf.py", line 16, in __init__
    _logger.error("data", str(data['form']))
NameError: global name 'data' is not defined

Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 2/16/16, 6:41 PM

Seems that you are trying to logging the data variable without had been defined previously. But also there is an error in the get_action method of the report module. The dict needed to be returned need to contains 'datas' instead of 'data' beause that is what it's expected in the report controller, so you will not be able to receive anything. You could fix it like this:

class Report(osv.Model):

_name = "report"

_inherit = "report"


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

"""Return an action of type ir.actions.report.xml.

:param ids: Ids of the records to print (if not used, pass an empty list)

:param report_name: Name of the template to generate an action for


if ids:

if not isinstance(ids, list):

ids = [ids]

context = dict(context or {}, active_ids=ids)

report_obj = self.pool['ir.actions.report.xml']

idreport = report_obj.search(cr, uid, [('report_name', '=', report_name)], context=context)


report = report_obj.browse(cr, uid, idreport[0], context=context)

except IndexError:

raise osv.except_osv(

_('Bad Report Reference'),

_('This report is not loaded into the database: %s.' % report_name)


return {

'context': context,

'datas': data,

'type': 'ir.actions.report.xml',

'report_name': report.report_name,

'report_type': report.report_type,

'report_file': report.report_file,

'context': context,

That was only the half way. To be able to get the data you need to create a new abstract model implementing the method like this example:

def render_html(self, data):
# or
#def render_html(self, cr, uid, ids, data=None, context=None):

self.model = self.env.context.get('active_model')

docs = self.env[self.model].browse(self.env.context.get('active_id'))

docargs = {

'doc_ids': self.ids,

'doc_model': self.model,

'data': data['form'],

'docs': docs,

'time': time,

'variable': 'value',


return self.env['report'].render('account.report_generalledger', docargs)

And that it's another way of implements parsers. I just discovered trying to find the answer for your question. See the class PosInvoiceReport or for an example of how to do it

I check all this stuff thanks once again

Pascal Tremblay
on 2/16/16, 8:32 PM

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.


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

2 follower(s)


Asked: 2/16/16, 5:57 PM
Seen: 1743 times
Last updated: 2/18/16, 7:41 PM