Skip to main content

Posts

Showing posts with the label Your First Odoo Application

Web pages and controllers

Web pages and controllers Odoo also provides a web   development   framework, which can be used to develop website features closely integrated with our backend apps. We will take our first steps toward this by creating a   simple   web page to display the list of active books in our library. It will respond to web requests at the  http://my-server/library/books   address, so   /library/books   is the URL endpoint we want to implement. We will just have a short taste of what web development with Odoo looks like. This topic is addressed in more depth in   Chapter 13 ,   Creating Website Frontend Features . Web   controllers   are the components responsible for   rendering   web pages. Controllers are methods defined in an  http.Controller   class, and they are bound to URL endpoints. When that URL endpoint is accessed, the controller code executes, producing the HTML to be presented to...

The business logic layer

The business logic layer The business logic layer encodes the application's business rules, such as validations and automatic computations. We will add the logic for our button now. This is done with Python code, using the  methods  in the Python class that represent the model. Adding business logic Previously, we added a button to the Book  Form  section to check whether the ISBN is valid. Modern ISBNs have 13 digits, where the last one is a check digit computed from the first 12. There is little point getting into the details of the algorithm used, so here is a Python function that implements this validation. It should be added inside the  class Book(...)  object, before the  name  field: Copy @api.multi def _check_isbn(self): self.ensure_one() digits = [int(x) for x in self.isbn if x.isdigit()] if len(digits) == 13: ponderations = [1, 3] * 6 terms = [a * b for a, ...

The view layer

The view layer The view  layer  describes the user interface. Views are defined using XML, which is used by the web client framework to generate data-aware HTML views. We have menu items that can activate actions that can render views. For example, the  Users  menu item processes an action also called  Users , which in turn renders a series of views. There are several view types available, such as the list (sometimes called  tree  for historical reasons) and  form  views, and the filter options made available in the top-right search box are also defined by a particular type of view, the search view. The Odoo development guidelines state that the XML files defining the user interface should be placed inside a  views/  subdirectory. Let's start creating the user interface for our to-do application. In the next sections, we will make gradual improvements and frequent module upgrades to make those changes available. You...