This question has been flagged
4 Replies
9831 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.

Avatar
Discard
Best Answer

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


Avatar
Discard
Best Answer

you can try this: 

  1. import os 
  2. import shutil 
  3.  
  4. destination_directory = os.get_cwd() + '/some_directory' 
  5. if not os.path.exists(destination_directory): 
  6. os.mkdir(destination_directory) 
  7. path_to_html_file = "path/to/html/file" 
  8. shutil.copy2(path_to_html_file, os.path.join(destination_directory,path_to_html_file)) # file copied to another directory. 


Avatar
Discard
Best Answer


<a href="https://www.javacodegeeks.net" target="_blank">https://www.javacodegeeks.net</a>


<a href="http://www.welookups.com/" target="_blank">http://www.welookups.com/</a>

Avatar
Discard
Best Answer

Anybody knows how to save it in a specific directory?

Avatar
Discard

why would you want to do that if you can save it in the db with the fields.Binary? If you really want to you'll need to use python write https://www.programiz.com/python-programming/file-operation but you'll probably run into permission problems on the server and you'll have to get the path where to store from the server admin.