How to do it...

To add a wizard for recording borrowed books to the addon module, you need to perform the following steps:

  1. Add a new transient model to the module with the following definition:
class LibraryLoanWizard(models.TransientModel): 
    _name = 'library.loan.wizard' 
    member_id = fields.Many2one('library.member', string='Member') 
    book_ids = fields.Many2many('library.book', string='Books')
  1. Add the callback method performing the action on the transient model. Add the following code to the LibraryLoanWizard class:
    @api.multi 
    def record_loans(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})
  1. Create a form view for the model. Add the following view definition to the module views:
 <record id='library_loan_wizard_form' model='ir.ui.view'> 
  <field name='name'>library loan wizard form view</field> 
  <field name='model'>library.loan.wizard</field> 
  <field name='arch' type='xml'> 
    <form string="Borrow books"> 
      <sheet> 
        <group> 
          <field name='member_id'/> 
        </group> 
        <group> 
          <field name='book_ids'/> 
        </group> 
      </sheet> 
      <footer> 
        <button name='record_loans' 
                string='OK' 
                class='btn-primary' 
                type='object'/>
        <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_loan_books" 
            name="Record Loans" 
            res_model="library.loan.wizard" 
            view_mode="form" 
            target="new" 
            /> 
<menuitem id="menu_wizard_loan_books" 
          parent="library_book_menu" 
          action="action_wizard_loan_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
18.188.216.249