Book Image

Odoo Development Cookbook

By : Holger Brunn, Alexandre Fayolle, Daniel Reis
Book Image

Odoo Development Cookbook

By: Holger Brunn, Alexandre Fayolle, Daniel Reis

Overview of this book

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source is also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. The book starts by covering Odoo installation and administration, and provides a gentle introduction to application development. It then dives deep into several of the areas that an experienced developer will need to use. You’ll learn implement business logic, adapt the UI, and extend existing features.
Table of Contents (23 chapters)
Odoo Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Updating Odoo from source


We saw in the first recipe how to install Odoo from source by using the git repository. The main benefit of this setting is being able to update the source code of Odoo using git to get the latest bug fixes.

Getting ready

Stop any instance currently running with the Odoo source you are about to update.

Make a backup of all the databases you care about in case something goes bad. This is obviously something you need to do for production databases. See the Managing Odoo server databases recipe for instructions.

Then make a note of the current version of the source you are running. The best way is to create a lightweight tag using the following command:

$ cd ~/odoo-dev/odoo
$ git checkout 9.0
$ git tag 9.0-before-update-$(date --iso)

How to do it...

To update the source code of Odoo, use the following command:

$ git pull –-ff-only

This will fetch the latest version of the source code committed to the current branch.

To update an instance running on this code, run the following command:

$ odoo.py -c myodoo.cfg --stop-after-init -u base

Note

-u is the shortcut notation for the --update option of odoo.py.

If you don't have a database set in the configuration file, you will have to add the -d database_name option. That command is to be repeated for all the instances running with this version of the source code.

If the update fails, don't panic, you have backups.

  1. Read the error message carefully. Save it to a file, as it will be useful to make a bug report later.

  2. If you cannot figure out what the problem is, restore the service; restore the Odoo source code to the previous version, which is known to work using the tag you set before updating the source version:

    $ git reset --hard 9.0-before-update-$(date --iso)
    
  3. Drop the broken databases and restore them from the backups you made (see the Managing Odoo server databases recipe for instructions).

  4. Restart your instances and tell your users that the upgrade has been postponed.

Note

Note that in real life, this should never happen on a production database, because you would have tested the upgrade beforehand on a copy of the database, fixed the issues, and only done the upgrade on the production server after making sure that it runs flawlessly. But sometimes, you still get surprises, so even if you are really sure, make a backup.

How it works...

Updating the source code is done by making sure we are on the correct branch using git checkout, and then fetching the new revisions using git pull. The --ff-only option will cause a failure if you have local commits not present in the remote repository. If this happens and you want to keep your changes, you can use git pull (without --ff-only) to merge the remote changes with yours; otherwise, use git reset --hard origin/9.0 to force the update, discarding your local modifications.

The update command uses the following options:

  • -c: specify the configuration file

  • --stop-after-init: stop the instance when the update is over

  • -u base or --update base: requests the update of the base module

When updating a module, Odoo does the following:

  • It updates the database structure for the models defined in the module for which the structure changes. For updates on the stable branch of Odoo, there should be no such changes, but this can happen for your own addons or third party addons.

  • It updates the database records stored in data files of the module, most notably the views. It then recursively updates the installed modules which have declared a dependency on the module.

Since the base module is an implicit dependency of all Odoo modules, updating it will trigger an update of all the installed modules in your instance. To update all installed modules, the alias all can be used instead of base.