Adding custom logic

Website forms allow us to plug in our own validations and computations to form processing. This is done by implementing a website_form_input_filter() method with the logic on the target model. This method should expect a values argument, containing a dictionary, performing validations, and even modifying it, and then return the final values dictionary to be used.

We will make use of it to implement two features:

  • Removing any leading and trailing spaces from the task title
  • Ensuring that the task title is at least three characters long

Add the todo_website/models/todo_task.py file containing the following code:

from odoo import api, models from odoo.exceptions import ValidationError class TodoTask(models.Model): _inherit ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.