How to Auto-Increment a Field Value When Clicking “Add a Line” in Odoo17
In Odoo, One2many fields are widely used to manage related records directly within a form view. A common requirement is to automatically increment a field—like a sequence number—whenever a new line is added using the "Add a line" button. This article provides a easy-to-implement solution using the @api.onchange decorator in the child model, how to dynamically assign incremental values to the sequence field without manual input, improving data consistency and user experience.