Skip to content

Instantly share code, notes, and snippets.

@yelizariev
Last active March 17, 2017 05:37
Show Gist options
  • Save yelizariev/147f5db1a28a76ce707589be8b1af09b to your computer and use it in GitHub Desktop.
Save yelizariev/147f5db1a28a76ce707589be8b1af09b to your computer and use it in GitHub Desktop.
Helpers for migrating to new odoo api (10.0+). Obsolete. Check for latest version here: https://odoo-development.readthedocs.io/en/latest/migration/index.html
# IMPORTS
# replace osv, orm
find . -type f -name '*.py' | xargs sed -i 's/from openerp.osv import orm$/from odoo import models/g'
find . -type f -name '*.py' | xargs sed -i 's/from openerp.models.orm import Model$/from odoo.models import Model/g'
find . -type f -name '*.py' | xargs sed -i 's/osv.osv_memory/models.TransientModel/g'
find . -type f -name '*.py' | xargs sed -i 's/osv.osv/models.Model/g'
find . -type f -name '*.py' | xargs sed -i 's/osv.except_osv/UserError/g'
find . -type f -name '*.py' | xargs sed -i 's/osv\./models./g'
find . -type f -name '*.py' | xargs sed -i 's/\<orm\./models./g'
find . -type f -name '*.py' | xargs sed -i 's/\(import .*\), osv/\1, models/g'
find . -type f -name '*.py' | xargs sed -i 's/\(import .*\)osv, /\1models, /g'
find . -type f -name '*.py' | xargs sed -i 's/\(import .*\)osv/\1models/g'
find . -type f -name '*.py' | xargs sed -i 's/\(import .*\), orm/\1/g'
find . -type f -name '*.py' | xargs sed -i 's/\(import .*\)orm, /\1/g'
find . -type f -name '*.py' | xargs sed -i 's/^.*import orm$//g'
find . -type f -name '*.py' | xargs sed -i 's/openerp.osv/openerp/g'
# replace http import
find . -type f -name '*.py' | xargs sed -i 's/from openerp.addons.web import http/from odoo import http/g'
find . -type f -name '*.py' | xargs sed -i 's/openerp.addons.web.http/odoo.http/g'
# replace odoo
# fix importing. Otherwise you will get error:
# AttributeError: 'module' object has no attribute 'session_dir'
find . -type f -name '*.py' | xargs sed -i 's/openerp.tools.config/odoo.tools.config/g'
# FIELDS
# update fields
# (multiline: http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed/7697604#7697604 )
# delete _columns
find . -type f -name '*.py' | xargs perl -i -p0e 's/    _columns = {(.*?)\n    }/$1\n/gs'
# computed fields
find . -type f -name '*.py' | xargs sed -i 's/fields.function(\(.*\) \(["\x27][^,]*\)/fields.function(\1 string=\2/g'
find . -type f -name '*.py' | xargs sed -i 's/fields.function(\(.*\) multi=[^,)]*/fields.function(\1/g'
find . -type f -name '*.py' | xargs sed -i 's/fields.function(\([^,]*\)\(.*\)type=.\([2a-z]*\)["\x27]/fields.\3(compute="\1"\2/g'
find . -type f -name '*.py' | xargs sed -i 's/fields.many2one(\(.*\)obj=\([^,]*\)/fields.many2one(\2, \1/g'
find . -type f -name '*.py' | xargs sed -i 's/,[ ]*,/,/g'
find . -type f -name '*.py' | xargs sed -i 's/,[ ]*,/,/g'
find . -type f -name '*.py' | xargs sed -i 's/,[ ]*,/,/g'
# replace fields
find . -type f -name '*.py' | xargs perl -i -p0e 's/    _columns = {(.*?)    }/$1/gs'
find . -type f -name '*.py' | xargs sed -i 's/fields\.\(.\)/fields.\u\1/g'
find . -type f -name '*.py' | xargs sed -i 's/ [\x27"]\(.*\)[\x27"].*:.*\(fields.*\),$/\1 = \2/g'
# REFERENCES
# hr
find . -type f -name '*.xml' | xargs sed -i 's/menu_hr_configuration/menu_human_resources_configuration/g'
find . -type f -name '*.csv' -o -name '*.py' -o -name '*.xml' | xargs sed -i 's/base.group_hr/hr.group_hr/g'
# OTHER (it's recommended to check result manually or don't apply this part)
# pool -> env
find . -type f -name '*.py' | xargs sed -i 's/self.pool/self.env/g'
# remove cr, uid
find . -type f -name '*.py' | xargs sed -i 's/(cr, [^,]*, /(/g'
find . -type f -name '*.py' | xargs sed -i 's/, context=[^,)]*//g'
@kkoci
Copy link

kkoci commented Mar 17, 2017

Very cool one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment