This question has been flagged
2 Replies
8002 Views

I am trying to create a qweb report that is not based on certain record of module, but I would create a dictionary of records

and pass them to qweb template. I've done this on RML reports but here 'data['form'] is not recognized of qweb template. Data is empty.

User starts a wizard from a menu, where he selects month and year. After that data is prepared as a dictionary and is passed to the report.

Wizard part:

datas = {
     'ids': ids,
, 'model': 'report.environmental.oils.wizard',
 'form': data
}
return {
     'type': 'ir.actions.report.xml',
     'report_name': 'mga_reports.report_environmental_oils',
data': datas, }

Report declaration:

<report        
id="action_report_environmental_oils"     
model="report.environmental.oils.wizard"     
name="mga_reports.report_environmental_oils"     
file="mga_reports.report_environmental_oils"     
report_type="qweb-pdf"     
menu="False"     
string="Environmental oils report"/>


I am not sure what model should I use in report definition, because report is not based on one, data will be computed from several one. I have also created parser file and data argument that comes in is empty

@api.multidef render_html(self, data=None):    
    report_obj = self.env['report']
    report = report_obj._get_report_from_name('mga_reports.report_environmental_oils')
    docargs = {
        'doc_ids': self._ids,
        'doc_model': report.model,
        'docs': self,          
} return report_obj.render('mga_reports.report_environmental_oils', docargs)


When I use data in qweb template data is empty in a got error.

<p t-esc="data['form']['date_from']"/>


Could someone help me with that case. I'm kind of lost... :-(

Avatar
Discard
Author Best Answer

Thanks Axel,

I already have parser with render_html method and since I have an id from wizard I can do all the 'calculation' / preparing data dictionary there and than pass than dictionary to docargs. It just took me a day of tests to find out that dictionary passed to docargs in parser class are recognized in Qweb template while passing it as a result of wizard as (data or datas) not.

@api.multi
def render_html(self, data=None):
         report_obj = self.env['report']
         report = report_obj._get_report_from_name('mga_reports.report_environmental_oils')
         dict_mydata = { ..do some calculation and prepare a dictionary.. }
         docargs = {
             'doc_ids': self._ids,
             'doc_model': report.model,
             'docs': self,
           'mydata': dict_mydata
        }
        return report_obj.render('mga_reports.report_environmental_oils', docargs)

But a lot of reports in Odoo are done as passing as a result of wizard, but all are based on certain model and mine doesn't.

Ok, I found a solution, but If someone has an answer to why do I have to use parser and Odoo reports doesn't....

Avatar
Discard
Best Answer

You are good to go with your code and the only way to receive the data in your parser is implementing the parser using an AbstractModel with the render_html method. The only thing is that 'datas' is what it's expected in the report controller to call your parser. You need to change your code:

return {

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

'report_name': 'mga_reports.report_environmental_oils',

'datas': datas,

It's a bug or something missed on the get_action method of the report module that use 'data' instead of 'datas' in the return dict, but datas find it's way to the parser ok

Avatar
Discard