You can execute Model's method upon module's install or upgrade. Here's an example:
First, add the method that will do the initialization actions. For example:
"""For each Department and Role, which user is the responsible"""
_name = "crm.routing.users"
def _migrate_from_project_issue_profiling(self, cr, uid, ids=None, context=None):
"""Migrate from project.issue.profiling. since this module can completely replace it."""
if ids is not None:
raise NotImplementedError("Ids is just there by convention! Please don't use it.")
cr.execute("select exists(select * from information_schema.tables " "where table_name=project_issue_profiling)")
cr.execute(""" INSERT INTO crm_routing_users ( create_uid, create_date, write_date, write_uid, notes, user_id, section_id, department_id) SELECT create_uid, create_date, write_date, write_uid, notes, user_id, section_id, department_id FROM project_issue_profiling""")
_logger.info("Successful data copy from project.issue.profiling to crm.routing.users")
Next, declare the call in an XML data file:
<!-- Migration for "project_service_profiling". Can be skipped if that module is not in use. -->
<function model="crm.routing.users" name="_migrate_from_project_issue_profiling"/>
Finally, add the XML data file to tour _openerp_.py manifest, in the data (v7) section. If you want it to run only on first install, add noupdate="1" to the data tag.