This question has been flagged
4 Replies
7714 Views

Hi all,

I need to make a report when generate with button click. also I need to show the odoo error message when report has no data. anyone can tell me the simple method to do this. 

Avatar
Discard

Hello Rishan,

way : 1):Just check your data on button click which you are using / fetching in report and if not data found raise warning in that button's method it self.

way : 2) def render_html() / def get_report_values() ->(in v11) Do check in this method , this method will be called when you print any qweb report.just check here your data and raise warning accordingly !

Thanks!

Author

Hi Dipak,

Thanks for your answer. do you have any example?

Best Answer

Try this:

if docs:
    return {
'doc_ids': data['ids'],
'doc_model': data['model'],
'date_start': date_start,
'date_end': date_end,
'docs': docs,
    }
else:
    raise UserError(_("""No Data\n""") )
 


Avatar
Discard
Best Answer

Hello Rishan,

You can do like below.

i n  render_html you can raise error message, if you set you report names like below

class YourModuleName (models.AbstractModel):

_ name = 'report.module_name.template_name'

@ api.multi
def render_html (self, docids, data = None):
    report_obj = self.env ['report']
    raise UserError (_ ('Example Error Message!')) 
    report = report_obj._get_report_from_name ('modulename.template_name' ) 
    docargs = {} 
    docargs.update ({
        'doc_ids': docids,
        'doc_model': 'mrp.production',
        'docs': mrp,
})
return report_obj.render ('modulename.template_name', docargs)

in report view

<report> .....

file = "modulename.template_name" 
name = "modulename.template_name"

and..

<template  ​id  ="template_name">

Please try like this if not worked, Please ask me.


Avatar
Discard