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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Odoo 12 Development Cookbook

You're reading from   Odoo 12 Development Cookbook 190+ unique recipes to build effective enterprise and business applications

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781789618921
Length 774 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Parth Gajjar Parth Gajjar
Author Profile Icon Parth Gajjar
Parth Gajjar
Daniel Reis Daniel Reis
Author Profile Icon Daniel Reis
Daniel Reis
Holger Brunn Holger Brunn
Author Profile Icon Holger Brunn
Holger Brunn
Alexandre Fayolle Alexandre Fayolle
Author Profile Icon Alexandre Fayolle
Alexandre Fayolle
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Installing the Odoo Development Environment FREE CHAPTER 2. Managing Odoo Server Instances 3. Server Deployment 4. Creating Odoo Add-On Modules 5. Application Models 6. Basic Server-Side Development 7. Module Data 8. Debugging 9. Advanced Server-Side Development Techniques 10. Backend Views 11. Access Security 12. Internationalization 13. Automation, Workflows, and Printouts 14. Web Server Development 15. CMS Website Development 16. Web Client Development 17. In-App Purchasing with Odoo 18. Automated Test Cases 19. Managing, Deploying, and Testing with Odoo.sh 20. Remote Procedure Calls in Odoo 21. Performance Optimization 22. Point of Sale 23. Manage Emails in Odoo 24. IoT Box 25. Other Book You May Enjoy

Updating Odoo from source

In the first recipe, we saw how to install Odoo from source 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 that's currently running with the Odoo source you are about to update, and then make a backup of all of the databases you care about in case something goes wrong. This is obviously something you need to do for production databases. Refer to the Managing Odoo server databases recipe of this chapter for further instructions.

Next, make a note of the current version of the source you are running. The best way to do this is by creating a lightweight tag using the following command:

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

How to do it...

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

$ git pull –-ff-only origin 12.0

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

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

$ ./odoo-bin -c myodoo.cfg --stop-after-init -u base
-u is the shortcut notation for the --update option of odoo-bin.

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

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

  1. Read the error message carefully and save it to a file, as it will be useful for making a bug report later.
  2. If you cannot figure out what the problem is, restore the service and 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 12.0-before-update-$(date --iso)
  1. Drop the broken databases and restore them from the backups you made (refer to the Managing Odoo server databases recipe of this chapter for instructions).
  2. Restart your instances and tell your users that the upgrade has been postponed.
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 ensuring that it runs flawlessly. However, you sometimes still get surprises, so even if you are really sure, make a backup.

How it works...

Updating the source code is done by ensuring that 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 that aren't 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. If not, use git reset --hard origin/12.0 to force the update, hence discarding your local modifications.

The update command uses the following options:

  • -c: Specifies the configuration file
  • --stop-after-init: Stops 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 add-ons or third-party add-ons.
  • It updates the database records that are stored in data files of the module, most notably, the views. It then recursively updates the installed modules that 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 of the installed modules in your instance. To update all installed modules, the all alias can be used instead of base.

You have been reading a chapter from
Odoo 12 Development Cookbook - Third Edition
Published in: Apr 2019
Publisher: Packt
ISBN-13: 9781789618921
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