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.

1

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

By
Keywoker
on 4/6/15, 4:43 AM 896 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)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

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

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
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

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

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',
}


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