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 Essentials

You're reading from   Odoo Development Essentials Fast track your development skills to build powerful Odoo business applications

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781784392796
Length 214 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Odoo Development FREE CHAPTER 2. Building Your First Odoo Application 3. Inheritance – Extending Existing Applications 4. Data Serialization and Module Data 5. Models – Structuring the Application Data 6. Views – Designing the User Interface 7. ORM Application Logic – Supporting Business Processes 8. QWeb – Creating Kanban Views and Reports 9. External API – Integration with Other Systems 10. Deployment Checklist – Going Live Index

Initializing a new Odoo database

To be able to create a new database, your user must be a PostgreSQL superuser. The ./odoo.py setup_pg does that for you; otherwise use the following command to create a PostgreSQL superuser for the current Unix user with:

$ sudo createuser --superuser $(whoami)

To create a new database we use the command createdb. Let's create a v8dev database:

$ createdb v8dev

To initialize this database with the Odoo data schema we should run Odoo on the empty database by using the -d option:

$ ~/odoo-dev/odoo/odoo.py -d v8dev

This will take a couple of minutes to initialize a v8dev database, and will end with an INFO log message Modules loaded. Then the server will be ready to listen to client requests.

By default, this method will initialize the database with demonstration data, which often is useful on development databases. To initialize a database without demonstration data, add to the command the option: --without-demo-data=all.

Open http://<server-name>:8069 in your browser to be presented with the login screen. If you don't know your server name, type the hostname command at the terminal to find it, or the ifconfig command to find the IP address.

If you are hosting Odoo in a virtual machine you might need to do some network configuration to be able to use it as a server. The simplest solution is to change the VM network type from NAT to Bridged. With this, instead of sharing the host IP address, the guest VM will have its own IP address. It's also possible to use NAT, but that requires you to configure port forwarding, so your system knows that some ports, such as 8069, should be handled by the VM. In case you're having trouble, hopefully these details can help you find help in the documentation for your chosen virtualization software.

The default administrator account is admin with password admin. Upon login you are presented with the Settings menu, displaying the installed modules. Remove the Installed filter and you will be able to see and install any of the official modules.

Whenever you want to stop the Odoo server instance and return to the command line, press Ctrl + C. At the bash prompt, pressing the Up arrow key will bring you the previous shell command, so it's a quick way to start Odoo again with the same options. You will see the Ctrl + C followed by Up arrow and Enter is a frequently used combination to restart the Odoo server during development.

Managing your databases

We've seen how to create and initialize new Odoo databases from the command line. There are more commands worth knowing for managing databases.

You already know how to use the createdb command to create empty databases, but it can also create a new database by copying an existing one, by using a --template option.

Make sure your Odoo instance is stopped and you have no other connection open on the v8dev database created above, and run:

$ createdb --template=v8dev v8test

In fact, every time we create a database, a template is used. If none is specified, a predefined one called template1 is used.

To list the existing databases in your system use the PostgreSQL utility psql utility with the -l option:

$ psql -l

Running it we should see listed the two databases we created so far: v8dev and v8test. The list will also display the encoding used in each database. The default is UTF8, which is the encoding needed for Odoo databases.

To remove a database you no longer need (or want to recreate), use the dropdb command:

$ dropdb v8test

Now you know the basics to work with several databases. To learn more on PostgresSQL, the official documentation can be found at http://www.postgresql.org/docs/

Note

WARNING: The drop database will irrevocably destroy your data. Be careful when using it and always keep backups of your important databases before using it.

You have been reading a chapter from
Odoo Development Essentials
Published in: Apr 2015
Publisher: Packt
ISBN-13: 9781784392796
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