Book Image

Odoo 12 Development Essentials - Fourth Edition

By : Daniel Reis
Book Image

Odoo 12 Development Essentials - Fourth Edition

By: Daniel Reis

Overview of this book

Odoo is one of the best platforms for open source ERP and CRM. Its latest version, Odoo 12, brings with it new features and updates in Python packages to develop more customizable applications with additional cloud capabilities. The book begins by covering the development essentials for building business applications. You will start your journey by learning how to install and configure Odoo, and then transition from having no specific knowledge of Odoo to being ready for application development. You will develop your first Odoo application and understand topics such as models and views. Odoo 12 Development Essentials will also guide you in using server APIs to add business logic, helping you lay a solid foundation for advanced topics. As you progress through the chapters, you will be equipped to build and customize your applications and explore the new features in Odoo 12, such as cloud integration, to scale your business applications. You will get insights into building business logic and integrating various APIs into your application. By the end of the book, you will be able to build a business application from scratch by using the latest version of Odoo.
Table of Contents (22 chapters)
Title Page
Packt Upsell
Foreword
Contributors
Preface
Index

Chapter 4


  1. How do we extend an existing Model to add a mixin, such as mail.thread?

Both in-place classic extension and mixin prototype inheritance use the same _inherit Model attribute. For example, to extend x and add the y mixin, we should have the _name='x' model attribute and the _inherit = ['x', 'y'] Model attribute.

  1. What changes are needed to also have the phone field available in the member form view?

No model changes are needed, since a phone field exists in partners, and delegation inheritance makes all partner fields also available on the member Model. We only need to add the field to the form view, for example, next to the email field: <field name=phone" />.

  1. What happens if you create a Model class with name attribute different form the inherit attribute (for example, _name='y' and _inherit='x')?

A new ymodel will be created, copying all the features (data structure and methods) from Model x. If x is a database-stored Model, we will have two database tables with the same fields, but independent data records, which is not a good design practice. That's why this is usually used with abstract mixin classes that don't have an actual database representation.

 

 

  1. Can XPath be used to modify data record from other modules?

No. XPath is used only for views, to find the element in the view structure where the extension should be done. This extension is performed at runtime, and no actual change is made to the record being extended.

  1. When inheriting a Model to extend it, can we extend a method and not use super() to call original code being inherited?

We can, and sometimes we may have to, but we should avoid it. When not using super() we are completely replacing the original code, our re-implementation will have different behavior form the original one, and it may have unanticipated side-effects. Also, extensions implemented in other modules may not work as expected. If the parent method is hard to extend, it's best to propose changes to it, so that it includes extension points we can use (separating part of the logic into their own methods will make extension simpler).

  1. How can we extend the book catalog web page to add the ISBN field at the end of the line without referencing any particular field name?

We can insert the ISBN field inside the row div element: <xpath expr="//div[class='row']"><span t-field="book.isbn"/></xpath>