Posts

Understanding @api.depends vs @api.onchange in Odoo 19

Image
  One of the most confusing topics for many Odoo developers — especially beginners — is the difference between @api.depends and @api.onchange . At first glance, both seem to react when a field changes. But internally, they work very differently and are used for completely different purposes. Understanding when to use each one is extremely important for writing clean, efficient, and bug-free Odoo modules. What is @api.depends ? @api.depends is used with computed fields . It tells Odoo: “Recompute this field whenever these dependent fields change.” The value is computed: on the server side automatically and can optionally be stored in the database Example of @api.depends from odoo import models, fields, api class Student(models.Model): _name = 'student.student' name = fields.Char() mark1 = fields.Float() mark2 = fields.Float() total = fields.Float( compute='_compute_total', store=True ) @api.depends('mark1', 'm...