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

Qweb Report based on wizard started from a menu!

By
Matjaz
on 2/18/16, 6:17 AM 988 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... :-(

0
Matjaz
On 2/19/16, 3:21 AM

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....

0

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 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 an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 2/18/16, 9:38 AM

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

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: 2/18/16, 6:17 AM
Seen: 988 times
Last updated: 2/19/16, 3:21 AM