Redirecting the user

The method in step 2 does not return anything. This will cause the wizard dialog to be closed after the action is performed. Another possibility is to have the method return a dictionary with the fields of an ir.action. In this case, the web client will process the action as if a menu entry had been clicked on by the user. The get_formview_action() method defined on the BaseModel class can be used to achieve this. For instance, if we wanted to display the form view of the member who has just borrowed the books, we could have written the following:

    @api.multi 
    def record_borrows(self): 
loan = self.env['library.book.loan'] for wizard in self: member = wizard.member_id books = wizard.book_ids for book in books:
loan.create({'member_id': member.id,
'book_id': book.id}) members = self.mapped('member_id')
action = members.get_formview_action()
if len(member_ids) > 1: action['domain'] = [('id', 'in', tuple(member_ids))]
action['view_mode'] = 'tree,form'
return action

This builds a list of members who have borrowed books from this wizard (in practice, there will only be one such member, when the wizard is called from the user interface) and creates a dynamic action, which displays the members with the specified IDs.

This trick can be extended by having a wizard (with several steps to be performed one after the other), or depending on some condition from the preceding steps, by providing a Next button that calls a method defined on the wizard. This method will perform the step (maybe using a hidden field and storing the current step number), update some fields on the wizard, and return an action that will redisplay the same updated wizard and get ready for the next step.

..................Content has been hidden....................

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