Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I placed a text file in the same directory as models.py and wrote a file opening and reading code in models.py to open and read the file content. I have set all permissions of the file properly as well. But the file is not read. I'm not sure whether it's a location error. The code works well independently (that means if the python code is run alone, not within odoo). Please help me in this...
The solution you found works in your computer, but it'll break if you try to use the module anywhere else. A better solution is to get the path of your module, then append the .txt file name:
directory_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
return os.path.join(directory_path, 'filename.txt')
By the way, unless you have a good reason not to do so, I advise you to use "with open(...) as logFile:" instead of "logFile = open(...)", since it makes sure it'll always close the file, even if there's an exception. Otherwise, you might leak file handles.
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
|Asked: 11/8/15, 11:17 PM|
|Seen: 3480 times|
|Last updated: 11/10/15, 11:47 PM|