<openerp> <data> <!-- 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"/> </data></openerp>

EDIT:

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.

Are you sure there could be an init section in module manifest? Please check my comment on GEM's answer below. I think there is not init section and there is no difference between xml declaration using init_xml and update_xml attributes. At least in v7.0. Using noupdate="1" on data tag will run function tags only at module install.

Regarding .xml and .sql files, there is no difference between module attributes init_xml, update_xml and data. The file will always be updated/executed on any module installation or update. Check the load_module_graph() function in openerp/modules/loading.py

You can create a method init(self, cr) in your model and it will be called upon module installation or upgrade.

You can check for update or install mode by checking the the existence of data or structures that should have been created in initialization or you can just use common sql or replace mechanism to use the same sql for both states.

Most reports use this method to create required views. Check this example from addons/account/report/account_report:

I have just to create report by using sql query (the same with above). But I have the problem: If I execute the query by postgreSQL maestro, there are 600 records. By postgreSQL Maestro, I open the view there are also 600 records. But the tree view in Openerp V7 there are only 19 records. Anyone help me?

As long as we write less SQL sentences, the ORM can make more
optimizations for us in the future and the maintenance will be easier.

There
are cases where you have made strong changes to your models already
used in production and the ORM can't make the automatic inference of the
sql statements needed to give the database a logical state
corresponding to your new code (ex: fix your table structure, move data
between columns, calculate quickly default values for new not null
columns using sql expressions, etc..).If your case is one of
those data maintenance problems, you can use the migration scripts as
specified in the MigrationManager descriptions: http://bit.ly/1UqiO8h.This mechanism is used extensively inside openupgrade: http://bit.ly/1QDc40R You can find a lot of samples there.

In your case, just create a migration folder with a -pre or -post update script:

<moduledir> `-- migrations |-- 8.0 | |-- pre-migration.py

In the pre-migration.py script you can check the version and put both queries. The first two digits passed to the script is always the odoo version the others come from your module version ( __openerp__.py of your module)

You can install the module specifying one version 1.1 and then change
the module version to 1.2, 1.3, etc... in