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.
Rather specific question: Is there any way to find out where the Odoo is installed on Ubuntu (for example /odoo/odoo-server) and then get the addon path? I want to get the full path to my module in order to create a new file in this module.
I couldn't find any model / field that stores this..
The second thing that I am wondering is if there is any 'guideline' about creating new files inside an Odoo module? I want to create a script inside my module which will be generated and executed after some action in Odoo. Where is the best way to create a new file inside the custom module without the Odoo complaining?
Any ideas / tips?
Turns out there is a very basic statement for this. You can get the location of the Python file that is being executed so from there on you know the whole path. The code:
If your Odoo is under /odoo/odoo-server and your addon is named auto_installer it will build the path /odoo/odoo-server/addons/auto_installer and from there on it is as simple as navigating to the folder and adding files.
if you've full control over the odoo installation and you can make sure that module folder is writable, or using this as private solution, then creating files in the module directory is ok. But, if you're going to ship module, then it's NOT guaranteed that the module directory will be writable for odoo server instance. most probably, often it will not. for example for security reasons or when installed from .deb package... whereas, there is a "Data Directory", which is guaranteed to be writable to odoo server instance. Inside your module code, you can gather path of data directory as follows:
from openerp.tools import config
path_to_data_directory = config['data_dir']
Under Data Directory, there is a folder named "filestore" which is used to store files uploaded/stored with "ir.attachment" model (BTW, it's also option to use ir.attachment model in order to store new files, if applicable it's recommended to use it, there is nice implementation of filestore, avoiding duplicated files, etc, etc...). Conventionally we can add another folder, say "custom_filestore". also it may be meaningful to use database names under it, as it's under filestore directory, and module name as well(?)... then, path to a directory where we can save files, may be acquired like:
@api.model def get_custom_data_dir(self): return os.path.join(config['data_dir'], "custom_filestore", "module_name", self.env.cr.dbname)
this way, you'll have separated folders in case of multiple databases. also, target directory will be always writable (worth to note, that directory itself may not exist for the moment, but the location will be always writable to the odoo server instance, whereas it's not guaranteed for module directory itself).
take look at how is filestore path calculated in original filestore implementation, you can see here
I'm Windows, but I decided to try.
I searched the source and tried the following code and got the home path of the odoo
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): import os dirpath = os.environ.get('HOME') or os.getcwd()
I just put it under the fields_view_get to run it immediately. Pls try this under the Ubuntu and I think it will help.
for the 2nd question, you now have the home path of your installation, you can now create any code and call it from say the create method and see.
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: 8/17/15, 10:01 AM|
|Seen: 2283 times|
|Last updated: 8/20/15, 9:22 AM|