beriliox
beriliox

Reputation: 267

How to print a report for each product independently?

I have a form view in the sale.order model. I added a button to print a report for each product independently in Form view.

Is it possible to do that?

The following image explains the above better.

Image: http://es.zimagez.com/zimage/formview.php

What I want is that pressing the button to print a product, it prints a report of that product specifically . So add a button for each row.

This is the button to print the method:

<button name="print_report" string="Print Service Ticket" type="object" icon="gtk-print"/>


    @api.multi
    def print_report(self):    
        return self.env['report'].get_action(self, 'sale.ticket_servicio')

And this is my report view :

<report 
            id="ticket_servicio"
            string="Ticket de Servicio"
            model="sale.order" 
            report_type="qweb-pdf"
            file="sale.ticket_servicio" 
            name="sale.ticket_servicio"
/>

That is all. Thank you very much for your time and dedication. I appreciate any advice , suggestions and assistance.

Upvotes: 1

Views: 155

Answers (1)

simahawk
simahawk

Reputation: 2431

It seems you didn't do proper searching on google, since the web is plenty of such examples. Anyway, you should return the action BUT you must pass it some arguments, like the id/s of the item/s you want to print. Something like:

return {
    'type': 'ir.actions.report.xml', 
    'report_name':'my.report.name',
    'datas': {
            'model':'my.model',
            'id': ids and ids[0] or False,
            'ids': ids and ids or [],
        }
}

note the you can read default data from the action itself (is just an object in the database) and then inject the ids in the dictionary you get back.

Upvotes: 1

Related Questions