diff --git a/docsource/development.rst b/docsource/development.rst index 16972978d40a..62f9e6dcba53 100644 --- a/docsource/development.rst +++ b/docsource/development.rst @@ -60,6 +60,7 @@ Learn from typical Use cases use_cases/xml_id_renaming use_cases/module_renaming use_cases/noupdate_xml_entry_changed + use_cases/format_value_changing use_cases/value_mapping use_cases/sql_constraint_deleted diff --git a/docsource/use_cases/format_value_changing.rst b/docsource/use_cases/format_value_changing.rst new file mode 100644 index 000000000000..b4c18d56f896 --- /dev/null +++ b/docsource/use_cases/format_value_changing.rst @@ -0,0 +1,133 @@ +Format Value Changing ++++++++++++++++++++++ + +Example +------- + +From version 14.0 to version 15.0, the field ``description`` of the model ``hr.job`` +is changed his type from ``fields.Text`` to ``fields.Html``. + +Source Code Differences +----------------------- + +Version 14.0 +"""""""""""" + +.. code-block:: python + + class HrJob(models.Model): + _name = "hr.job" + + description = fields.Text(string='Job Description') + +See `Full v14 Code Source `_. + + +Version 15.0 +"""""""""""" + +.. code-block:: python + + class HrJob(models.Model): + _name = "hr.job" + + description = fields.Html(string='Job Description') + + +See `Full v15 Code Source `_. + + +Analysis +-------- + +.. code-block:: text + + ... + ---Fields in module 'hr'--- + ... + hr / hr.job / description (text) : type is now 'html' ('text') + + +See `Full V15 Analysis File `_. + +Result without migration script / Expected Result +------------------------------------------------- + +V14 table ``hr_job`` +"""""""""""""""""""" + +.. csv-table:: + :header: "id", "name", "description" + + "50", "OpenUpgrade Expert", "the candidate must have read the documentation at this url :\n\nhttps://oca.github.io/OpenUpgrade" + + +V15 table ``hr_job`` (Without openupgrade) +"""""""""""""""""""""""""""""""""""""""""" + +.. csv-table:: + :header: "id", "name", "description" + + "50", "OpenUpgrade Expert", "

the candidate must have read the documentation at this url :

https://oca.github.io/OpenUpgrade/

" + +**Problem**: + +The data has not been converted in HTML. + +V15 table ``hr_job`` (With openupgrade) +""""""""""""""""""""""""""""""""""""""" + +.. csv-table:: + :header: "id", "name", "description" + + "50", "OpenUpgrade Expert", "

the candidate must have read the documentation at this url :

https://oca.github.io/OpenUpgrade/

" + +Contribution to OpenUpgrade +--------------------------- + +Update ``upgrade_analysis_work.txt`` file +""""""""""""""""""""""""""""""""""""""""" + +Add a comment after the line: + +.. code-block:: text + + hr / hr.job / description (text) : type is now 'html' ('text') + # DONE pre-migration: convert to html + + +See `Full v15 Work Analysis File `_. + +Write migration Script +"""""""""""""""""""""" + +in the ``pre-migration.py`` script add: + +.. code-block:: python + + from openupgradelib import openupgrade + + + @openupgrade.migrate() + def migrate(env, version): + openupgrade.convert_field_to_html(env.cr, "hr_job", "description", "description") + +See `Full V15 pre migration Script `_. + + +Notes +----- + +there are several other functions that handle field type changes: + +* **convert_field_to_html** : to transform a ``field.Date()`` into a ``field.Datetime()``, + with correct timezone management. + (otherwise, all datetimes will have a number of offset hours, + corresponding to the difference between the administrator's timezone and greenwitch's timezone + at the time of migration) + +**float_to_integer** : to transform a ``field.Float()`` into a ``field.Integer()``, + truncating the decimal value. + (If not done, the value will be rounded by odoo ORM) + +**m2o_to_x2m** : to transform a ``field.Many2one()`` into a ``field.Many2many()`` or ``field.One2many()``.