How to do it...

In order to add the post_init_hook, follow these steps:

  1. Register the hook in the __manifest__.py file with the post_init_hook key:
...
'post_init_hook': 'add_book_hook',
...
  1. Add the add_book_hook() method in the __init__.py file:
from odoo import api, fields, SUPERUSER_ID

def add_book_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
book_data1 = {'name': 'Book 1', 'date_release': fields.Date.today()}
book_data2 = {'name': 'Book 2', 'date_release': fields.Date.today()}
env['library.book'].create([book_data1, book_data2])
..................Content has been hidden....................

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