How it works...

In step 1, we refactor the code from the Writing a wizard to guide the user recipe in Chapter 9, Advanced Server-Side Development Techniques, to use a very common and useful coding pattern to create the library.book.loan records. The creation of the dictionary of values is extracted in a separate method rather than hard-coded in the method calling create(). This eases extending the addon module in case new values have to be passed at creation time, which is exactly the case we are facing.

Step 2 then does the extension of the business logic. We define a model that extends library.loan.wizard and redefines the _prepare_loan() method. The redefinition starts by calling the implementation from the parent class:

values = super(LibraryLoanWizard, self)._prepare_loan(book) 

In the case of Odoo models, the parent class is not what you'd expect by looking at the Python class definition. The framework has dynamically generated a class hierarchy for our recordset, and the parent class is the definition of the model from the modules on which we depend. So, the call to super() brings back the implementation of library.loan.wizard from my_module. In this implementation, _prepare_loan() returns a dictionary of values with 'member_id' and 'book_id'. We update this dictionary by adding the 'expected_return_date' key before returning it.

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

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