Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to print a report with one button?

By
beriliox
on 2/25/16, 4:30 PM 1,152 views

Hi. I'm trying to print a report that is a Qweb view from one button . This button I assign a function ( def) that would print the view.

I saw another question in this forum on how to create a button but do not stay clear and not work for me.

This would be the button in the view:

<button name="%(ID VIEW)d" string="Print" type="action" icon="gtk-print"/>.

In my case my statement would be:

<button name="%(769)d" string="Print" type="action" icon="gtk-print"/>.

The problem is that the id of the view that I set, the button does not recognize and does not generate any action .Is okay this statement or maybe you have to do something else?

Please help me with this. Thanks to all.

Great!Thanks but a i've a problem with the function:

def check_report(self, cr, uid, ids, context=None):

if context is None:

context = {}

data = {}

data['ids'] = context.get('active_ids', [])

data['model'] = context.get('active_model', 'ir.ui.menu')

 

return self.pool['report'].get_action(cr, uid, [], 'custom_module.report_pricelist', data=data, context=context)

Odoo shows me the next message when I press the button .

"TypeError: print_report() takes at least 6 arguments (5 given)"

Thanks of all :)

beriliox
on 2/25/16, 4:30 PM

Please do not triple post the same question and sign in with different accounts.

Ermin Trevisan
on 2/26/16, 10:26 AM
1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 2/26/16, 12:30 AM

Hi,

One option is to define a python function to generate the report and call that function from the button.

For example:

<button name="check_report" string="Print pdf" type="object" icon="gtk-print"/>

in .py file

class custom_report_product_pricelist(models.TransientModel):

_name = 'custom.report.product.pricelist'

pricelist_type = fields.Selection([('partner', 'Partner Pricelist'), ('dealer', 'Dealer Pricelist')], 'Pricelist Type', default='dealer',required=True)


 

@api.v7

def check_report(self, cr, uid, ids, context=None):

if context is None:

context = {}

data = {}

data['ids'] = context.get('active_ids', [])

data['model'] = context.get('active_model', 'ir.ui.menu')

 

return self.pool['report'].get_action(cr, uid, [], 'custom_module.report_pricelist', data=data, context=context)

Define the qweb report and add it to report model:

<report

id="report_product_pricelist"

string="Pricelist"

model="product.template"

report_type="qweb-pdf"

file="custom_module.report_pricelist"

name="custom_module.report_pricelist"

     menu="False" />


The qweb template ID is also "report_pricelist".  This is just an example code, which I did to print report from a button on the wizard. Might be helpful to you.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/25/16, 4:30 PM
Seen: 1152 times
Last updated: 2/26/16, 2:32 PM