Skip to Content
Menu
This question has been flagged
1 Reply
1400 Views

Went I create a Sale, 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 dissapear automatically).

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


Avatar
Discard
Best Answer

Hi

Inherit the sale.order model and inside the onchange of 'order_line' we can add ValidationError or UserError

Try like this 


@api.onchange('order_line')
def _onchange_check_lines(self):
if len(self.order_line) > 2:
raise ValidationError("Only two products are allowed")

Regards

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 22
4402
2
Dec 22
2305
1
Dec 23
996
2
Aug 23
928
1
Dec 23
2068