Skip to content

Migration to version 12.0

Eric Antones edited this page Apr 15, 2021 · 8 revisions

Based on https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-12.0

Before migrating

  • Announce on the corresponding GitHub issue with the name "Migration to version 12.0" which module(s) you want to migrate

Tasks to do in the migration

  • Bump module version to 12.0.1.0.0
  • Remove any possible migration script from previous version.
  • Add tests to increase code coverage.
  • If you handle dates and datetimes, you might need to adapt your code now that Odoo returns always native Python objects, so no more fields.Date/Datetime.from_string is needed. For converting old style date/datetime strings to Python object, use fields.Date.to_date and fields.Datetime.to_datetime methods.
  • If you overwrite create method (in a new model or in an inherited one), look if you can apply decorator @api.model_create_multi for batch mode creation. See https://www.youtube.com/watch?v=KhDg-t0F_T8 for more details.
  • If your model uses _parent_store = True, then you should remove parent_left and parent_right fields, and add a new one parent_path = fields.Char(index=True). For providing full support when migrating, a post-migration script should be done calling env['model_name']._parent_store_compute() for filling this new field.
  • All <label> elements in views must have a for="" attribute.
  • All <filter> elements in search views must have a name attribute.
  • All <button> elements in a tree view should have a string attribute for accessibility.
  • Convert your SASS styles to SCSS.
  • Related fields are now read only by default. If your code relies on the default contrary, you should add readonly=False in your field definition.
  • base module has reorganized all the model files to include everything inside models folder. If you import that files, you should change import path. You can automate most of these changes with these bash commands:
    find . -type f -name '*.py' | xargs sed -i 's/from odoo.addons.base.res/from odoo.addons.base.models/g'
    find . -type f -name '*.py' | xargs sed -i 's/from http://odoo.addons.base.ir/from  odoo.addons.base.models/g'
    
  • If you need to generate a PDF in tests, you have to pass the context key force_report_rendering=True for getting that instead of an HTML, as now the method qweb_render_pdf defaults to qweb_render_html on test environment.
  • On website modules, website_published field, that comes from website.published.mixin, turns to computed non stored, and the stored value is now is_published. You will need migration scripts for renaming the field.
  • Do the rest of the changes you need to do for making the module works on new version.

Howto

Technical method to migrate a module from "11.0" to "12.0" branch

  • $MODULE: the name of the module you want to migrate
  • $USER_ORG: your GitHub login or organization name

Full process

  • Fork the https://github.com/nuobit/odoo-addons repo from your GitHub account https://github.com/$USER_ORG

  • On a shell command:

    $ git clone https://github.com/$USER_ORG/odoo-addons -b 12.0
    $ git checkout -b 12.0-mig-$MODULE origin/12.0
    $ git format-patch --keep-subject --stdout origin/12.0..origin/11.0 -- $MODULE | git am -3 --keep
    $ pre-commit run -a  # to run black, isort and prettier (ignore pylint errors at this stage)
    $ git add -A
    $ git commit -m "[IMP] $MODULE: black, isort, prettier"  --no-verify  # it is important to do all formatting in one commit the first time
  • Adapt the module to the 12.0 version following tasks to do.

  • On a shell command, type this for uploading the content to GitHub:

    $ pre-commit run -a  # every message should be green (no errors allowed at this stage)
    $ git add --all
    $ git commit -m "[MIG] $MODULE: Migration to 12.0"
    $ git push origin 12.0-mig-$MODULE --set-upstream
  • Follow the link on the command line or check in https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork how to create the pull request.

Troubleshooting

Sometimes, when performing these operations, the process can hang due to conflicts on the patches being applied. One of the possible problems is because a patch removes entirely a file and git am is not able to resolve this. It ends with a message error: ...: patch does not apply.

If that's your case, you can add --ignore-whitespace at the end of the git am command for allowing the patch to be applied, although there will be still conflicts to be solved, but they will be doable through standard conflict resolution system. Starting from the previous situation, you will need to do:

git am --abort
git format-patch --keep-subject --stdout origin/12.0..origin/11.0 -- <module path> | git am -3 --keep --ignore-whitespace
# resolve conflicts (for example git rm <file>)
git add --all
git am --continue