Skip to Content
Menu
This question has been flagged
1 Odpoveď
2351 Zobrazenia

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
Zrušiť
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
Zrušiť
Autor

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 Zobrazenia Aktivita
0
apr 24
1961
0
nov 23
1530
1
mar 24
1474
1
aug 23
4661
1
júl 23
2100