Menu

Working with XML data in Odoo

1.Create Records

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


field_data

                        

My first product
 
                        

2.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

                        

3.Delete Records

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



                        
Example:


                        

4.Calling methods from XML data

4.1.Calling method without parameters

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):
        ...
                        

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.

4.2.Calling method with parameters

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):
        ...
                

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

                
Share this post
OWL: The Future of Odoo Development