Odoo Help

1

Programatically Print a Report and Save it to disk on Server

By
Cyrus Waithaka
on 2/11/16, 6:03 PM 1,244 views

Hi people.

I am looking for a way to print a report, say a quotation and saving it to disk on the server. Anyone with an idea on how I can achieve this? 

The reason behind this is that we want to maintain pdf documents of all sales offers. 


I know I can programatically generate and add the report as an attachment, but again, how can I get that attachment from the file system.

2
Axel Mendoza
On 2/26/16, 10:08 PM

You are asking about two things

1- How to print a report(and get the binary data perhaps?)

result = self.pool.get('report').get_pdf(cr, uid, [res_id], report_name, context=ctx)

where:

  • res_id is the id of the object to use in the report related to the model of the report, 

  • report_name is the name of the report to print used to locate the report template

  • result is the binary data of the pdf report

2- How get an already saved Odoo report file

obj = self.pool.get(report.model).browse(cr, uid, rec_id)

filename = eval(report.attachment, {'object': obj, 'time': time})

alreadyindb = [('datas_fname', '=', filename),('res_model', '=', report.model),('res_id', '=', rec_id)]

attach_ids = self.pool.get('ir.attachment').search(cr, uid, alreadyindb)

if attach_ids:

pdf = self.pool.get('ir.attachment').browse(cr, uid, attach_ids[0]).datas

pdf = base64.decodestring(pdf)

where report is the record of the report located by name object and res_id the id of the object of the model of the report


About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/11/16, 6:03 PM
Seen: 1244 times
Last updated: 9/6/17, 7:26 AM