Odoo views are dynamically created from XML codes. We can create all types of data using XML files. But while coming to the real-time business environment, most of the time it may be difficult to generate data. For example, in some cases, you may need to modify records when the user installs a module in production.
This blog explains how to call methods while installing your modules using the tag <function> in the XML files. Most of the time you need to perform some operations just after the installation of your module. So, in this case, you can use the tags <function> and invoke the function or method in the XML files to perform these operations.
So, let us see how it can be done.
In order to invoke a function from XML files in odoo, first of all, you have to create an XML demo data file, something like data.xml.
In this, the parameter noupdate is used to indicate that, at the time of the update of a module, reimporting the values in the XML files should be carried out. For example, If noupdate=”1” is used in a file with demo data then, the demo record is not imported back if it is deleted, right before updating the module. The record is reimported if it is not present in the database, with noupdate=”0”. Thus, this noupdate parameter ensures that this XML is not executed repeatedly during the update of the module. Also, you have to include this data file in your __manifest__.py file of the module.
A function of this method can be invoked as follows:
1. Invoking Function without parameters
First of all, we have to create a function in a model as follows
So now in order to invoke this created function, we use the <function> tag in the data file.
2. Invoking Function with parameters
Create a function with parameters as follows
Now for calling these functions you can use the <function/> tag in the XML files as given below and can pass the parameters using <value/> tag.
Now your data.xml file will look like as follows
Once you have installed this module these functions will be called.