There's more...

With <function>, it is also possible to send parameters to the functions. Let's say you only want to increase the price of books in a particular category and you want to send that amount as a parameter.

For that, you need to create a method that accepts the category as a parameter, as follows:

    @api.model
def update_book_price(self, category, amount_to_increase):
category_books = self.search([('category_id', '=', category.id)])
for book in category_books:
book.cost_price += amount_to_increase

To pass the category and amount as a parameter, you need to use the eval attribute, as follows:

<function model="library.book" 
name="update_book_price"
eval="(ref('category_xml_id'), 20)"/>

When you install the module, it will increase the price of the books of the given category by $20.

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

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