nicoorfi
5/22/2019 - 8:58 AM

Odoo install function

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)