Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2401 Widoki

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()

        }



Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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

Powiązane posty Odpowiedzi Widoki Czynność
0
kwi 24
1996
0
lis 23
1578
1
mar 24
1474
1
sie 23
4689
1
lip 23
2158