How to do it...

We will make a change in the change_state method from the previous recipe and display a helpful message when the user is trying to change the state that is not allowed by the is_allowed_transition method. Follow these steps to get started:

  1. Add the following import at the beginning of the Python file:
from odoo.exceptions import UserError
from odoo.tools.translate import _
  1. Modify the change_state method and raise a UserError exception from the else part:
@api.multi
def change_state(self, new_state):
for book in self:
if book.is_allowed_transition(book.state, new_state):
book.state = new_state
else:
msg = _('Moving from %s to %s is not allowed') % (book.state, new_state)
raise UserError(msg)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset