Here after the book count falls below 0 warning is displayed but it is possible to add items again to the field even after the warning .How to make the field such that it is not possible to add items again after the count of items fall below zero.What i am asking is how to disable add an item option in many2many field after a certain condition (disable add an item option when book count falls below zero) is met.
@api.depends('member_name')
def name_member(self):
for data in self:
if len(data.member_name) >= self.book_selected.number_of_books :
raise exceptions.ValidationError("BOOK NOT AVAILABLE")
else:
data.copies_remain = self.book_selected.number_of_books-len(data.member_name)
new_count = self.book_selected.number_of_books-len(data.member_name)
self.book_selected.write({'copies_left': new_count})
You can use one Boolean field to set such validation.
Instead of raising ValidationError, return Warning on onchange method. and at same time, make that boolean field True and set attrs of readonly on that field.
But I can't say this is perfect solution for you, as once field gets readonly, you won't be able to items again.
from your question problem statement is not much clear.
hope that helps to you.
Try giving limit , once the limit is given there will not be any warning or validation will be shown, but only in it the number in the limit will get saved