Odoo Help


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.


write to a local file

on 8/21/13, 6:08 AM 1,801 views

Hi, I'm trying to create a file and write to it, but the file is not created. Here's my code:

            f.write("this is a test")

This code works well outside openerp, but it's not working when it's integrated into a module, the file is not created. Any help would be appreciated.

Pinakin Nayi (pna)
On 8/21/13, 6:56 AM

Hi, you can also do with following :


Thank you, but that code does not work in Openerp, but works outside it:

on 8/21/13, 7:30 AM

I think there is something wrong at your end, i test the same code in openerp and its work perfectly to me.

Pinakin Nayi (pna)
on 8/21/13, 7:32 AM

I think that too. Where did you test your code? Did you write a custom module for that?

on 8/21/13, 7:44 AM

Actually that is not matter, you can write it anywhere in openerp, but for test in addons/sale/sale.py in def action_button_confirm(self, cr, uid, ids, context=None): in this just write like open('/home/xxx/xxxx/test.txt','wb').write('Testing') and its generate at the time of sale order confirming.

Pinakin Nayi (pna)
on 8/21/13, 7:49 AM

Yes, that worked in sale.py, thanks a lot. But it does not work in product_images.py in product_images_olbs module. So I have to find where to place my little piece of code into that file.

on 8/21/13, 8:41 AM


--Borni DHIFI--
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 


Skype : dhifi.borni

On 8/21/13, 6:21 AM

Hi, you can use a TemporaryFile.

from tempfile import TemporaryFile
f = TemporaryFile('w+')
f.write("this is a test")
f.seek(0) # this will send you to the beginning of the file
print f.read()

Thank you for your answer, but unfortunately it does not work.

on 8/21/13, 6:57 AM

this code is tested and works well !

on 8/21/13, 7:04 AM

Is it tested in Openerp? Do you import only TemporaryFile? The two codes are correct, but the files are not created, I think that's a problem of file permissions or packages to import...

on 8/21/13, 7:16 AM

Thank you, but I have to work with normal files, not with temporary ones, As I said this code works in a separate script but not in Openerp. Did you write a wizard to run this code?

on 8/21/13, 7:50 AM

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

0 follower(s)


Asked: 8/21/13, 6:08 AM
Seen: 1801 times
Last updated: 3/16/15, 8:10 AM