How to do it...

In this recipe, we will manually create a record of the library.return.wizard model. We want the onchange method to compute the returned books for us. To do this, you need to perform the following steps:

  1. Create the return_this_books method in the library.book model:
    @api.multi 
    def return_all_books(self): 
        self.ensure_one()
  1. Get an empty recordset for library.return.wizard:
    wizard = self.env['library.return.wizard']
  1. Prepare the values to create a new wizard record. Here, we will use a current user's partner ID as the borrower_id, but if you want to put this button on the res.parnter model, you can use self.id:
    values = {
'borrower_id': self.env.user.partner_id.id,
}
  1. Retrieve the onchange specifications for the wizard:
specs = wizard._onchange_spec() 
  1. Get the results of the onchange method:
updates = wizard.onchange(values, ['borrower_id'], specs)
  1. Merge these results with the values of the new wizard:
value = updates.get('value', {})
for name, val in value.items():
if isinstance(val, tuple):
value[name] = val[0]
values.update(value)
  1. Create the wizard:
wiz = wizard.create(values)
return wiz.sudo().books_returns()
..................Content has been hidden....................

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