majid
majid

Reputation: 271

how to print record using report in odoo 11?

i am unable to print record using report, having error:

AttributeError: 'report.my_module.certificate_template' object has no attribute 'get_report_values'

Here is code below i am using.

class Reports(models.AbstractModel):
_name = 'report.my_module.certificate_template'

@api.model

def render_html(self, docids, data=None):
    report_object = self.env['report']
    report = report_object._get_report_from_name('my_module.certificate_template')
    docargs = {
          'doc_ids': docids,
          'doc_model': report.res_partner,
          'docs': self,  
    }
    return report_object.render('my_module.certificate_template', docargs)

Upvotes: 0

Views: 404

Answers (2)

Avani Somaiya
Avani Somaiya

Reputation: 348

You have to return an object like the following:

@api.model
def get_report_values(self, docids, data=None):
    report = self.env['ir.actions.report']._get_report_from_name('your_module.certificate_template')
    records = self.env['your_module_name'].browse(self.ids)
    return {
        'doc_ids': self._ids,
        'doc_model': report.model,
        'docs': records,
        'data': data
    }

Upvotes: 0

Avani Somaiya
Avani Somaiya

Reputation: 348

You just need to write the method name "get_report_values". Like the following:

    class Reports(models.AbstractModel):
       _name = 'report.my_module.certificate_template'

       @api.model
       def get_report_values(self, docids, data=None):
           report_object = self.env['report']
           report = report_object._get_report_from_name('my_module.certificate_template')
           docargs = {
                       'doc_ids': docids,
                       'doc_model': report.res_partner,
                       'docs': self,  
                     }
           return report_object.render('my_module.certificate_template', docargs)

So, you just need to change the method name.

I hope this helps you.Thank you.

Upvotes: 1

Related Questions