Skip to Content
Menu
This question has been flagged

Hi,

I want to generate a custom PDF report with custom data fetched from a python method called from a button in a Wizard.

Report Template:


---------

Python Wizard Method:

from odoo import fields, models, api

class TDSReport(models.TransientModel):
​_name = 'tds.report.wizard'

​user_id = fields.Many2one('res.users')
​from_date = fields.Date()
​to_date = fields.Date()

​def generate_report(self):
​for record in self:
​custom_records = self.env['user.payment.tds'].search([domain])
//generate tds_report_document with custom_records data​

Thanks for the help

Avatar
Discard
Author

Report Template:

<template id="tds_report_document">
----------------
</template>

Best Answer

Hi,

Under specific circumstances, we must print the report using a wizard or button. In that case, we execute the report action from the earlier example using the print button inside the wizard or form.

This generates a report by executing a custom SQL query to retrieve truck booking data based on specific criteria.

def generate_report(self):

        query = """xxx """

        if self.from_date:

            query += """ where tb.date >= '%s' and tb.date

        self.env.cr.execute(query)

        report = self.env.cr.dictfetchall()

        data = {'date': self.read()[0],'report': report}

        return self.env.ref('module_name.action_report_booking').report_action(None, data=data)


For more info, please refer to the blog https://www.cybrosys.com/blog/how-to-create-pdf-report-in-odoo-16

Hope it helps,

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 23
3
3
Aug 24
2421
0
Aug 23
1309
1
Jul 23
1727
3
Mar 18
7341