How it works...

Step 1 defines a new model. It is no different from other models, apart from the base class, which is TransientModel instead of Model. Both TransientModel and Model share a common base class called BaseModel, and if you check the source code of Odoo, you will see that 99% of the work is in BaseModel and that both Model and TransientModel are almost empty.

The only things that change for TransientModel records are as follows:

  • Records are periodically removed from the database, so the tables for transient models don't grow up in size over time.
  • You cannot define access rules on TransientModels. Anyone is allowed to create a record, but only the user who created a record can read and use it.
  • You must not define One2many fields on a TransientModel that refer to a normal model, as this will add a column on the persistent model linking to transient data. Use Many2many relations in this case. You can, of course, define Many2one and One2many fields for relations between transient models.

We define two fields in the model: one to store the member borrowing the books and one to store the list of books being borrowed. We can add other scalar fields to record a scheduled return date, for instance.

Step 2 adds the code to the wizard class that will be called when the button defined in step 3 is clicked on. This code reads the values from the wizard and creates library.book.loan records for each book.

Step 3 defines a view for our wizard. Refer to the Document-style forms recipe in Chapter 10, Backend Views, for details. The important point here is the button in the footer; the type attribute is set to 'object', which means that when the user clicks on the button, the method with the name specified by the name attribute of the button will be called.

Step 4 ensures that we have an entry point for our wizard in the menu of the application. We use target='new' in the action so that the form view is displayed as a dialog box over the current form. Refer to the Add a Menu Item and Window Action recipe in Chapter 10, Backend Views, for details.

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

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