Add the data file to your __openerp__ file
Create the data file with the `noupdate="1"` flag
This indicates the code should be run once, then never again
It will run upon installation, or if the module is already installed, then it will the next time the module is upgraded.
Define the function element in your data file to trigger the appropriate python method
You can see the documentation here for details, but the end result looks something like this:
__openerp__.py
````
{
...
'data': [
...
'data/data.xml',
...
],
...
}
````
#### /data/data.xml
````
<openerp>
<data noupdate="1">
<function model="res.country" name="method_name"/>
</data>
</openerp>
````
#### /models/country.py
```
from openerp import models
import logging
_logger = logging.getLogger(__name__)
class ResCountry(models.Model):
_inherit = 'res.country'
@api.model
def method_name(self):
for country in self.search([]):
_logger.error(country.name)
```