123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import logging
- logger = logging.getLogger('upgrade')
- logger.setLevel(logging.DEBUG)
- xmlid_renames = [
- ('document_page_quality_manual.wiki_group_quality_manual',
- 'mgmtsystem_manuals.manuals'),
- ]
- def logged_query(cr, query, args=None):
- """
- Logs query and affected rows at level DEBUG
- """
- if args is None:
- args = []
- cr.execute(query, args)
- logger.debug('Running %s', query % tuple(args))
- logger.debug('%s rows affected', cr.rowcount)
- return cr.rowcount
- def rename_xmlids(cr, xmlids_spec):
- """
- Rename XML IDs. Typically called in the pre script.
- One usage example is when an ID changes module. In OpenERP 6 for example,
- a number of res_groups IDs moved to module base from other modules (
- although they were still being defined in their respective module).
- """
- for (old, new) in xmlids_spec:
- if not old.split('.') or not new.split('.'):
- logger.error(
- 'Cannot rename XMLID %s to %s: need the module '
- 'reference to be specified in the IDs' % (old, new))
- else:
- query = ("UPDATE ir_model_data SET module = %s, name = %s "
- "WHERE module = %s and name = %s")
- logged_query(cr, query, tuple(new.split('.') + old.split('.')))
- def migrate(cr, version):
- if version is None:
- return
- rename_xmlids(cr, xmlid_renames)
|