Menu

Working with XML data in Odoo

Create Records

For creating the record of model , create a tag and place the fields Like:


field_data

                        

My first product
 
                        

Modify Records

In some cases, we need to update the previously created records by other modules.

To do this, create the record with id (module_name.record_id) in your module like:


some_data

                        
Example:

My modified Product

                        

Delete Records

In case you want to delete the record , use tag along with id or search like:



                        
Example:


                        

Calling methods from XML data

Calling method without parameters

1- Create a method in model

from odoo import api, fields, models
class product(models.Model):
    _inherit = "product.product"
    @api.model
    def my_method_without_params(self):
        ...
                        

2- Call this method

In order to call this method, create a tag in your data xml file


                        
Example:

                        
Once module is installed this method(oe_method_without_params) will be called.

Calling method with parameters

1- Create a method in model

from odoo import api, fields, models
class product(models.Model):
    _inherit = "product.product"
    @api.model
    def my_method_with_params(self, param1, param2):
        ...
                

2- Call this method

In order to call this method, create a tag in your data xml file


    param1
    param2
    ....

                
Example:

    My value 1
    My value 1

                
Environment in Odoo