Invoke Functions from XML Files in Odoo 17

January 4, 2024

The open-source business application package Odoo offers a strong foundation for functionality extensions and customization. Invoking functions from XML files is a popular customization that lets developers do particular operations inside their Odoo modules. We’ll look at how to call methods from XML files in Odoo 17 in this blog post.

1. Making an argumentless call to a function.

2. Making an argument-based function call.

I will demonstrate in this blog how to use XML in a unique way to create a new partner.

1. Making an argumentless call to a function

You can call a function inside a model in this manner without passing any parameters. Here is the XML syntax to accomplish this.

<?xml version="1.0" encoding="utf-8"?>
		<function model="res.partner" name="_create_new_partner"/>

There’s a <function> element inside the <data> element. This element represents an Odoo function call. It specifically refers to the _create_new_partner method in this case. The model attribute identifies the Odoo model—in this example, res. partner—where the function would be applied.

This function will perform a specific action associated with adding a new partner or contact record to the Odoo database.

Let’s now investigate
Let’s now investigate this function’s coding by going into the Python file.

2. Making an argument-based function call

By giving parameters to a model, we can make it activate. This has the following XML syntax:

   <function model="res.partner" name="func_with_params">

There’s a “value” tag inside the “function” element with the string “John.” This particular value is supplied to the func_with_params function as an argument. Let’s now investigate this function’s coding by going into the Python file.

class ResPartner(models.Model):
   _inherit = "res.partner"
   def func_with_params(self, name):

One name and a parameter are required for the func_with_params method. The res. partner database is expanded by adding new items using the create function. The record is then generated using the name that was specified as an input.

In this blog post, we looked at how to call methods from XML files in Odoo 17. Knowing this customization method increases the versatility of your Odoo modules, whether you’re giving specific information or calling functions without parameters. Use the power of XML as you start your Odoo development journey to customize the system to your specific company needs.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *