Book Image

Odoo 10 Development Essentials

By : Daniel Reis
Book Image

Odoo 10 Development Essentials

By: Daniel Reis

Overview of this book

Odoo is one of the fastest growing open source, business application development software products available. With announcement of Odoo 10, there are many new features added to Odoo and the face of business applications developed with Odoo has changed. This book will not only teach you how to build and customize business applications with Odoo, but it also covers all the new features that Odoo has to offer. This book is the latest resource on developing and customizing Odoo 10 applications. It comes packed with much more and refined content than its predecessor. It will start with building business applications from scratch and will cover topics such as module extensions, inheritance, working with data, user interfaces, and so on. The book also covers the latest features of Odoo 10, in addition to front end development, testing and debugging techniques. The book will also talk about Odoo Community and Odoo Enterprise.
Table of Contents (20 chapters)
Odoo 10 Development Essentials
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Preface

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:

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.