Odoo Help

1

Odoo8. Send file to browser to download (Save As..)

By
Keywoker
on 4/6/15, 4:43 AM 1,560 views

Hello. How can I send the file, what I have on the disk, to my browser to download, like "save as? Or how can I do that when I've finished to compose my csv? Thanks.

Do you have the solution, I am looking for it too.

JC
on 12/20/15, 10:44 PM

Hello.
I used a binary field for that. It's not what I looked for, but I have only this solution. The question is not actual for me now, but I think there is another way.

--
Отправлено из Mail.Ru для Android

понедельник, 21 декабря 2015г., 09:44 +06:00 от JC jcchua-gmail.com@mail.odoo.com>:


Do you have the solution, I am looking for it too.

--
JC

Keywoker
on 12/21/15, 3:13 AM
1
Cyril Gaspard (GEM)
On 4/6/15, 6:07 AM

Hi,

"saveas" or "saveas_ajax" python functions are in module web/controllers/main.py in class Binary (but I think you should create yours using what you need in saveas method, because this function use attachment)

(v8) : def saveas(self, model, field, id=None, filename_field=None, **kw):

bye

Thank you for your answer. I know everything you're speaking about, but maybe you didn't understand what I want to get as result. I have the module, where I make my own .csv file and after making process I need to download it via my browser. How can I do that? How can I send it to browser?

Keywoker
on 4/6/15, 6:18 AM

Sorry, it's not very clear => I have the module, where I make my own .csv file (you edit it in odoo ?), => after making process (what process); you should explain all actions you are doing, where ... bye

Cyril Gaspard (GEM)
on 4/6/15, 7:01 AM

In the module I make new csv file? like this out = csv.writer(open("new_file.csv"), delimiter=','). And then I write to this file everything I want. And as result, I want to download the file, new_file.csv, via my browser.

Keywoker
on 4/6/15, 7:55 AM

answer updated

Cyril Gaspard (GEM)
on 4/6/15, 8:35 AM
1
Temur
On 4/6/15, 8:24 AM

you can use binary field I think, add a binary field to your model and when you make new csv file, save this file to the binary field. you'll be able then to download it (normally with binary field you'll have upload too.. but if you try to set this field to readonly, then maybe upload will be disabled(?))

0
deep
On 11/16/16, 1:23 AM

You can use URL-Action to send your file, but before that, you need to dump the data into IRAttachment, then use this attachment to download the file via Browser(URL)

A sample snippet as follows: (in my case am writing into an Excel File & returning the same as downloaded)

# Attach & Print: Excel File 
out = base64.encodestring(result_ExcelFile)
 
attachment = self.env['ir.attachment'].create({
'name': <file_name>,
'datas': out,
'datas_fname': <file_name>,
'res_model': self._name,
'res_id': self.id,
'type': 'binary'})
 
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
 
return {'type' : 'ir.actions.act_url',
'url': base_url + '/web/content/%s/%s'%(attachment.id, <file_name>),
'target': 'self',
}


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: 4/6/15, 4:43 AM
Seen: 1560 times
Last updated: 11/16/16, 1:23 AM