콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
9 답글
7586 화면

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.

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

베스트 답변

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


아바타
취소
베스트 답변

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?

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

작성자

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.

answer updated

베스트 답변

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(?))

아바타
취소