|
| 1 | + |
| 2 | +======================== |
| 3 | +Upgrading customizations |
| 4 | +======================== |
| 5 | + |
| 6 | +The source code of custom modules maintained by third parties must be upgraded to be compatible with |
| 7 | +each new version of Odoo. This usually requires a static analysis of the code to find all the |
| 8 | +references of deprecated elements. However, it can also be done by installing the module and fixing |
| 9 | +the errors that occur during the installation. |
| 10 | + |
| 11 | +Information on the changes between versions can be found in the `release notes |
| 12 | +<https:/odoo.com/page/release-notes>`_ and the :ref:`upgrade report <upgrade/upgrade_report>`. |
| 13 | + |
| 14 | +.. seealso:: |
| 15 | + - :ref:`reference/views` |
| 16 | + - :ref:`reference/fields` |
| 17 | + - :ref:`reference/orm/models` |
| 18 | + |
| 19 | +.. _upgrade/comparing_customizations: |
| 20 | + |
| 21 | +Comparing customizations to the new version |
| 22 | +------------------------------------------- |
| 23 | + |
| 24 | +As many new features are added with each new version, some customizations may become obsolete when |
| 25 | +equivalent features become part of the standard version of Odoo. |
| 26 | + |
| 27 | +Therefore, exploring the new features and comparing them with your customizations is recommended. |
| 28 | +Removing unnecessary customizations reduces the work needed to maintain and upgrade your database. |
| 29 | + |
| 30 | +.. _upgrade/remove_customizations: |
| 31 | + |
| 32 | +Removing customizations |
| 33 | +----------------------- |
| 34 | + |
| 35 | +Customizations that have become redundant with the release of a new version of Odoo can be removed |
| 36 | +from your database with a :ref:`migration script <reference/upgrade/migration-scripts>` using the |
| 37 | +`uninstall_module` method from the `upgrade-util package <https://github.com/odoo/upgrade-util/blob/master/src/util/modules.py#L71>`__. |
| 38 | +This method renames the field and the column in the database but does not impact views, reports, |
| 39 | +filters, mail templates, automated and server actions, etc., that refer to those fields. Those |
| 40 | +references must be found and removed from the database, as well as in the same migration script. |
| 41 | + |
| 42 | +.. important:: |
| 43 | + :ref:`Testing your database <upgrade/test_your_db>` is crucial, especially when uninstalling a |
| 44 | + custom module. Any customized view, report, filter, mail template, automated and server actions, |
| 45 | + etc., referring to an uninstall field will prevent them from working correctly and might block |
| 46 | + your processes in certain situations. |
| 47 | + |
| 48 | +.. seealso:: |
| 49 | + :ref:`upgrade/comparing_customizations` |
| 50 | + |
| 51 | +Upgrading custom fields and their data |
| 52 | +-------------------------------------- |
| 53 | + |
| 54 | +Any custom field that has a reference to a modified standard field must be adapted to the new |
| 55 | +version of Odoo. To find the corresponding field in the new version, we recommend looking at its |
| 56 | +properties and finding a field with matching properties. You can also use the :ref:`upgrade report |
| 57 | +<upgrade/upgrade_report>` and the `release notes <https:/odoo.com/page/release-notes>`_ to support |
| 58 | +your search. |
| 59 | + |
| 60 | +.. example:: |
| 61 | + In Odoo 12 and before, the `account.invoice` model had a field named `refund_invoice_id` (`source |
| 62 | + code <https://github.com/odoo/odoo/blob/f7431b180834a73fe8d3aed290c275cc6f8dfa31/addons/account/models/account_invoice.py#L273>`_), |
| 63 | + which is absent on the `account.move` model after Odoo 13. This field was renamed to |
| 64 | + `reversed_entry_id` during the upgrade process. It is possible to find this information by |
| 65 | + searching for another Many2one field in `account.move` related to `account.move`, for example, |
| 66 | + `in Odoo 16 <https://github.com/odoo/odoo/blob/a0c1e2aa602ae46598a350ea6ae8d8b4a0c1c823/addons/account/models/account_move.py#L453>`_. |
| 67 | + |
| 68 | +.. note:: |
| 69 | + Renaming fields can be done with the `rename_field` method from `the upgrade-util package <https://github.com/odoo/upgrade-util/blob/220114f217f8643f5c28b681fe1a7e2c21449a03/src/util/fields.py#L336>`_. |
| 70 | + However, this only renames the field and column names. Therefore, custom views, reports, field |
| 71 | + relations, automated actions, etc., might still refer to the old field name and need to be |
| 72 | + updated in the migration script as well. |
| 73 | + |
| 74 | +Upgrading models and methods definitions |
| 75 | +---------------------------------------- |
| 76 | + |
| 77 | +Upgrading custom models consists mainly of ensuring that the module name and its inheritances |
| 78 | +are correct. The :ref:`upgrade report <upgrade/upgrade_report>` and the `release notes |
| 79 | +<https:/odoo.com/page/release-notes>`_ can contain helpful information concerning various standard |
| 80 | +models being changed or renamed. |
| 81 | + |
| 82 | +.. example:: |
| 83 | + The `sale.subscription` model has a `_prepare_invoice_data` method `in Odoo 15 <https://github.com/odoo/enterprise/blob/e07fd8650246d52c7289194dbe2b15b22c6b65e0/partner_commission/models/sale_subscription.py#L86-L92>`_ |
| 84 | + that has been moved and renamed to `_prepare_invoice` in the `sale.order` model `of Odoo 16 <https://github.com/odoo/enterprise/blob/b4182d863a3b925dc3fe082484c27dbb1f2a57d8/partner_commission/models/sale_order.py#L62-L68>`_. |
| 85 | + |
| 86 | +If a custom model overrides standard methods, you must ensure that their name still matches the |
| 87 | +name of the method they are overriding. In case of changes, you can search the method's source code |
| 88 | +in the new version to find its new name. If the method has been refactored, the source code might |
| 89 | +not exactly match, and a manual search is then required. |
| 90 | + |
| 91 | +Upgrading views definitions |
| 92 | +--------------------------- |
| 93 | + |
| 94 | +Views defined in Odoo have an external identifier corresponding to the `id` attribute of a view's |
| 95 | +`<record/>` tag, which can happen during a module update or when rendering it. |
| 96 | + |
| 97 | +Most of the time, the incompatibility of a custom view is expressed via an error when parsing the |
| 98 | +view, which can happen during the update of a module or when rendering it. |
| 99 | + |
| 100 | +Custom views for custom models only require upgrading if the custom model has been changed. In |
| 101 | +contrast, custom views inheriting from standard views can be impacted by changes in the standard |
| 102 | +views. In this case, the custom views' source code requires an upgrade to be compatible with the new |
| 103 | +version of its parent view. This can be done by retargetting the various Xpath expressions to match |
| 104 | +an equivalent element that might have been moved or renamed. |
0 commit comments