How to do it...

Follow given steps to add a new wizard for creating book rent records:

  1. Add a new transient model to the module, with the following definition:
class LibraryRentWizard(models.TransientModel):
_name = 'library.rent.wizard'

borrower_id = fields.Many2one('res.partner', string='Borrower')
book_ids = fields.Many2many('library.book', string='Books')
  1. Add the callback method that performs the action on the transient model. Add the following code to the LibraryRentWizard class:
    def add_book_rents(self):
rentModel = self.env['library.book.rent']
for wiz in self:
for book in wiz.book_ids:
rentModel.create({
'borrower_id': wiz.borrower_id.id,
'book_id': book.id
})
  1. Create a form view for the model. Add the following view definition to the module views:
 <record id='library_rent_wizard_form' model='ir.ui.view'>
<field name='name'>library rent wizard form view</field>
<field name='model'>library.rent.wizard</field>
<field name='arch' type='xml'>
<form string="Borrow books">
<sheet>
<group>
<field name='borrower_id'/>
</group>
<group>
<field name='book_ids'/>
</group>
</sheet>
<footer>
<button string='Rent' type='object'
name='record_book_rents'
class='btn-primary'/>
<button string='Cancel' class='btn-default' special='cancel'/>
</footer>
</form>
</field>
</record>
  1. Create an action and a menu entry to display the wizard. Add the following declarations to the module menu file:
<act_window id="action_wizard_rent_books" 
name="Give on Rent"
res_model="library.rent.wizard"
view_mode="form" target="new" />
<menuitem id="menu_wizard_rent_books"
parent="library_base_menu"
action="action_wizard_rent_books"
sequence="20" />
..................Content has been hidden....................

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