Odoo 14 Development Cookbook - Parth Gajjar - E-Book

Odoo 14 Development Cookbook E-Book

Parth Gajjar

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

With its latest iteration, the powerful Odoo framework released a wide variety of features for rapid application development. This updated Odoo development cookbook will help you explore the new features in Odoo 14 and learn how to use them to develop Odoo applications from scratch. You'll learn about the new website concepts in Odoo 14 and get a glimpse of Odoo's new web-client framework, the Odoo Web Library (OWL).
Once you've completed the installation, you'll begin to explore the Odoo framework with real-world examples. You'll then 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) applications. This book isn't just limited to backend development; you'll discover advanced JavaScript recipes for creating new views and widgets. As you progress, you'll learn about website development and become a quality Odoo developer by studying performance optimization, debugging, and automated testing. Finally, you'll delve into advanced concepts such as multi-website, In-App Purchasing (IAP), Odoo.sh, the IoT Box, and security.
By the end of the book, you'll have all the knowledge you need to build impressive Odoo applications and you'll be well versed in development best practices that will come in handy when 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:

EPUB
MOBI

Seitenzahl: 875

Veröffentlichungsjahr: 2020

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Odoo 14 Development Cookbook

Fourth Edition

Rapidly build, customize, and manage secure and efficient business apps using Odoo's latest features

Parth Gajjar

Alexandre Fayolle

Holger Brunn

Daniel Reis

BIRMINGHAM—MUMBAI

Odoo 14 Development Cookbook Fourth Edition

Copyright © 2020 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.

Group Product Manager: Aaron Lazar

Associate Publishing Product Manager: Shweta Bairoliya

Senior Editor: Rohit Singh

Content Development Editor: Dwayne Fernandes, Tiksha Lad

Technical Editor: Pradeep Sahu

Copy Editor: Safis Editing

Project Coordinator: Deeksha Thakkar

Proofreader: Safis Editing

Indexer: Pratik Shirodkar

Production Designer: Prashant Ghare

First published: April 2016

Second edition: January 2018

Third edition: April 2019

Fourth edition: December 2020

Production reference: 2150221

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80020-031-9

www.packt.com

I dedicate this book to my parents with love and gratitude. Thank you for giving me the freedom and support to follow my ambitions throughout my childhood.

– Parth Gajjar

Packt.com

Subscribe to our online digital library for full access to over 7,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.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and videos from over 4,000 industry professionalsImprove your learning with Skill Plans built especially for youGet a free eBook or video every monthFully searchable for easy access to vital informationCopy 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 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.

Contributors

About the authors

Parth Gajjar is an Odoo expert with a deep understanding of the Odoo framework. He started his career at Odoo and spent 7 years in the R&D department at Odoo India. During his time at Odoo, he worked on several key features, including a marketing automation app, mobile application, report engine, domain builder, and more. He also worked as a code reviewer and helped manage the code quality of the new features. Later, he started his own venture named Droggol and now provides various development services related to Odoo. He loves working on Odoo and solving real-world business problems with different technologies. He often gives technical training to Odoo developers.

I would like to thank my parents and family members for all of the support they have given throughout the writing of this book.

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.

Daniel Reis has had a long career in the IT industry, largely as a consultant implementing business applications in a 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.

About the reviewer

Kishan Gajjar is a lead developer at Droggol and has been working on Odoo for the last 4 years. Previously, he worked at the Indian branch of Odoo for 3 years in the R&D department. During his time at Odoo, he mostly worked on the website builder, themes, and the backend JavaScript framework. Later, he established Droggol as one of the co-founders. He has expertise in website and theme development and loves creating beautiful and eye-catching websites in Odoo. Aside from development, he loves playing video games.

To begin with, I would like to thank my parents for allowing me to follow my ambitions throughout my childhood, and also my brother, who encourages me in his own particular way. He has been my inspiration and motivation.

Packt is searching for authors like you

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.

Table of Contents

Preface

Chapter 1: Installing the Odoo Development Environment

Understanding the Odoo ecosystem

Odoo editions

Git repositories

Runbot

Odoo app store

Odoo Community Association

Official Odoo help forum

Odoo's eLearning platform

Easy installation of Odoo from source

Getting ready

How to do it...

How it works...

Managing Odoo server databases

Getting ready

How to do it...

How it works...

There's more...

Storing the instance configuration in a file

How to do it...

How it works...

Activating Odoo developer tools

How to do it...

How it works...

Updating the add-on modules list

Getting ready

How to do it…

How it works…

Chapter 2: Managing Odoo Server Instances

Configuring the add-ons path

Getting ready

How to do it…

How it works…

There's more…

Standardizing your instance directory layout

How to do it…

How it works…

There's more...

Installing and upgrading local add-on modules

Getting ready

How to do it…

How it works…

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…

Chapter 3: Creating Odoo Add-On Modules

Technical requirements

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...

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...

Chapter 4: Application Models

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...

There's more...

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...

Copy model definition using inheritance

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...

Using abstract models for reusable model features

Getting ready

How to do it...

How it works...

There's more...

Chapter 5: Basic Server-Side Development

Technical requirements

Defining model methods and using API decorators

Getting ready

How to do it...

How it works...

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 using read_group()

Getting ready

How to do it...

How it works...

Chapter 6: Managing Module Data

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...

Chapter 7: Debugging Modules

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

Understanding the debug mode options

How to do it...

How it works...

Chapter 8: Advanced Server-Side Development Techniques

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...

See also

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...

See also

Defining onchange with the compute method

Getting ready

How to do it...

How it works...

There's more...

See also

Defining a model based on a SQL view

Getting ready

How to do it...

How it works...

There's more...

See also

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...

Chapter 9: Backend Views

Technical requirements

Adding a menu item and window actions

Getting ready

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...

There's more...

Adding content and widgets to a form view

How to do it...

How it works...

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...

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

Adding a search filter side panel

Getting ready

How to do it...

How it works...

There's more...

Changing existing views – view inheritance

How to do it...

How it works...

There's more...

Defining document-style forms

How to do it...

How it works...

See also

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...

See also

Showing kanban cards in columns according to their state

Getting ready

How to do it...

How it works...

There's more...

Defining calendar views

How to do it...

How it works...

There's more...

Defining graph view and pivot view

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....

Defining the gantt view

Getting ready

How to do it...

How it works...

There's more...

Defining the activity view

Getting ready

How to do it...

How it works...

Defining the map view

Getting ready

How to do it…

How it works...

Chapter 10: Security Access

Technical requirements

Creating security groups and assigning them to users

Getting ready

How to do it...

How it works...

There's more...

See also

Adding security access to models

Getting ready

How to do it...

How it works...

There's more...

See also

Limiting access to fields in models

Getting ready

How to do it...

How it works...

There's more...

See also

Limiting record access using record rules

Getting ready

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...

See also

Chapter 11: Internationalization

Installing a language and configuring user preferences

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...

Changing the custom language URL code for a website

Getting ready

How to do it...

How it works...

Chapter 12: Automation, Workflows, Emails, and Printing

Technical requirements

Managing dynamic record stages

Getting ready

How to do it...

How it works...

There's more...

See more

Managing kanban stages

Getting started

How to do it...

How it works...

There's more...

See more

Adding a quick create form to 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...

See more

Using automated actions on time conditions

Getting ready

How to do it...

How it works...

There's more...

See 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...

Managing activities from a kanban card

Getting started

How to do it...

How it works...

There's more…

See also

Adding a stat button to a form view

Getting started

How to do it...

How it works...

See also

Enabling the archive option for records

Getting started

How to do it...

How it works...

There's more…

Chapter 13: Web Server Development

Technical requirements

Making a path accessible from the network

Getting ready

How to do it...

How it works...

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

Serving static resources

Getting ready

How to do it...

How it works…

Chapter 14: CMS Website Development

Managing static assets

What are asset bundles and different assets in Odoo?

Custom assets

How to do it...

How it works...

There's more...

Adding CSS and JavaScript for a website

Getting ready

How to do it...

How it works...

There's more...

Creating or modifying templates – QWeb

Getting ready

How to do it...

How it works...

There's more...

See also

Managing dynamic routes

Getting ready

How to do it...

How it works...

There's more...

Offering static snippets to the user

Getting ready

How to do it...

How it works...

There's more...

Offering dynamic snippets to the user

Getting ready

How to do it...

How it works...

There's more...

Getting input from website users

Getting ready

How to do it...

How it works...

There's more...

Managing 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...

There's more...

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...

Redirecting old URLs

Getting ready

How to do it...

How it works...

Publish management for website-related records

Getting ready

How to do it…

How it works...

There's more…

Chapter 15: Web Client Development

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 tours

Getting ready

How to do it...

How it works...

Mobile app JavaScript

Getting ready

How to do it...

How it works...

There's more...

Chapter 16: The Odoo Web Library (OWL)

Technical requirements

Creating an OWL component

Getting ready

How to do it...

How it works...

There's more...

Managing user actions in an OWL component

Getting ready

How to do it...

How it works...

There's more...

Making OWL components reactive

Getting ready

How to do it...

How it works...

Understanding the OWL component life cycle

Getting ready

How to do it...

How it works...

There's more...

Adding an OWL field to the form view

Getting ready

How to do it...

How it works...

Chapter 17: In-App Purchasing with Odoo

Technical requirements

IAP 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...

Chapter 18: Automated Test Cases

Technical requirements

Adding 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...

Adding 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...

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...

Populating random data for testing

Getting ready

How to do it...

How it works...

There's more…

Chapter 19: Managing, Deploying, and Testing with Odoo.sh

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...

How it works...

Accessing debugging options

How to do it...

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...

There's more...

Chapter 20: Remote Procedure Calls in Odoo

Technical requirements

Logging in to/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 to/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...

Creating/updating/deleting 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

Generating API keys

How to do it...

How it works...

Chapter 21: Performance Optimization

The prefetching pattern for recordsets

How to do it…

How it works...

There's more...

The in-memory cache – ormcache

How to do it...

How it works...

There's more...

Generating differently sized images

How to do it...

How it works...

There's more...

Accessing grouped data

How to do it...

How it works...

There's more...

See also

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...

Chapter 22: Point of Sale

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...

There's more...

Modifying the Point of Sale 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...

Chapter 23: Managing Emails in Odoo

Technical requirements

Configuring incoming and outgoing email servers

Getting ready

How to do it...

How it works...

There's more...

Managing chatter on documents

Getting ready

How to do it...

How it works...

There's more...

Managing activities on documents

Getting ready

How to do it...

How it works...

There's more...

Sending emails using the Jinja template

Getting ready

How to do it...

How it works...

There's more...

Sending emails using the QWeb template

Getting ready

How to do it...

How it works...

There's more...

Managing the email alias

Getting ready

How to do it...

How it works...

There's more...

Logging user changes in a chatter

Getting ready

How to do it...

How it works...

Sending periodic digest emails

Getting ready

How to do it...

How it works...

Chapter 24: Managing the 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 a network

Getting ready

How to do it...

How it works...

Adding the IoT Box to Odoo

Getting ready

How to do it...

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's 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...

Sending PDF reports directly to a printer

Getting ready

How to do it...

How it works...

Other Books You May Enjoy

Chapter 1: Installing the Odoo Development Environment

There are several 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.

If you are new to Odoo development, you must know about certain aspects of the Odoo ecosystem. The first recipe will give you a brief introduction to the Odoo ecosystem, and then we will move on to the installation of Odoo for development.

In this chapter, we will cover the following recipes:

Understanding the Odoo ecosystemEasy installation of Odoo from sourceManaging Odoo server databasesStoring the instance configuration in a fileActivating Odoo developer toolsUpdating the add-on modules list

Understanding the Odoo ecosystem

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 embarking on your journey of becoming a successful Odoo developer.

Odoo editions

Odoo comes with two different editions. The first one is the Community Edition, which is open source, and the second one is the Enterprise Edition, which has licensing fees. Unlike other software vendors, Odoo Enterprise Edition is just a pack of extra applications that adds extra features or new apps to the Community Edition. Basically, the 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 sales, Customer Relationship Management (CRM), invoicing, purchases, and website builder. Alternatively, the Enterprise Edition comes with the Odoo Enterprise Edition License, which is a proprietary license. Odoo Enterprise Edition has a number of advanced features, such as full accounting, studio, Voice over Internet Protocol (VoIP), mobile responsive design, e-sign, marketing automation, delivery and banking integrations, IoT, and more. The Enterprise Edition also provides you with unlimited bugfix support. The following diagram shows that the Enterprise Edition depends on the Community Edition, which is why you need the latter in order to use the former:

Figure 1.1 – Differences between the Community and Enterprise Editions

You can see a full comparison of both editions here: https://www.odoo.com/page/editions.

Note

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. Some 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.

Git repositories

The entire 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:

Table 1.1

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 14.0, 13.0, and 12.0, while minor version branches have names such as saas-14.1, and saas-14.2 on GitHub. These minor versions are mostly used for Odoo's SaaS platform. The master branch is under development and is unstable, so it is advisable not to use this for production since it might break down your database.

Runbot

Runbot is Odoo's automated testing environment. Whenever there is a new commit in Odoo's GitHub branch, Runbot pulls those latest changes 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 exactly what happens during installation. Every build has two databases. The all database has all of the modules installed on it, while the base database only has base Odoo modules installed. Every build is installed with basic demo data, and therefore you can test it quickly without extra configurations.

Note

You can access Runbot from the following URL: http://runbot.odoo.com/runbot.

The following credentials can be used to access any Runbot build:

Login ID: admin Password: adminLogin ID: demo Password: demoLogin ID: portal Password: portal

Note

This is a public testing environment, so sometimes it is possible that other users are using/testing the same branch that you are testing.

Odoo app store

Odoo launched the app store a few years back, and this was an instant hit. Right now, there are over 22,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 or add new features to existing Odoo applications. The app store also provides numerous beautiful themes for the Odoo website builder. In Chapter 3, 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.

You can access the Odoo themes via the following URL: https://www.odoo.com/apps/themes.

Note

Odoo has open sourced several themes with versions 13 and 14. Note that these were paid themes in previous versions. This means that, in Odoo versions 13 and 14, you can download and use those beautiful themes at no extra cost.

Odoo Community Association

Odoo Community Association (OCA) is a non-profit organization that develops/manages community-based Odoo modules. All OCA modules are 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.

Official Odoo help forum

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 your questions or post your new questions at the following URL: https://help.odoo.com.help.odoo.com.

Odoo's eLearning platform

Recently, Odoo has launched a new eLearning platform. This platform has lots of videos that explain how to use different Odoo applications. At the time of writing this book, this platform does not have technical videos, just functional ones.

Here is the URL for Odoo's eLearning platform: https://www.odoo.com/slides.

Easy installation of Odoo from source

It is highly recommended to use the Linux Ubuntu operating system for the installation of Odoo, since this is the operating system that Odoo uses for all its tests, debugging, and installations of Odoo Enterprise, in addition to the fact that most developers of Odoo also use GNU/Linux distributions, and is much more likely to get support from the Odoo community for OS-level issues that occur in GNU/Linux than Windows or macOS.

It is also recommended to develop Odoo add-on modules 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 a 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.

Note

Ubuntu is available as an app in Microsoft Store so you can use that too, if you do not want to switch to Ubuntu OS.

For this book, we will be using Ubuntu Server 18.04 LTS, but you can use any another Debian GNU/Linux OS. Whatever Linux distribution you choose, you should have some notion of how to use it from the command line, and having knowledge of system administration will certainly not do any harm.

Getting ready

We are assuming that you have Ubuntu 18.04 up and running and that you have an account with root access or that sudo has been configured. In the following sections, we will install Odoo's dependencies and download Odoo's source code from GitHub.

Note

Some of the configurations require a system login username, so we will use $(whoami) whenever a login username 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.

How to do it...

To install Odoo from source, perform the following steps:

Run the following commands to install the main dependencies:

$ sudo apt-get update

$ sudo apt install git python3-pip build-essential wget python3-dev python3-venv python3-wheel libxslt-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools libpng12-0 libjpeg-dev gdebi -y

Download and install wkhtmltopdf:

$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.trusty_amd64.deb

$ sudo dpkg -i wkhtmltox_0.12.5-1.trusty_amd64.deb

If you find errors in a previous command, force install the dependencies with the following command:

$ sudo apt-get install -f

Now, install the PostgreSQL database:

$ sudo apt install postgresql -y

Configure PostgreSQL:

$ sudo -u postgres createuser --superuser $(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 14.0 --single-branch --depth 1 https://github.com/odoo/odoo.git

Create an odoo-14.0 virtual environment and activate it:

$ python3 -m venv ~/venv-odoo-14.0

$ source ~/venv-odoo-14.0/bin/activate

Install the Python dependencies of Odoo in venv:

$ cd ~/odoo-dev/odoo/

$ pip3 install -r requirements.txt

Create and start your first Odoo instances:

$ createdb odoo-test

$ python3 odoo-bin -d odoo-test –i base --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.

Note

If you need RTL support, please install node and rtlcss via the following command:sudo apt-get install nodejs npm -y sudo npm install -g rtlcss

How it works...

In step 1, we installed several core dependencies. These dependencies include various tools, such as git, pip3, wget, Python setup tools, and more. These core tools will help us install other Odoo dependencies using simple commands.

In step 2, we downloaded and installed the wkhtmltopdf package, which is used in Odoo to print PDF documents such as sale orders, invoices, and other reports. Odoo 14.0 needs version 0.12.5 of wkhtmltopdf, and that exact version might be not included in the current Linux distributions. Fortunately for us, the maintainers of wkhtmltopdf provide pre-built packages for various distributions at http://wkhtmltopdf.org/downloads.html and we have downloaded and installed it from that URL.

PostgreSQL configuration

In step 3, we installed the PostgreSQL database.

In step 4, we created a new database user with the login name of your system. $(whoami) is used to fetch your login name, and the -s option is used to give super user rights. Let's see why we need these configurations.

Odoo uses the psycopg2 Python library to connect with a PostgreSQL database. To access a PostgreSQL database with the psycopg2 library, Odoo uses the following values by default:

By default, psycopg2 tries to connect to a database with the same username as the current user on local connections, which enables password-less authentication (this is good for the development environment).The local connection uses Unix domain sockets.The database server listens on port 5432.

That's it! Your PostgreSQL database is now ready to be connected with Odoo.

As this is a development server, we have given --superuser rights to the user. It is OK to give the PostgreSQL user more rights as this will be your development instance. For a production instance, you can use the --createdb command line instead of --superuser to restrict rights. The –superuser rights in a production server will give additional leverage to an attacker exploiting a vulnerability in some part of the deployed code.

If you want to use a database user with a different login, you will need to provide a password for the user. This is done by passing the --pwprompt flag on the command line when creating the user, in which case the command will prompt you for the password.

If the user has already been created and you want to set a password (or modify a forgotten password), you can use the following command:

$ psql -c "alter role $(whoami) with password 'newpassword'"

If this command fails with an error message saying that the database does not exist, it is because you did not create a database named after your login name in step 4 of this recipe. That's fine; just add the --dbname option with an existing database name, such as --dbname template1.

Git configuration

For the development environment, we are using Odoo sourced from GitHub. With git, you can easily switch between different Odoo versions. Also, you can fetch the latest changes with the git pull command.

In step 5, we configured your git user.

In step 6, we downloaded the source code from Odoo's official GitHub repository. We have used the git clone command to download Odoo's source code. We have used a single branch as we only want a branch for the 14.0 version. Also, we have used --depth 1 to avoid downloading the full commit history of the branch. These options will download the source code very quickly, but if you want, you can omit those options.

Odoo developers also propose nightly builds, which are available as tarballs and distribution packages. The main advantage of using git clone is that you will be able to update your repository when new bug fixes are committed in the source tree. You will also be able to easily test any proposed fixes and track regressions so that you can make your bug reports more precise and helpful for developers.

Note

If you have access to the enterprise edition source code, you can download that too in a separate folder under the ~/odoo-dev directory.

Virtual environments

Python virtual environments, or venv for short, are isolated Python workspaces. These are very useful to Python developers because they allow different workspaces with different versions of various Python libraries to be installed, possibly on different Python interpreter versions.

You can create as many environments as you wish using the python3 -m venv ~/newvenv command. This will create a newvenv directory in the specified location, containing a bin/ subdirectory and a lib/python3.6 subdirectory.

In step 7, we created a new virtual environment in the ~/venv-odoo-14.0 directory. This will be our isolated Python environment for Odoo, and all of Odoo's Python dependencies will be installed in this environment.

To activate the virtual environment, we need to use the source command. With the source ~/venv-odoo-14.0/bin/activate command, we have activated the virtual environment.

Installing Python packages

Odoo's source code has a list of Python dependencies in requirements.txt. In step 8, we installed all those requirements via the pip3 install command.

That's it. Now you can run the Odoo instance.

Starting the instance

Now comes the moment you've been waiting for. To start our first instance, in step 9, we first created a new empty database, used the odoo-bin script, and then started the Odoo instance with the following command:

python3 odoo-bin -d odoo-test -i base --addons-path=addons --db-filter=odoo-test$

You can also omit python3 by using ./ before odoo-bin as it is an executable Python script, as follows:

./odoo-bin -d odoo-test –i base --addons-path=addons --db-filter=odoo-test$

With odoo-bin, a script with the following command-line arguments are used:

-d database_name: Use this database by default.--db-filter=database_name$: Only try to connect to databases that match the supplied regular expression. One Odoo installation can serve multiple instances that live in separate databases, and this argument limits the available databases. The trailing $ is important as the regular expression is used in match mode. This enables you to avoid selecting names starting with the specified string.--addons-path=directory1,directory2,...: This is a comma- separated list of directories in which Odoo will look for add-ons. This list is scanned at instance creation time to populate the list of available add-on modules in the instance. If you want to use Odoo's Enterprise Edition, then add its directory with this option.-i base: This is used to install a base module. This is required when you have created a database via the command line.

If you are using a database user with a database login that is different from your Linux login, you need to pass the following additional arguments:

--db_host=localhost: Use a TCP connection to the database server.--db_user=database_username: Use the specified database login.--db_password=database_password: This is the password for authenticating against the PostgreSQL server.

To get an overview of all available options, use the --help argument. We will see more of the odoo-bin script later in this chapter.

When Odoo is started on an empty database, it will first create the database structure that's needed to support its operations. It will also scan the add-ons path to find the available add-on modules and insert some into the initial records in the database. This includes the admin user with the default admin password, which you will use for authentication.

Pointing your web browser to http://localhost:8069/ leads you to the login page of your newly created instance, as shown in the following screenshot:

Figure 1.2 – Login screen of the Odoo instance

This is due to the fact that Odoo includes an HTTP server. By default, it listens on all local network interfaces on TCP port 8069.

Managing Odoo server databases

When working with Odoo, all the data in your instance is stored in a PostgreSQL database. All the standard database management tools you are used to are available, but Odoo also proposes a web interface for some common operations.

Getting ready

We are assuming that your work environment is set up and that you have an instance running.

How to do it...

The Odoo database management interface provides tools to create, duplicate, remove, back up, and restore a database. There is also a way to change the master password, which is used to protect access to the database management interface.

Accessing the database management interface

To access the database, perform the following steps:

Go to the login screen of your instance (if you are authenticated, log out).Click on the Manage Databases link. This will navigate to http://localhost:8069/web/database/manager (you can also point your browser directly to that URL):

Figure 1.3 – Database manager

Setting or changing the master password

If you've set up your instance with default values and haven't modified it yet, as we will explain in the following section, the database management screen will display a warning, telling you that the master password hasn't been set and will advise you to set one with a direct link:

Figure 1.4 – Master password warning

To set the master password, perform the following steps:

Click on the Set Master Password button. You will get a dialog box asking you to fill in the New Master Password field:

Figure 1.5 – Setting a new master password dialog

Type in a non-straightforward new password and click Continue.

If the master password is already set, click on the Set Master Password button at the bottom of the screen to change it. In the displayed dialog box, type the previous master password and the new one and then click on Continue.

Note

The master password is the server configuration file under the admin_password key. If the server was started without specifying a configuration file, a new one will be generated in ~/.odoorc. Refer to the next recipe for more information about the configuration file.

Creating a new database