Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 10 Development Essentials

You're reading from   Odoo 10 Development Essentials Explore the functionalities of Odoo to build powerful business applications.

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781785884887
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Reis Daniel Reis
Author Profile Icon Daniel Reis
Daniel Reis
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Getting Started with Odoo Development FREE CHAPTER 2. Building Your First Odoo Application 3. Inheritance – Extending Existing Applications 4. Module Data 5. Models – Structuring the Application Data 6. Views - Designing the User Interface 7. ORM Application Logic – Supporting Business Processes 8. Writing Tests and Debugging Your Code 9. QWeb and Kanban Views 10. Creating QWeb Reports 11. Creating Website Frontend Features 12. External API – Integrating with Other Systems 13. Deployment Checklist – Going Live

Initializing a new Odoo database

To be able to create a new database, your user must be a PostgreSQL superuser. The following command creates a PostgreSQL superuser for the current Unix user:

$ sudo createuser --superuser $(whoami)

To create a new database, use the createdb command. Let's create a demo database:

$ createdb demo

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

$ ~/odoo-dev/odoo/odoo-bin -d demo

This will take a couple of minutes to initialize a demo database, and it will end with an INFO log message, Modules loaded.

Note

Note that it might not be the last log message, and it can be in the last three or four lines. With this, the server will be ready to listen to client requests.

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

Now open http://<server-name>:8069 with your browser to be presented with the login screen. If you don't know your server name, type the hostname command in the terminal in order 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 set some network configurations to be able to access it from your host system. The simplest solution is to change the virtual machine network type from NAT to Bridged. With this, instead of sharing the host IP address, the guest virtual machine 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 virtual machine. In case you're having trouble, hopefully these details will help you find relevant information in the documentation for your chosen virtualization software.

The default administrator account is admin with its password admin. Upon login, you are presented with the Apps menu, displaying the available applications:

Initializing a new Odoo database

Whenever you want to stop the Odoo server instance and return to the command line, press Ctrl + in 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. The Ctrl + C keys followed by the up arrow key 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.

We 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, using the --template option.

Make sure your Odoo instance is stopped and you have no other connection open on the demo database we just created, then run this:

$ createdb --template=demo demo-test

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 psql utility with the -l option:

$ psql -l

Running it will list the two databases we have created so far: demo and demo-test. The list will also display the encoding used in each database. The default is UTF-8, which is the encoding needed for Odoo databases.

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

$ dropdb demo-test

Now you know the basics to work with databases. To learn more about PostgreSQL, refer to the official documentation at http://www.postgresql.org/docs/ .

Note

WARNING:

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

You have been reading a chapter from
Odoo 10 Development Essentials
Published in: Nov 2016
Publisher: Packt
ISBN-13: 9781785884887
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 €18.99/month. Cancel anytime