29,99 €
Odoo is a powerful framework known for rapid application development. Its latest release, Odoo 12, introduces tons of new features. With this book, you’ll learn how to develop powerful Odoo applications from scratch, using all the latest features.
This Odoo cookbook starts by covering Odoo installation and deployment on the server. Next, you’ll explore the Odoo framework with real-world examples. You’ll create a new Odoo module from the ground up and progress to advanced framework concepts. You’ll also learn how to modify existing applications, including Point of Sale (POS). This book is not just limited to backend development; the advanced JavaScript recipes for creating new views and widgets will help you build beautiful UI elements. As you move forward, you’ll gain insights into website development and become a quality Odoo developer by studying performance optimization, debugging, and automated tests. Finally, you’ll learn the latest concepts like multi-website, In-App Purchasing (IAP), Odoo.sh, and IoT Box.
By the end of the book, you’ll have all the knowledge you need to build powerful Odoo applications. The development best practices used in this book will undoubtedly come handy when you are working with the Odoo framework.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 842
Veröffentlichungsjahr: 2019
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Aaron LazarAcquisition Editor:Alok DhuriContent Development Editor:Digvijay BagulTechnical Editor:Ashi SinghCopy Editor:Safis EditingLanguage Support Editors: Mary McGowan, Storm MannProject Coordinator:Prajakta NaikProofreader: Safis EditingIndexer:Manju ArasanGraphics:Tom ScariaProduction Coordinator:Deepika Naik
First published: April 2016 Second edition: January 2018 Third edition: April 2019
Production reference: 1270419
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78961-892-1
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Parth Gajjar is Application Engineer at Odoo and has been working on Odoo for the past 6 years. For the past year and a half, Parth has been working as a code reviewer at Odoo India. During this time, he has worked in several departments of Odoo, including offshore, migration, and research and development. During his time in research and development, he has developed several key features in Odoo, including the marketing automation module Odoo mobile app (The hybrid JavaScript Part), mobile push notification, Less/CSS editor, Domain Selector widget, and the Qweb report engine prototype. He often gives technical training to Odoo partners. Also, he handes technical interviews at Odoo India.
Alexandre Fayolle started working with Linux and free software in the mid 1990s and quickly became interested in the Python programming language. In 2012, he joined Camptocamp to share his expertise on Python, PostgreSQL, and Linux with the team implementing Odoo. He currently manages projects for Camptocamp and is strongly involved in the Odoo Community Association. In his spare time, he likes to play jazz on the vibraphone.
Holger Brunn has been a fervent open source advocate since he came into contact with the open source market sometime in the nineties. He has programmed for ERP and similar systems in different positions since 2001. For the last 10 years, he has dedicated his time to TinyERP, which became OpenERP and evolved into Odoo. Currently, he works at Therp BV in the Netherlands as a developer and is an active member of the Odoo Community Association (OCA).
Daniel Reis has had a long career in the IT industry, mostly as a consultant implementing business applications in variety of sectors, and today works for Securitas, a multinational security services provider. He has been working with Odoo (formerly OpenERP) since 2010, is an active contributor to the Odoo Community Association projects, is currently a member of the board of the Odoo Community Association, and collaborates with ThinkOpen Solutions, a leading Portuguese Odoo integrator.
Dharmang Soni has master's degree in Information Technology. He loves to do code and has worked with multiple technologies and frameworks, such as ASP.NET, Android (Java), PHP, iOS (Swift), and Odoo. He has more than 6 years' of experience in development of Odoo applications, websites, and mobile applications. He joined the Indian branch of Odoo S.A. (TinyERP Pvt. Ltd.) in 2012, starting his career at Odoo by developing the Odoo mobile framework for the Android. Later, he developed mobile applications for Android and iOS, currently used worldwide. Currently, he is working as an R&D developer at Odoo and works on IoT and the optimization of the screens for mobile.
Kishan Gajjar has a degree in computer engineering. He loves programming and designing. He has expertise in various technologies, including Python, JavaScript, and CSS. He is an employee at the Indian branch of Odoo. He joined Odoo 2 years ago and currently works in the R&D department. At Odoo, he mostly works on website builders, themes, and the backend JavaScript framework.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Odoo 12 Development Cookbook Third Edition
About Packt
Why subscribe?
Packt.com
Contributors
About the author
Previous edition authors
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Code in Action
Conventions used
Sections
Getting ready
How to do it...
How it works...
There's more...
See also
Get in touch
Reviews
Installing the Odoo Development Environment
Introduction
Odoo ecosystem
Odoo editions
Git repositories
Runbot
Odoo app store
Odoo community association
Official Odoo help forum
Easy installation of Odoo from a source
Getting ready
How to do it...
How it works...
Virtual environments
PostgreSQL configuration
Git configuration
Downloading the Odoo source code
Starting the instance
Managing Odoo environments using the start command
Getting ready
How to do it...
How it works...
There's more...
Managing Odoo server databases
Getting ready
How to do it...
Accessing the database management interface
Setting or changing the master password
Creating a new database
Duplicating a database
Removing a database
Backing up a database
Restoring a database backup
How it works...
There's more...
Storing the instance configuration in a file
How to do it...
How it works...
Activating the Odoo developer tools
How to do it...
How it works...
Updating Odoo from source
Getting ready
How to do it...
How it works...
Managing Odoo Server Instances
Introduction
Configuring the add-ons path
Getting ready
How to do it...
How it works...
There's more...
Updating the add-on modules list
Getting ready
How to do it...
How it works...
Standardizing your instance directory layout
How to do it...
How it works...
See also
There's more...
Installing and upgrading local add-on modules
Getting ready
How to do it...
From the web interface
From the command line
How it works...
Add-on installation
Add-on update
There's more...
Installing add-on modules from GitHub
Getting ready
How to do it...
How it works...
There's more...
Applying changes to add-ons
Getting ready
How to do it...
How it works...
See also
Applying and trying proposed pull requests
Getting ready
How to do it...
How it works...
There's more...
Server Deployment
Introduction
Installing Odoo for production use
Getting ready
How to do it...
How it works...
There's more...
Server dimensioning
PostgreSQL tuning
Source code version
Backups
Adapting the configuration file for production
Getting ready
How to do it...
How it works...
There's more...
Setting up Odoo as a system service
Getting ready
How to do it...
How it works...
Configuring a reverse proxy and SSL with nginx and Let's Encrypt
Getting ready
How to do it...
How it works...
There's more...
See also
Using Docker to run Odoo
Getting ready
How to do it...
How it works...
Running the Odoo image with a configuration file
Running the Odoo image with custom add-ons
Running multiple Odoo instances
There is more...
Running Odoo through docker-compose
Getting ready
How to do it...
How it works...
There's more...
Managing content delivery networks for websites
Getting ready
How to do it...
Configuring the CDN provider
Configuring CDN at Odoo
How it works...
There's more...
Creating Odoo Add-On Modules
Technical requirements
Introduction
What is an Odoo add-on module?
Creating and installing a new add-on module
Getting ready
How to do it...
How it works...
Completing the add-on module manifest
Getting ready
How to do it...
How it works...
There's more...
Organizing the add-on module file structure
Getting ready
How to do it...
How it works...
Adding models
Getting ready
How to do it...
How it works...
Adding menu items and views
Getting ready
How to do it...
Accessing Odoo as a superuser
How it works...
Adding access security
Getting ready
How to do it...
How it works...
See also
Using the scaffold command to create a module
Getting ready
How to do it...
How it works...
Application Models
Introduction
Technical requirements
Defining the model representation and order
Getting ready
How to do it...
How it works...
There's more...
Adding data fields to a model
Getting ready
How to do it...
How it works...
There's more...
Using a float field with configurable precision
Getting ready
How to do it...
How it works...
Adding a monetary field to a model
Getting ready
How to do it...
How it works...
Adding relational fields to a model
Getting ready
How to do it...
How it works...
There's more...
Adding a hierarchy to a model
Getting ready
How to do it...
How it works...
There's more...
Adding constraint validations to a model
Getting ready
How to do it...
How it works...
There's more...
Adding computed fields to a model
Getting ready
How to do it...
How it works...
Exposing related fields stored in other models
Getting ready
How to do it...
How it works...
There's more...
Adding dynamic relations using reference fields
Getting ready
How to do it...
How it works...
Adding features to a model using inheritance
Getting ready
How to do it...
How it works...
There's more...
Using abstract models for reusable model features
Getting ready
How to do it...
How it works...
There's more...
Using delegation inheritance to copy features to another model
Getting ready
How to do it...
How it works...
There's more...
Basic Server-Side Development
Introduction
Technical requirements
Defining model methods and using the API decorators
Getting ready
How to do it...
How it works...
There's more...
Reporting errors to the user
Getting ready
How to do it...
How it works...
There's more...
Obtaining an empty recordset for a different model
Getting ready
How to do it...
How it works...
See also
Creating new records
Getting ready
How to do it...
How it works...
There's more...
Updating values of recordset records
Getting ready
How to do it...
How it works...
There's more...
Searching for records
Getting ready
How to do it...
How it works...
There's more...
Combining recordsets
Getting ready
How to do it...
How it works...
Filtering recordsets
Getting ready
How to do it...
How it works...
There's more...
Traversing recordset relations
Getting ready
How to do it...
How it works...
There's more...
See also
Sorting recordsets
Getting ready
How to do it...
How it works...
There's more...
Extending the business logic defined in a model
Getting ready
How to do it...
How it works...
There's more...
Extending write() and create()
Getting ready
How to do it...
How it works...
There's more...
Customizing how records are searched
Getting ready
How to do it...
How it works...
There's more...
See also
Fetching data in groups with read_group()
Getting ready
How to do it...
How it works...
Module Data
Introduction
Technical requirements
Using external IDs and namespaces
How to do it...
How it works...
There's more...
See also
Loading data using XML files
How to do it...
How it works...
There's more...
Using the noupdate and forcecreate flags
How to do it...
How it works...
There's more...
See also
Loading data using CSV files
How to do it...
How it works...
There's more...
Add-on updates and data migration
How to do it...
How it works...
There's more...
See also
Deleting records from XML files
Getting ready
How to do it...
How it works...
Invoking functions from XML files
How to do it...
How it works...
There's more...
Debugging
Introduction
The auto-reload and --dev options
Getting ready
How to do it...
How it works...
Producing server logs to help debug methods
Getting ready
How to do it...
How it works...
There's more...
Using the Odoo shell to interactively call methods
Getting ready
How to do it...
How it works...
There's more...
Using the Python debugger to trace method execution
Getting ready
How to do it...
How it works...
There's more...
See also
Using the Odoo Community Association maintainer quality tools
Getting ready
How to do it...
How it works...
There's more...
Using Pylint to check your code
Using Flake8 to check your code
Understanding the debug mode options
How to do it...
How it works...
Advanced Server-Side Development Techniques
Introduction
Technical requirements
Changing the user that performs an action
Getting ready
How to do it...
How it works...
There's more...
See also
Calling a method with a modified context
Getting ready
How to do it...
How it works...
There's more...
See also
Executing raw SQL queries
Getting ready
How to do it...
How it works...
There's more...
See also
Writing a wizard to guide the user
Getting ready
How to do it...
How it works...
There's more...
Using the context to compute default values
Wizards and code reuse
Redirecting the user
Defining onchange methods
Getting ready
How to do it...
How it works...
There's more...
Calling onchange methods on the server side
Getting ready
How to do it...
How it works...
There's more...
See also
Defining a model based on an SQL view
Getting ready
How to do it...
How it works...
There's more...
Adding custom settings options
Getting ready
How to do it...
How it works...
There's more...
Implementing init hooks
Getting ready
How to do it...
How it works...
Backend Views
Introduction
Technical requirements
Adding a menu item and window action
How to do it...
How it works...
There's more...
See also
Having an action open a specific view
How to do it...
How it works...
ir.actions.act_window.view
There's more...
Adding content and widgets to a form view
How to do it...
How it works...
Form
Header
Button
Group
Field
Notebook and page
General attributes
Other tags
There's more...
See also
Adding buttons to forms
How to do it...
How it works...
There's more...
Passing parameters to forms and actions – Context
Getting ready
How to do it...
How it works...
There's more...
See also
Defining filters on record lists – Domain
How to do it...
How it works...
There's more...
Operators
Pitfalls of searching using domains
See also
Defining list views
How to do it...
How it works...
There's more...
Defining search views
How to do it...
How it works...
There's more...
See also
Changing existing views – view inheritance
How to do it...
How it works...
There's more...
Order of evaluation in view inheritance
See also
Defining document-style forms
How to do it...
How it works...
Dynamic form elements using attrs
How to do it...
How it works...
There's more...
Defining embedded views
How to do it...
How it works...
There's more...
Displaying attachments on the side of the form view
How to do it...
How it works...
There's more...
Defining kanban views
How to do it...
How it works...
There's more...
Showing kanban cards in columns according to their state
Getting ready
How to do it...
How it works...
There's more...
Defining calendar and gantt views
How to do it...
How it works...
There's more...
Gantt View
Defining graph and pivot views
Getting ready
How to do it...
How it works...
There's more...
Defining the cohort view
Getting ready
How to do it...
How it works...
Defining the dashboard view
Getting ready
How to do it...
How it works...
There's more....
Access Security
Technical requirements
Creating security groups and assigning them to users
Getting ready
How to do it...
How it works...
There's more...
Adding security access to models
Getting ready
How to do it...
How it works...
There's more...
Limiting access to fields in models
How to do it...
How it works...
There's more...
Limiting record access using record rules
How to do it...
How it works...
There's more...
Using security groups to activate features
Getting ready
How to do it...
How it works...
There's more...
Accessing recordsets as a superuser
How to do it...
How it works...
There's more...
Hiding view elements and menus based on groups
Getting ready
How to do it...
How it works...
Internationalization
Installing a language and configuring user preferences
Getting ready
How to do it...
How it works...
There's more...
Configuring language-related settings
Getting ready
How to do it...
How it works...
There's more...
Translating texts through the web client user interface
Getting ready
How to do it...
How it works...
There's more...
Exporting translation strings to a file
Getting ready
How to do it...
How it works...
There's more...
Using gettext tools to make translations easier
How to do it...
How it works...
There's more...
Importing translation files into Odoo
Getting ready
How to do it...
How it works...
Automation, Workflows, and Printouts
Introduction
Technical requirements
Managing dynamic record stages
Getting ready
How to do it...
How it works...
There's more...
Managing kanban stages
Getting started
How to do it...
How it works...
There's more...
Adding a quick create form in a kanban card
Getting started
How to do it...
How it works...
Creating interactive kanban cards
Getting started
How to do it...
How it works...
Adding a progress bar in kanban views
Getting started
How to do it...
How it works...
Creating server actions
Getting ready
How to do it...
How it works...
There's more...
Using Python code server actions
Getting ready
How to do it...
How it works...
There's more...
Using automated actions on time conditions
Getting ready
How to do it...
How it works...
There's more...
Using automated actions on event conditions
Getting ready
How to do it...
How it works...
There's more...
Creating QWeb-based PDF reports
Getting ready
How to do it...
How it works...
There's more...
Web Server Development
Introduction
Technical requirements
Making a path accessible from the network
Getting ready
How to do it...
How it works...
odoo.http.route
Return values
odoo.http.request
There's more...
See also
Restricting access to web accessible paths
Getting ready
How to do it...
How it works...
There's more...
Consuming parameters passed to your handlers
How to do it...
How it works...
There's more...
See also
Modifying an existing handler
Getting ready
How to do it...
How it works...
There's more...
See also
CMS Website Development
Introduction
Managing static assets
What are asset bundles and different assets in Odoo?
Custom assets
How to do it...
How it works...
There's more...
Extending CSS and JavaScript for the website
Getting ready
How to do it...
How it works...
Creating or modifying templates – QWeb
Getting ready
How to do it...
How it works...
Loops
Dynamic attributes
Fields
Conditionals
Setting variables
Subtemplates
Inline editing
There's more...
See also
Managing dynamic routes
Getting ready
How to do it...
How it works...
There's more...
Offering snippets to the user
Getting ready
How to do it...
How it works...
There's more...
Getting input from users
Getting ready
How to do it...
How it works...
There's more...
Managing Search Engine Optimization (SEO) options
Getting ready
How to do it...
How it works...
There's more...
Managing sitemaps for the website
Getting ready...
How to do it...
How it works...
Getting a visitor's country information
Getting ready...
How to do it...
How it works...
Tracking a marketing campaign
Getting ready
How to do it...
How it works...
Managing multiple websites
Getting ready
How to do it...
How it works...
Web Client Development
Introduction
Technical requirements
Creating custom widgets
Getting ready
How to do it...
How it works...
There's more...
Using client-side QWeb templates
Getting ready
How to do it...
How it works...
There's more...
See also
Making RPC calls to the server
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a new view
Getting ready
How to do it...
How it works...
There's more...
Debugging your client-side code
Getting ready
How to do it...
How it works...
There's more...
Improving onboarding with tour
Getting ready
How to do it...
How it works...
Mobile app JavaScript
Getting ready
How to do it...
How to works...
There's more...
In-App Purchasing with Odoo
Introduction
Technical requirements
In-app purchase concepts
How it works...
The IAP service flow
There's more...
Registering an IAP service in Odoo
Getting ready
How to do it...
How it works...
Creating an IAP service module
Getting ready
How to do it...
How it works...
Authorizing and charging IAP credits
Getting ready
How to do it...
How it works...
There's more...
See also
Creating an IAP client module
Getting ready
How to do it...
How it works...
There's more...
Displaying offers when an account lacks credits
Getting ready
How to do it...
How it works...
There's more...
Automated Test Cases
Introduction
Technical requirements
Python test cases
Getting ready
How to do it...
How it works...
There's more...
Running tagged Python test cases
Getting ready
How to do it...
How it works...
There's more...
Setting up Headless Chrome for client-side test cases
How to do it...
How it works...
Client-side QUnit test cases
Getting ready
How to do it...
How it works...
There's more...
Adding tour test cases
Getting ready
How to do it...
How it works...
Running client-side test cases from the UI
How to do it...
Running QUnit test cases
Running tours from the UI
How it works...
Debugging client-side test cases
Getting ready
How to do it...
How it works...
Generating videos/screenshots for failed test cases
How to do it...
How it works...
Managing, Deploying, and Testing with Odoo.sh
Introduction
Technical requirements
Exploring some basic concepts of Odoo.sh
What is Odoo.sh?
Why was Odoo.sh introduced?
When should you use Odoo.sh?
What are the features of Odoo.sh?
Creating an Odoo.sh account
Getting ready
How to do it...
How it works...
There's more...
Adding and installing custom modules
Getting ready
How to do it...
How it works...
There's more...
Managing branches
Getting ready
How to do it...
Creating the production branch
Creating a development branch
Creating a staging branch
Merging new features in the production branch
How it works...
Accessing debugging options
How to do it...
Branch history
Mail catcher
Web shell
Code editor
Logs
There's more...
Getting a backup of your instance
How to do it...
How it works...
Checking the status of your builds
How to do it...
How it works...
There's more...
All Odoo.sh options
Getting ready
How to do it...
Project name
Collaborators
Public access
Module installation
Submodules
Database workers
Staging branches
There's more...
Database size
Odoo source code revisions
Remote Procedure Calls in Odoo
Technical requirements
Logging in/connecting Odoo with XML-RPC
Getting ready
How to do it...
How it works...
There's more...
Searching/reading records through XML-RPC
Getting ready
How to do it...
How it works...
There's more...
Creating/updating/deleting records through XML-RPC
Getting ready
How to do it...
How it works...
There's more...
Calling methods through XML-RPC
Getting ready
How to do it...
How it works...
There's more...
Logging in/connecting Odoo with JSON-RPC
Getting ready
How to do it...
How it works...
There's more...
Fetching/searching records through JSON-RPC
Getting ready
How to do it...
How it works...
There's more...
Create/update/delete records through JSON-RPC
Getting ready
How to do it...
How it works...
There's more...
Calling methods through JSON-RPC
Getting ready
How to do it...
How it works...
The OCA odoorpc library
Getting ready
How to do it...
How it works...
There's more...
See also
Performance Optimization
The prefetching pattern for the recordsets
How to do it...
How it works...
There's more...
The in-memory cache – ormcache
How to do it...
ormcache
ormcache_context
ormcache_multi
How it works...
There's more...
Generating image thumbnails
How to do it...
How it works...
There's more...
Accessing grouped data
How to do it...
How it works...
There's more...
Creating or writing multiple records
How to do it...
How it works...
There's more...
Accessing records through database queries
How to do it...
How it works...
There's more...
Profiling Python code
How to do it...
How it works...
There's more...
Point of Sale
Introduction
Technical requirements
Adding custom JavaScript/SCSS files
Getting ready
How to do it...
How it works...
There's more...
Adding an action button on the keyboard
Getting ready
How to do it...
How it works...
There's more...
Making RPC calls
Getting ready
How to do it...
How it works...
Modifying the POS screen UI
Getting ready
How to do it...
How it works...
Modifying existing business logic
Getting ready
How to do it...
How it works...
Modifying customer receipts
Getting ready
How to do it...
How it works...
There's more...
Manage Emails in Odoo
Technical requirements
Configuring incoming and outgoing mail servers
Getting ready
How to do it...
Configuring the incoming mail server
Configuring the outgoing mail server
How it works...
There's more...
Managing chatter on documents
Getting ready
How to do it...
How it works...
There is more...
Managing activities on documents
Getting ready
How to do it...
How it works...
There's more...
Sending mail using the Jinja template
Getting ready
How to do it...
How it works...
There's more...
Sending mail using the QWeb template
Getting ready
How to do it...
How it works...
There's more...
Managing the mail alias
Getting ready
How to do it...
How it works...
There's more...
Logging user changes in chatter
Getting ready
How to do it...
How it works...
IoT Box
Technical requirements
Flashing the IoT Box image for Raspberry Pi
Getting ready
How to do it...
How it works...
There's more...
Connecting the IoT Box with the network
Getting ready
How to do it...
How it works...
Adding the IoT Box to Odoo
Getting ready
How to do it...
Connecting the IoT Box automatically
Connecting the IoT Box manually
How it works...
There's more...
Loading drivers and listing connected devices
Getting ready
How to do it...
How it works...
Taking input from devices
Getting ready
How to do it...
How it works...
There is more...
Accessing the IoT Box through SSH
Getting ready
How it works...
How to do it...
There's more...
Configuring a point of sale
Getting ready
How to do it...
How it works...
There's more...
Other Book You May Enjoy
Leave a review - let other readers know what you think
Odoo is a suite of integrated business applications. Odoo comes with over 25 different business applications covering CRM, manufacturing, e-commerce, accounting, and more. In short, it is an all-in-one solution covering all of your business needs.
Odoo is great software for developers too. Thanks to Odoo's strong framework, developers can build powerful applications from scratch. The Odoo framework has a built-in extension mechanism. Odoo's built-in applications are also built with the same framework, and its extensibility helps developers to create extension modules to modify existing applications.
The scope of the Odoo framework is huge, and it is very hard for newcomers to follow its learning curve. Odoo 12 Development Cookbook - Third Edition provides step-by-step recipes that help you learn every aspect of the Odoo framework, including all of the latest features of version 12. Its unique problem-and-solution approach helps you to solve your day-to-day Odoo development issues.
This book is suitable for both newcomers and experienced developers. If you have basic knowledge of the Python programming language, then this book will help you to easily gain expertise in the Odoo framework. If you are a developer who wants to develop a highly efficient business application with the Odoo framework, and wants practical examples with which to learn the Odoo framework, then this book is for you!
Chapter 1, Installing the Odoo Development Environment, starts with an introduction to the Odoo ecosystem. Here you will learn how to install and set up Odoo for the development environment. You will also learn how to activate developer tools.
Chapter 2, Managing Odoo Server Instances, is about installing and upgrading add-ons. It provides you with useful tips to organize custom add-ons downloaded from GitHub.
Chapter 3, Server Deployment, is about how to install and configure Odoo instances for production use. This chapter includes the NGINX reverse proxy, SSL configuration, the startup service, and basic Docker deployment. It also includes the configuration for the CDN of a website.
Chapter 4, Creating Odoo Add-On Modules, explains the structure of the Odoo add-on module and provides a step-by-step guide to create a simple Odoo module from scratch.
Chapter 5, Application Models, focuses on Odoo model structure, and explains all types of fields with their attributes. This chapter also includes different ways to inherit and extend existing models.
Chapter 6, Basic Server-Side Development, introduces the API of the Odoo framework, presenting the usage of CRUD methods and other commonly used methods. This chapter also explains how to write business logic in Odoo.
Chapter 7, Module Data, shows how to ship built-in data along with your add-on module. It also explains the basic steps to write migration functions.
Chapter 8, Debugging, provides different strategies for debugging Odoo code. This chapter includes the usage of developer options and Odoo shell.
Chapter 9, Advanced Server-Side Development Techniques, covers more advanced topics of the ORM framework. It is useful for developing wizards, SQL views, installation hooks, on-change methods, and more. This chapter also explains how to execute raw SQL queries in the database.
Chapter 10, Backend Views, teaches you how to create different UI views and how to invoke the business logic from the user interface. It covers the all of the usual views, such as the list, form, kanban, calendar, graph, search, and pivot, as well as newly introduced views, such as cohort and dashboard. This chapter also includes a recipe for modifying/inheriting existing views.
Chapter 11, Access Security, covers the security aspect of the Odoo framework. It shows how to control/restrict user access on the models by creating security groups, access control lists, and record level rules.
Chapter 12, Internationalization, shows how to translate the user interface for your add-on modules, and provides useful tricks for managing translation files.
Chapter 13, Automation, Workflows, and Printouts, illustrates the different tools and techniques available in Odoo to implement better business processes. It shows how to use server actions, automated actions, and time-based scheduled actions. This chapter also includes a recipe for creating PDF reports for your model.
Chapter 14, Web Server Development, covers the core of the Odoo web server. It shows how to create custom URL routes to serve data on a given URL, and also shows how to control access to these URLs.
Chapter 15, CMS Website Development, show how to manage a website with Odoo. It also shows how to create and modify beautiful web pages and QWeb templates. This chapter also includes how to create dynamic building blocks with options. It includes some dedicated recipes for managing SEO, user forms, UTM tracking, sitemaps, and fetching visitor location information. This chapter also highlights the latest concept of a multi-website in Odoo.
Chapter 16, Web Client Development, dives into the JavaScript part of the Odoo. It covers how to create a new field widget and make RPC calls to the server. This also includes how to create a brand new view from scratch. You will also learn how to create on-boarding tours.
Chapter 17, In-App Purchasing with Odoo, covers everything related to the latest concept of In-App Purchasing (IAP) in Odoo. In this chapter, you will learn how to create client and service modules for IAP. You will also learn how to create an IAP account and draw IAP credits from the end user.
Chapter 18, Automated Test Cases, covers how to write and execute automated test cases in Odoo, including server-side, client-side, and tour integration test cases. This chapter also has a recipe to set up chrome-headless to capture screenshots and videos to see failed client-side test cases.
Chapter 19, Managing, Deploying, and Testing with Odoo.sh, explains Odoo.sh, a PaaS platform for deploying Odoo instances that cover different aspects of the production, staging, and development branches. This also explains the different options of the platform.
Chapter 20, Remote Procedure Calls in Odoo, covers different ways to connect Odoo instances from external applications. This chapter teaches you how to connect and access the data from an Odoo instance through XML-RPC, JSON-RPC, and the odoorpc library.
Chapter 21, Performance Optimization, explains the different concepts and patterns used to gain performance improvements in Odoo. This chapter includes the concept of prefetching, ORM-cache, and profiling the code to detect performance issues.
Chapter 22, Point of Sale, covers customization in a point-of-sale application. This includes customization of the user interface, adding a new action button, modifying business flow, and extending customer recipes.
Chapter 23, Manage Emails in Odoo, explains how to manage email and chatter in Odoo. It starts with configuring mail servers and moves towards the mailing API of the Odoo framework. This chapter also covers the Jinja2 and QWeb mail templates, chatters on the form view , field logs, and activities.
Chapter 24, IoT Box, gives you the highlight of the latest hardware of IoT Box. This chapter covers how to configure, access, and debug IoT Box. It also includes a recipe to integrate IoT Box with your custom add-ons.
This book is meant for developers who have basic knowledge of the Python programming language, as the Odoo backend runs on Python. In Odoo, data files are created with XML, so basic knowledge of XML is required.
This book also covers the backend JavaScript framework, point-of-sale applications, and the website builder, which requires basic knowledge JavaScript, jQuery, and Bootstrap 4.
The community edition of Odoo is open source and freely available, but a few features, including IoT, cohort, and dashboard, are available only in the Enterprise edition, so to follow along with that recipe, you will need the Enterprise edition.
To follow Chapter 24, IoT Box, you will require the Raspberry Pi 3 Model B+, which is available at https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latestversion of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/Odoo-12-Development-Cookbook-Third-Edition. Note that, the code bundle has the separate folder for each recipe. We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781789618921_ColorImages.pdf.
Visit the following link to check out videos of the code being run: http://bit.ly/2IWHLtr
In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).
To give clear instructions on how to complete a recipe, use these sections as follows:
This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
In this chapter, we will cover the following recipes:
Odoo ecosystem
Easy installation of Odoo from source
Managing Odoo environments using the
start
command
Managing Odoo server databases
Storing the configuration instance in a file
Activating Odoo developer tools
Updating Odoo from source
There are lots of ways to set up an Odoo development environment. This chapter proposes one of them; you will certainly find a number of other tutorials on the web explaining other approaches. Keep in mind that this chapter is about a development environment that has different requirements from a production environment. This will be covered in Chapter 3, Server Deployment.
If you are new to Odoo development, you must know about certain aspects of the Odoo ecosystem. The next section will give you a brief introduction to those aspects, and then we will move on to the installation of Odoo for development.
Odoo provides the developer with out-of-the-box modularity. Its powerful framework helps the developer to build projects very quickly. There are various characters in the Odoo ecosystem that you should be familiar with before starting your journey of becoming a successful Odoo developer.
Odoo comes with two editions. The first is the Community Edition, which is open source, and the second is the Enterprise Edition, which has licensing fees. Unlike other software vendors, Odoo Enterprise Edition is just a bunch of advance applications that adds extra features/apps in the Community Edition. Basically, Enterprise Edition runs on top of the Community Edition. The Community Edition comes under the Lesser General Public License v3.0 (LGPLv3) license and comes with all of the basic Enterprise resource planning(ERP) applications, such as sale, Customer Relationship Management (CRM), invoicing, purchase, website builder, and so on. Alternatively, Enterprise Edition comes with the Odoo Enterprise Edition License, which is a proprietary license. Odoo Enterprise Edition comes with advanced features such as full accounting, studio, Voice over Internet Protocol (VoIP), mobile responsive design, e-sign, marketing automation, and delivery and banking integrations. Enterprise Edition also provides you with unlimitedbugfixes. The following diagram shows that Enterprise Edition depends on the Community Edition, which is why you need Community Edition to use Enterprise Edition:
You can see a full comparison of both editions here: https://www.odoo.com/page/editions.
Odoo has the largest number of community developers, which is why you will find a large number of third-party apps (modules) on the app store. Most of the free apps use an Affero General Public License version 3 (AGPLv3). You cannot use the proprietary license on your app if your application has dependencies on such apps. Apps with an Odoo proprietary license can be developed only on modules that have LGPL or other proprietary licenses.
The whole code base of Odoo is hosted on GitHub. You can post bugs/issues for stable versions here. You can also propose a new feature by submitting Pull Requests (PR). There are several repositories in Odoo; see the following table for more information:
Repositories
Purpose
https://github.com/odoo/odoo
This is the Community Edition of Odoo. It's available publicly.
https://github.com/odoo/enterprise
This is the Enterprise Edition of Odoo.
It's
a
vailable to official Odoo partners only
.
https://github.com/odoo-dev/odoo
This is an Ongoing development repository. It's available publicly.
Every year, Odoo releases one major (Long Term Support (LTS)) version and a few minor versions. Minor versions are mostly used in Odoo's online SaaS service, meaning that Odoo SaaS users get early access to these features. Major version branches have names such as 12.0, 11.0, and 10.0, while minor version branches have names such as saas-12.1, saas-11.1, and saas-11.2 on GitHub. The master branch is under development and is subject to change at any time. Consequently, it is advisable not to use this for production, since it might break down your database.
Runbot is Odoo's automated testing environment. This pulls the latest branches from Odoo's Git repositories and creates the builds for the last four commits. Here, you can test all stable and in-development branches. You can even play with the Enterprise Edition and its development branches.
Every build has a different background color, which indicates the status of the test cases. A green background color means that all of the test cases run successfully and you can test that branch, while a red background color means that some test cases have failed on this branch and some features might be broken on that build. You can view the logs for all test cases, which show exactlywhat happens during installation. Every build has two databases. Theall database has all of the modules installed on it, while thebasedatabase only has base Odoo modules installed. Every build is installed with basic demo data, and therefore you can test it quickly without extra configurations.
The following credentials can be used to access any runbot build:
Login ID:
admin
Password:
admin
Login ID:
demo
Password:
demo
Login ID:
portal
Password:
portal
Odoo launched the app store a few years back, and this was an instant success. Right now, there are over 15,000 different apps hosted there. In the app store, you will find lots of free and paid applications for different versions. This includes specific solutions for different business verticals, such as education, food industries, and medicine. It also includes apps that extend/add new features to existing Odoo applications. The app store also provides numerous beautiful themes for the Odoo website builder. In Chapter 4, Creating Odoo Add-On Modules, we will look at how you can set pricing and currency for your custom module.
You can access the Odoo app store via the following URL: https://www.odoo.com/apps.
Odoo Community Association (OCA) is a non-profit organization that develops/manages community-based Odoo modules. All OCA modulesare open source and maintained by Odoo community members. Under the OCA's GitHub account,you will find multiple repositories for different Odoo applications. Apart from Odoo modules, it also contains various tools, a migration library, accounting localizations, and so on.
Here is the URL for OCA's official GitHub account: https://github.com/OCA.
Odoo has a very powerful framework, and tons of things can be achieved just by using/activating options or by following specific patterns. Consequently, if you run into some technical issues or if you are not sure about some complex cases, then you can post your query on Odoo's official help forum. Lots of developers are active on this forum, including some official Odoo employees.
You can search for or post your questions at the following URL: https://help.odoo.com.
For Odoo deployment, it is recommended to use a GNU/Linux environment. You may be more at ease using Microsoft Windows or Mac OS X, but the fact is that most Odoo developers use GNU/Linux, and you are much more likely to get support from the community for OS-level issues that occur on GNU/Linux than on Windows.
It is also recommended to develop using the same environment (the same distribution and the same version) as the one that will be used in production. This will avoid nasty surprises, such as discovering on the day of deployment that a library has a different version than expected with slightly different and incompatible behavior. If your workstation is using a different OS, a good approach is to set up a Virtual Machine (VM) on your workstation and install a GNU/Linux distribution in the VM.
This book assumes that you are running Debian GNU/Linux as its stable version (this is version 9, code name Stretch, at the time of writing). Ubuntu is another popular choice, and since it is built on top of Debian, most of the examples in this book should work without needing to be changed. Whatever Linux distribution you choose, you should have some notion of how to use it from the command line, and having knowledge about system administration will certainly not cause any harm.
We are assuming that you have Linux up and running and that you have an account with root access, either because you know the root password, or because sudo has been configured. In the following sections, we will use $(whoami) whenever the login of your work user is required in a command line. This is a shell command that will substitute your login in the command you are typing.
Some operations will definitely be easier if you have a GitHub account. If you don't have one already, go to https://github.com and create one.
To install Odoo from a source, you need to follow these steps:
Run the following commands to install the main dependencies:
$ sudo apt-get update$ sudo apt-get install -y git python3.5 postgresql nano virtualenv xz-utils wget fontconfig libfreetype6 libx11-6 libxext6 libxrender1 xfonts-75dpi
Download and install
wkhtmltopdf
:
$ wget -O wkhtmltox.tar.xz \ https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
$ tar xvf wkhtmltox.tar.xz
$ sudo mv wkhtmltox/lib/* /usr/local/lib/
$ sudo mv wkhtmltox/bin/* /usr/local/bin/
$ sudo mv wkhtmltox/share/man/man1 /usr/local/share/man/
Now, use the following code to install the build dependencies:
$ sudo apt-get install -y gcc python3.5-dev libxml2-dev \libxslt1-dev libevent-dev libsasl2-dev libssl1.0-dev libldap2-dev \libpq-dev libpng-dev libjpeg-dev
Configure PostgreSQL:
$ sudo -u postgres createuser --createdb $(whoami)$ createdb $(whoami)
Configure
git
:
$ git config --global user.name "Your Name"$ git config --global user.email [email protected]
Clone the Odoo code base:
$ mkdir ~/odoo-dev$ cd ~/odoo-dev$ git clone -b 12.0 --single-branch\ https://github.com/odoo/odoo.git$ cd odoo
Create an
odoo-12.0
virtual environment and activate it:
$ virtualenv -p python3 ~/odoo-12.0
$ source ~/odoo-12.0/bin/activate
Install the Python dependencies of Odoo in
virtualenv
:
$ pip3 install -r requirements.txt
Create and start your first Odoo instances:
$ createdb odoo-test$ python3 odoo-bin -d odoo-test --addons-path=addons \ --db-filter=odoo-test$
Point your browser to
http://localhost:8069
and authenticate it by using the
admin
account and using
admin
as the password.
You can download the code files by following these steps:
You can also download the code files by clicking on the Code Files button on this book's web page on the Packt Publishing website. This page can be accessed by entering this book's title in the search box. Note that you need to be logged into your Packt account to do this.
Once the file has been downloaded, ensure that you unzip or extract the folder using the latest version of the following tool: