Community mailing list archives

community@mail.odoo.com

Re: additional parameter to qweb report

by
Phillip
- 08/01/2016 12:22:01
You could take a look at Odoo Development Cookbook. The topic is covered briefly. There may be a better way to do it however I would define the report function as an abstract model and you should create your wizard just like normal. Create a function in your wizard with opens a new tab in the browser which generates your report. All odoo reports can be called directly by opening a tab to a url. Create a function like this in your wizard, pointing at the AbstractModel you defined to create your report.

     @api.multi
    def print_report(self):
        record_id = self.env['your.model'].browse([some_id]).id
        return {
            'type' : 'ir.actions.act_url',
            'url' : "%sreport/pdf/model.report_id/%d" % (request.httprequest.url_root,record_id),
            'target' : 'new',
        }

So in your wizard definition you need to be able to identify the record you wish to print a report for. Use that as the id in your url. In your wizard view definition create a smart button which will call the function which will open the url to the report you wish to print.

Odoo reports can be accessed in the browser using the following path.

http://127.0.0.1:8069/report/pdf/model_name.report_id/record_id
http://127.0.0.1:8069/report/html/model_name.report_id/record_id

Ensure the url in your ir.actions.act_url will open the appropriate report and record id.

Once the report is open in the browser you can print it, save it, whatever you like.

On 2016-07-30 03:52 AM, shabeer m wrote:
hi philip is there any document that differentiate models.AbstractModel and models.TransientModel

coz i want to initiate report from wizard 
i am using odoo 9 community


thanks  

On Fri, Jul 29, 2016 at 6:03 PM, Phillip <phillips@aimsystems.ca> wrote:

You need to define an AbstractModel for your report. Then when you call your report in odoo it will run the function render_html() for your report.

class AttendeesReport(models.AbstractModel):
    _name = 'report.your_model.report_id'

    @api.multi
    def render_html(self, data=None):
        _logger.info("Creating Attendees Report")
        report_obj = self.env['report']
        report = report_obj._get_report_from_name('your_model.report_id')

        # docs: the recordset you plan on passing to your report

        docs = self.env['your.model'].browse(self._ids)

        foo = "bar"

        docargs = {
            'doc_model': report.model,
            'docs': docs,
            'foo': foo,
            'additional_arg':"my_arg"
        }
        return report_obj.render('your_model.report_id', docargs)






On 2016-07-29 07:52 AM, shabeer m wrote:
this is not working in my case 

"'NoneType' object has no attribute '__getitem__'" while evaluating
"datas['unit_id'][0]": (<class 'openerp.exceptions.QWebException'>, QWebException(ValueError(u'"\'NoneType\' object has no attribute \'__getitem__\'" while evaluating\n"datas[\'unit_id\'][0]"',),), <traceback object at 0x7f39d64a6ef0>)

On Fri, Jul 29, 2016 at 1:43 PM, Jesús Ventosinos <jesus@comunitea.com> wrote:

2016-07-29 8:57 GMT+02:00 shabeer m <msg2shabeer@gmail.com>:
hi community,
how do i pass an additional argument to a qweb report and how can i use it in report,

passing variable through wizard

thanks in advance 

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
with regards
Shabeer M
Contact : 94 00 7 44 77 6

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
with regards
Shabeer M
Contact : 94 00 7 44 77 6

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe