Skip to Content
Menu
This question has been flagged

I need to modify the invoice report like totally change the way it looks and i have read through the odoo qweb docs (https://www.odoo.com/documentation/16.0/developer/reference/backend/reports.html)   and saw the Custom Reports section but i don't really understand how it works.


from odoo import api, models


class ParticularReport (models.AbstractModel):

    _name = 'report.module.report_name'


    def _get_report_values (self,docids,data= None ):

        # get the report action back as we will need its data

        report = self.env['ir.actions.report']._get_report_from_name('module.report_name')

        # get the records selected for this rendering of the report

        obj = self.env[report.model].browse(docids)

        # return a custom rendering context

        return {

            'lines': docids.get_lines()

        }



Avatar
Discard
Best Answer

Hi,

You can try the Python code like this
from odoo import models

class ParticularReport(models.AbstractModel):
    _name = 'report.module.report_name'

    @api.model
    def _get_report_values(self, docids, data=None):
        # Retrieve the records for this report
        records = self.env[self.env.context.get('active_model')].browse(docids)

        # Define the data to pass to the report template
        report_data = {
            'records': records,  # Pass the records for template usage
        }

        return report_data

Please note that this is just the Python part of the customization. You will also need to create an XML template that defines the actual structure and layout of your report. This template should be placed in your custom module's reports folder and should be associated with the report you're customizing.
For more information, you can refer to this blog: https://www.cybrosys.com/blog/how-to-create-a-custom-pdf-report-in-odoo-16

Hope it helps

Avatar
Discard
Author

hello. i did that but it says the record is missing when i created a new template. see my changes here: https://www.odoo.com/it_IT/forum/assistenza-1/how-to-get-passed-values-from-qweb-report-231993

Related Posts Replies Views Activity
0
Apr 24
1825
0
Nov 23
1410
1
Mar 24
1474
1
Aug 23
4474
1
Jul 23
1931