How to do it...

To create a category with some child categories, you need to perform the following steps:

  1. Create a method in the library.book.category model with the name create_dummy_category:
def create_categories(self):
......
  1. Inside the body of this method, prepare a dictionary of values for the fields of the first child category:
categ1 = {
'name': 'Child category 1',
'description': 'Description for child 1'
}
  1. Prepare a dictionary of values for the fields of the second category:
categ2 = {
'name': 'Child category 2',
'description': 'Description for child 2'
}
  1. Prepare a dictionary of values for the fields of the parent category:
parent_category_val = {
'name': 'Parent category',
'email': 'Description for parent category',
'child_ids': [
(0, 0, categ1),
(0, 0, categ2),
]
}
  1. Call the create() method to create the new records:
record = self.env['library.book.category'].create(parent_category_val) 
  1. Add a button in the <form> view to trigger the create_categories method from the user interface:
<button name="create_categories" string="Create Categories" type="object"/>
..................Content has been hidden....................

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