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

i have a new field that is computed and want to pass it to the qweb report. according to the document, if i am not mistaken i can do that using:


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

        }


but i'm not sure how is this called?

I wanted to add a custom data/field in the invoice report using the mentioned code above but when i tried logging something, it was not called.




Avatar
Discard
Best Answer

Hi,

While you calling the get_lines function from the doc_ids you can pass your own custom values in the get_lines() function

You can try these ways
def _get_report_values(self, docids, data=None):
//data contains the field values
lst = []
required_value = self.env['your.model'].search([])
// in this search you can add your own custom conditions
docs = self.env['hr.employee'].browse(docids)

for line in required_value:
    lst.append({
        'doc_ids': docs.ids,
        'doc_model': 'your.model',
        'name': line.name,
        'custom_field': data['custom-field],
        //You can add your own fields
    })
return {
    'data': lst,
}

XML :

<t t-call="module_name.inherited template_id">
    <t t-foreach="data" t-as="o">
        // you can add the fields here eg : <t t-esc="o['custom_field']"/>
    </t>
</t>

otherways you can add the details on the get_lines function

for example, if you used get_lines once you can override or super the function
def get_lines(self, line_id=None, **kw):
context = dict(self.env.context)
model = kw and kw['model_name'] or context.get('model')
rec_id = kw and kw['model_id'] or context.get('active_id')
level = kw and kw['level'] or 1
lines = self.env['model.name'].search([])
    // In the lines you can assign the values and that will return
   //The code contains your module details and the data so you can pass the value here
return lines

For more reference, you can refer to this Bloghttps://www.cybrosys.com/blog/how-to-create-a-custom-pdf-report-in-odoo-16 And https://www.cybrosys.com/blog/how-to-create-a-custom-report-in-the-odoo-16-portal-view

Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 23
4325
0
Mar 24
658
2
Apr 23
7892
1
Jan 21
4899
3
Sep 20
3926