Book Image

Odoo 11 Development Cookbook - Second Edition - Second Edition

Book Image

Odoo 11 Development Cookbook - Second Edition - Second Edition

Overview of this book

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source are also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. Version 11 offers better usability and speed: a new design (as compared to the current Odoo Enterprise version) and a mobile interface. The book starts by covering Odoo installation and administration and Odoo Server deployment. It then delves into the implementation of Odoo modules, the different inheritance models available in Odoo. You will then learn how to define access rules for your data; how to make your application available in different languages; how to expose your data models to end users on the back end and on the front end; and how to create beautiful PDF versions of your data. By the end of the book, you will have a thorough knowledge of Odoo and will be able to build effective applications by applying Odoo development best practices
Table of Contents (18 chapters)

To get the most out of this book

This book is meant for developers, and it is not a development tutorial. It expects you to be familiar with the Python programming language (especially in the backend development chapters), the JavaScript programming language (especially in the front end development chapters). Since the data files in the modules are often formatted as XML files, some knowledge of the XML syntactic rule is definitely welcome.

Odoo will run without problem on any recent GNU/Linux distribution. In order to simplify the code in the recipes, we chose to Debian GNU/Linux 9 (code name Stretch), so it will also help if you had some previous acquaintance with the apt-get command used to install software packages, and some notions about GNU/Linux system administration.

Download the example code files

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:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. 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 latest version 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 at https://github.com/PacktPublishing/Odoo-11-Development-Coobook-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Create a virtualenv and install the dependencies"

A block of code is set as follows:

from odoo import models, fields, api 
class LibraryBook(models.Model): 
    # [...] 
    state = fields.Selection([('draft', 'Unavailable'), 
                              ('available', 'Available'), 
                              ('borrowed', 'Borrowed'), 
                              ('lost', 'Lost')], 
                             'State') 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

def export_stock_level(self, stock_location): 
    import pdb; pdb.set_trace() 
    products = self.with_context(location=stock_location.id).search([]) 
    fname = join(EXPORTS_DIR, 'stock_level.txt') 
    try: 
        with open(fname, 'w') as fobj: 
            for prod in products.filtered('qty_available'): 
                fobj.write('%s\t%f\n' % (
prod.name, prod.qty_available)) except IOError: raise exceptions.UserError('unable to save file')

Any command-line input or output is written as follows:

$ ../odoo/odoo-bin --save --config myodoo.cfg --stop-after-init

In the example above $ is the command line prompt, and it should not be typed. When the command line prompt is a hash sign (#), this means that the command must be run as the root user. Some command lines had to be wrapped on multiple lines due to the width of the pages. In these cases, there is a backslash (\) at the end of the line. When typing the command you may want to ignore these backslashes completely and not input them, entering the whole command on a single line. If you choose to type them, you must not add any spaces after the backslash and hit the Return key immediately to insert a new line character just after the backslash.

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Go to the Settings menu."

Warnings or important notes appear like this.
Tips and tricks appear like this.