Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Odoo Development Cookbook

You're reading from   Odoo Development Cookbook Build effective applications by applying Odoo development best practices

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher Packt
ISBN-13 9781785883644
Length 400 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Holger Brunn Holger Brunn
Author Profile Icon Holger Brunn
Holger Brunn
Alexandre Fayolle Alexandre Fayolle
Author Profile Icon Alexandre Fayolle
Alexandre Fayolle
Daniel Reis Daniel Reis
Author Profile Icon Daniel Reis
Daniel Reis
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Installing the Odoo Development Environment FREE CHAPTER 2. Managing Odoo Server Instances 3. Creating Odoo Modules 4. Application Models 5. Basic Server Side Development 6. Advanced Server Side Development Techniques 7. Debugging and Automated Testing 8. Backend Views 9. Module Data 10. Access Security 11. Internationalization 12. Automation and Workflows 13. Web Server Development 14. CMS Website Development 15. Web Client Development 16. Server Deployment Index

Storing the instance configuration in a file

The odoo.py script has dozens of options, and it is tedious to remember them all and to remember to set them properly when starting the server. Fortunately, it is possible to store them all in a configuration file and to only specify by hand the ones you want to alter, for example, for development.

How to do it...

To generate a configuration file for your Odoo instance, run the following command:

$ odoo.py --save --config myodoo.cfg --stop-after-init

You can add additional options, and their values will be saved in the generated file. All the unset options will be saved with their default value set. To get a list of possible options, use:

$ odoo.py --help | less

This will provide you with some help about what the various options perform. To convert from the command line form to the configuration form, use the long option name, remove the leading dashes, and convert the dashes in the middle to underscores: --without-demo becomes without_demo. This works for most options, but there are a few exceptions listed in the next section.

Edit the file myodoo.cfg (use the table in the following section for some parameters you may want to change). Then to start the server with the saved options, run the following command:

$ odoo.py -c myodoo.cfg

Note

The --config option is commonly abbreviated as -c

How it works...

At start up, Odoo loads its configuration in three passes. First a set of default values for all options is initialized from the source code. Then the configuration is parsed, and any value defined in the file overrides the defaults. Finally, the command-line options are analyzed and their values override the configuration obtained from the previous pass.

As mentioned earlier, the names of the configuration variables can be found from the names of the command-line options by removing the leading dashes and converting the middle dashes to underscores. There are a few exceptions, notably:

Command line

Configuration file

--db-filter

dbfilter

--no-xmlrpc

xmlrpc = True / False

--database

db_name

--debug

debug_mode = True / False

--i18n-import / --i18n-export

Unavailable

Here is a list of options commonly set through the configuration file:

Option

Format

Usage

without_demo

 

Prevents module demo data from being loaded.

addons_path

Comma separated list of paths

A list of directory names in which the server will look for addons (see Chapter 2, Managing Odoo Server instances).

admin_passwd

Text

The master password (see previous recipe).

data_dir

Path to a directory

A directory in which the server will store session information, addons downloaded from the Internet, and documents if you enable the file store.

db_host

Host name

The name of the server running the PostgreSQL server. Use False to use local Unix Domain sockets, and localhost to use TCP sockets locally.

db_user

Database user login

 

db_password

Database user password

This is generally empty if db_host is False and db_user has the same name as the user running the server. Read the man page of pg_hba.conf for more information on this.

database

Database name

Used to set the database name on which some commands operate by default). This does not limit the databases on which the server will act. See the following dbfilter option for this.

dbfilter

A regular expression

The expression should match the name of the databases considered by the server. If you run the website, it should match a single database, so it will look like ^databasename$. More information on this is in Chapter 16, Server Deployment.

xmlrpc_interface

IP address of a network interface

Defaults to 0.0.0.0, meaning the server listens on all interfaces

xmlrpc_portlongpolling_port

Port number

The ports on which the Odoo server will listen. You will need to specify both to run multiple Odoo servers on the same host. longpolling_port is only used if workers is not 0.

logfile

Path to a file

The file in which Odoo will write its logs.

log_level

Log verbosity level

Specify the level of logging. Accepted values (in increasing verbosity order): critical, error, warn, info, debug, debug_rpc, debug_rpc_answer, debug_sql.

workers

Integer

The number of worker processes. See Chapter 16, Server Deployment, for more information.

no_database_list

True / False

Set to True to disable listing of databases. See Chapter 16, Server Deployment, for more information.

There is more...

The parsing of the configuration file by Odoo is done using the Python ConfigParser module. This module supports defining values for variables from the values of other variables using the %(section.variable)s notation. You can omit section if the value comes from the same section or if it is defined in the special [DEFAULT] section.

For instance, if you want to define the database login to be the same as the database name, you can write the following in your Odoo configuration file:

[options]
db_name = projectname
db_user = %(options.db_name)s

A very common use is to define a common prefix for the paths of the addons:

[DEFAULT]
project = /home/odoo/projects/project1
env = dev
prefix = %(project)s/%(env)s

[options]
addons-path = %(prefix)s/odoo/addons,%(prefix)s/OCA/server-tools
data_dir = %(prefix)s/data_dir
You have been reading a chapter from
Odoo Development Cookbook
Published in: Apr 2016
Publisher: Packt
ISBN-13: 9781785883644
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image