invoking-functions-from-xml-files-in-odoo.png
Blogger_637079905001142766.png
By: Mehjabin Farsana P

Invoking Functions from XML Files in Odoo

Technical

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.


invoking-functions-from-xml-files-in-odoo-cybrosys


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


invoking-functions-from-xml-files-in-odoo-cybrosys


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


invoking-functions-from-xml-files-in-odoo-cybrosys


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.


invoking-functions-from-xml-files-in-odoo-cybrosys


Now your data.xml file will look like as follows


invoking-functions-from-xml-files-in-odoo-cybrosys


Once you have installed this module these functions will be called.



cybrosys youtube

Comments

0


Leave a comment

 
Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message