This question has been flagged
1 Reply
6477 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))
          self.localcontext.update({
               '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
Avatar
Discard
Best Answer

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"

@api.v7

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)

try:

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:

@api.multi
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

Avatar
Discard
Author

I check all this stuff thanks once again