Search code examples
pythonodooodoo-15

How to limit quantity of lines in a notebook [Odoo 15]


I want to limit the quantity of "Order lines" to 2 products only (When 2 products are loaded, I want the "Add a Product", "Add a section" and "Add a note" buttons to disappear automatically).

I tried to use an @api.constrains but it only validates when I click Save button.

enter image description here


Solution

  • Solved

    @api.onchange('reservation_line')
    def _onchange_check_cabanias(self):
        if len(self.reservation_line) > 1:
            raise ValidationError("Only one habitation per reserve is allowed")