April 2019
Beginner to intermediate
774 pages
24h 59m
English
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:
from odoo.exceptions import UserErrorfrom odoo.tools.translate import _
@api.multidef 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)
Read now
Unlock full access