Skip to Content
Menu
This question has been flagged
1 Reply
14300 Views

Hi, I want to pass data to qweb report and print that data in report.

python code:

pdf = self.env['report'].sudo().get_pdf(self.ids, report_name, data={'test_variable': 'test_passed'}) 

report template :


<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <report id="my_module.report_id" model="my_module.report_model" string="Some Model Report" report_type="qweb-pdf" name="my_module.daily_report" file="my_module.daily_report_file" menu="False"/>
        <template id="my_module.daily_report">
            <t t-call="report.html_container">
                <t t-call="report.internal_layout">
                    <div class="page">
                        <div class="header">
                            <h4>HEADER</h4>
                            <-- i want to see "test_passed" value below -->
                            <span t-esc="data.test_variable"/>

                        </div>
                    </div>
                </t>
            </t>
        </template>
    </data>
</odoo>

When i create a pdf, i don't see variable value.

I am working on odoo-10 .


Avatar
Discard
Best Answer

Hi,

you can use this code to pass data


from odoo import models, api

class ReportClassName(models.AbstractModel):
_name = 'report.module_name.report_name'

@api.model
def render_html(self, docids, data=None):
docargs = {
'doc_ids': self.ids,
'doc_model': self.model,
'data': data,
}
return self.env['report'].render('module_name.report_name', docargs)
Insert this code in your .py file to pass data to report
To print data in qweb report you can use this code
<t t-esc="data"/>
For creating custom report in odoo10 refer this link

Avatar
Discard
Author

Thank you, but i need to pass variable in get_pdf method because i need pdf as an output.

Related Posts Replies Views Activity
2
Sep 24
216
1
Apr 24
484
2
Jul 21
3221
1
Jun 24
452
1
Jul 21
2333