Skip to content

Commit d9b169f

Browse files
committed
[FIX] Upgrade documentation: Code review changes
1 parent e513911 commit d9b169f

File tree

4 files changed

+75
-74
lines changed

4 files changed

+75
-74
lines changed

content/developer/howtos/upgrade_custom_db.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Upgrade a customized database
88
:titlesonly:
99
:glob:
1010

11-
upgrade/*
11+
upgrade_custom_db/*
1212

1313
Upgrading to a new version of Odoo can be challenging, especially if the database you work on
1414
contains custom modules. This page intent is to explain the technical process of upgrading a
@@ -195,9 +195,10 @@ To make sure the custom code is working flawlessly in the new version, follow th
195195
Migrate the data
196196
----------------
197197

198-
During the upgrade of the custom modules, you might have to use :doc:`upgrade/upgrade_scripts` to
199-
reflect changes from the source code to their corresponding data. Together with the Upgrade
200-
scripts, you can also make use of the :doc:`upgrade/upgrade_util` and its helper functions.
198+
During the upgrade of the custom modules, you might have to use
199+
:doc:`upgrade scripts <upgrade_custom_db/upgrade_scripts>` to reflect changes from the source code
200+
to their corresponding data. Together with the upgrade scripts, you can also make use of the
201+
:doc:`../reference/upgrade_util` and its helper functions.
201202

202203
- Any technical data that was renamed during the upgrade of the custom code (models, fields,
203204
external identifiers) should be renamed using upgrade scripts to avoid data loss during the
@@ -227,7 +228,7 @@ scripts, you can also make use of the :doc:`upgrade/upgrade_util` and its helper
227228
"""
228229
)
229230
230-
Check the documentation for more information on :doc:`upgrade/upgrade_scripts`.
231+
Check the documentation for more information on :doc:`upgrade_custom_db/upgrade_scripts`.
231232

232233
Upgrade scripts can also be used to:
233234

content/developer/howtos/upgrade/upgrade_scripts.rst renamed to content/developer/howtos/upgrade_custom_db/upgrade_scripts.rst

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Upgrade scripts
55
An upgrade script is a Python file containing a function called :meth:`migrate`, which the upgrade
66
process invokes during the update of a module.
77

8-
.. method:: migrate(cr, version):
8+
.. method:: migrate(cr, version)
99

1010
:param cr: current database cursor
1111
:type cr: :class:`~odoo.sql_db.Cursor`
1212
:param str version: installed version of the module
1313

1414
Typically, this function executes one or multiple SQL queries and can also access Odoo's ORM, as
15-
well as the :doc:`../upgrade/upgrade_util`.
15+
well as the :doc:`../../reference/upgrade_util`.
1616

1717
As described in :ref:`upgrade_custom/upgraded_database/migrate_data`, you might have to use upgrade
1818
scripts to reflect changes from the source code to their corresponding data.
@@ -38,15 +38,18 @@ Follow this steps to create the directory's structure and the Python file:
3838
Upgrade scripts are only executed when the module is being updated. Therefore, the
3939
:file:`minor_version` set in the directory needs to be higher than the module's installed
4040
version and equal or lower to the updated version of the module.
41-
For example, in an `Odoo 16` database, with a custom module installed in version `1.1`, and an
42-
updated module version equal to `1.2`; the version directory should be `16.0.1.2`.
43-
#. Create a :file:`Python file` inside the :file:`<version>` directory named according to the
41+
42+
.. example::
43+
44+
In an Odoo 16 database, with a custom module installed in version `1.1` that has been
45+
updated to version `1.2`; the version directory should be `16.0.1.2`.
46+
47+
#. Create a Python file inside the :file:`<version>` directory named according to the
4448
:ref:`Phase <upgrade/upgrade-scripts/phases>` on which it needs to be executed. It should
4549
follow the template `{pre|post|end}-*.py`. The file name will determine the order in which it
4650
is executed for that module, version and phase.
47-
#. Create a :file:`migrate` function in the Python file that receives as parameters
48-
:file:`(cr, version)`.
49-
#. Add the logic needed inside the Python file.
51+
#. Create a :meth:`migrate` function in the Python file.
52+
#. Add the logic needed inside the function.
5053

5154
.. example::
5255

@@ -91,8 +94,9 @@ Follow this steps to create the directory's structure and the Python file:
9194
9295
_logger.info("Updated %s partners", len(partners))
9396
94-
Note that in the second example, the script takes advantage of the :doc:`../upgrade/upgrade_util`
95-
to access the ORM. Check the documentation to find out more about this library.
97+
Note that in the second example, the script takes advantage of the
98+
:doc:`../../reference/upgrade_util` to access the ORM. Check the documentation to find out
99+
more about this library.
96100

97101

98102
Running and testing upgrade scripts
@@ -144,14 +148,14 @@ The upgrade process consists of three phases for each version of each module:
144148
Upgrade scripts are grouped according to the first part of their filenames into the corresponding
145149
phase. Within each phase, the files are executed according to their lexical order.
146150

147-
.. note::
151+
.. tip::
148152
If you are unsure which phase to use, use the end-phase.
149153

150-
.. spoiler:: Execution order of example scripts for one module in one version
154+
.. admonition:: Execution order of example scripts for one module in one version
151155

152-
- :file:`pre-10-do_something.py`
153-
- :file:`pre-20-something_else.py`
154-
- :file:`post-do_something.py`
155-
- :file:`post-something.py`
156-
- :file:`end-01-migrate.py`
157-
- :file:`end-migrate.py`
156+
#. :file:`pre-10-do_something.py`
157+
#. :file:`pre-20-something_else.py`
158+
#. :file:`post-do_something.py`
159+
#. :file:`post-something.py`
160+
#. :file:`end-01-migrate.py`
161+
#. :file:`end-migrate.py`

content/developer/reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Reference
1212
reference/user_interface
1313
reference/standard_modules
1414
reference/cli
15+
reference/upgrade_util
1516
reference/external_api
1617
reference/extract_api

content/developer/howtos/upgrade/upgrade_util.rst renamed to content/developer/reference/upgrade_util.rst

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The `Upgrade Util package <https://github.com/odoo/upgrade-util/>`_ is a library
66
helper functions to facilitate the writing of upgrade scripts. This package, used by Odoo for the
77
upgrade scripts of standard modules, provides reliability and helps speed up the upgrade process:
88

9-
- The helper functions make sure the data is consitent in the database.
9+
- The helper functions help make sure the data is consistent in the database.
1010
- It takes care of indirect references of the updated records.
1111
- Allows calling functions and avoid writing code, saving time and reducing development risks.
1212
- Helpers allow to focus on what is important for the upgrade and not think of details.
@@ -37,7 +37,7 @@ Using the Util package
3737

3838
Once installed, the following packages are available for the upgrade scripts:
3939

40-
- :mod:`odoo.upgrade.util`: the helper themself.
40+
- :mod:`odoo.upgrade.util`: the helper itself.
4141
- :mod:`odoo.upgrade.testing`: base TestCase classes.
4242

4343
To use it in upgrade scripts, simply import it:
@@ -62,47 +62,45 @@ helper functions.
6262

6363
.. note::
6464

65-
All util functions receive :attr:`cr` as a parameter. This refers to the database cursor. Use the
66-
one received as a parameter in the :doc:`upgrade_scripts`.
65+
All util functions receive :attr:`cr` as a parameter. This refers to the database cursor. Pass
66+
the one received as a parameter in the :doc:`upgrade_scripts`.
6767

6868
Fields
6969
------
7070

7171
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/fields.py#L91>`_
72-
.. method:: remove_field(cr, model, fieldname[, cascade=False][, drop_column=True][, skip_inherit=()])
72+
.. method:: remove_field(cr, model, fieldname, cascade=False, drop_column=True, skip_inherit=())
7373

74-
Remove a field and its references from the database
74+
Remove a field and its references from the database.
7575

7676
:param str model: model name of the field to remove
7777
:param str fieldname: name of the field to remove
78-
:param bool cascade: if ``True``, removes the field's column and inheritance in ``CASCADE``
79-
(default: ``False``)
80-
:param bool drop_column: if ``True``, drops the field's column (default: ``True``)
78+
:param bool cascade: whether the field's column and inheritance are removed in ``CASCADE``
79+
:param bool drop_column: whether the field's column is dropped
8180
:param list(str) or str skip_inherit: list of models whose field's inheritance is skipped.
8281
Use ``"*"`` to skip all inheritances
8382

8483
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/fields.py#L362>`_
85-
.. method:: rename_field(cr, model, old, new[, update_references=True][, domain_adapter=None][, skip_inherit=()])
84+
.. method:: rename_field(cr, model, old, new, update_references=True, domain_adapter=None, skip_inherit=())
8685

87-
Rename a field and its references from ``old`` to ``new``
86+
Rename a field and its references from ``old`` to ``new``.
8887

8988
:param str model: model name of the field to rename
9089
:param str old: current name od the field to rename
9190
:param str new: new name od the field to rename
92-
:param bool update_references: if ``True``, Replace all references of field ``old`` to ``new``
91+
:param bool update_references: whether all references of field ``old`` to ``new`` are replaced
9392
in: ``ir_filters``, ``ir_exports_line``, ``ir_act_server``, ``mail_alias``,
9493
``ir_ui_view_custom (dashboard)``, ``domains (using "domain_adapter")``, ``related fields``
95-
(default: ``True``)
9694
:param function domain_adapter: function that takes three arguments and returns a domain that
9795
substitutes the original leaf: ``(leaf: Tuple[str,str,Any], in_or: bool, negated: bool)`` ->
9896
``List[Union[str,Tuple[str,str,Any]]]``
9997
:param list(str) or str skip_inherit: list of models whose field's inheritance is skipped.
10098
Use ``"*"`` to skip all inheritances
10199

102100
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/fields.py#L337>`_
103-
.. method:: move_field_to_module(cr, model, fieldname, old_module, new_module[, skip_inherit=()])
101+
.. method:: move_field_to_module(cr, model, fieldname, old_module, new_module, skip_inherit=())
104102

105-
Move a field's reference in ``ir_model_data`` table from ``old_module`` to ``new_module``
103+
Move a field's reference in ``ir_model_data`` table from ``old_module`` to ``new_module``.
106104

107105
:param str model: model name of the field to move
108106
:param str fieldname: name of the field to move
@@ -115,26 +113,26 @@ Models
115113
------
116114

117115
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/models.py#L53>`_
118-
.. method:: remove_model(cr, model[, drop_table=True][, ignore_m2m=()])
116+
.. method:: remove_model(cr, model, drop_table=True, ignore_m2m=())
119117

120-
Remove a model and its references from the database
118+
Remove a model and its references from the database.
121119

122120
:param str model: name of the model to remove
123-
:param bool drop_table: if ``True``, drops the model's table (default: ``True``)
121+
:param bool drop_table: whether the model's table is dropped
124122
:param list(str) or str ignore_m2m: list of m2m tables ignored to remove. Use ``"*"`` to ignore
125123
all m2m tables
126124

127125
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/models.py#L203>`_
128-
.. method:: rename_model(cr, old, new[, rename_table=True])
126+
.. method:: rename_model(cr, old, new, rename_table=True)
129127

130-
Rename a model and its references from ``old`` to ``new``
128+
Rename a model and its references from ``old`` to ``new``.
131129

132130
:param str old: current name of the model to rename
133131
:param str new: new name of the model to rename
134-
:param bool rename_table: if ``True``, renames the model's table (default: ``True``)
132+
:param bool rename_table: whether the model's table is renamed
135133

136134
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/models.py#L323>`_
137-
.. method:: merge_model(cr, source, target[, drop_table=True][, fields_mapping=None][, ignore_m2m=()])
135+
.. method:: merge_model(cr, source, target, drop_table=True, fields_mapping=None, ignore_m2m=())
138136

139137
Merge the references from ``source`` model into ``target`` model and removes ``source`` model and
140138
its references. By default, only the fields with the same name in both models are mapped.
@@ -144,7 +142,7 @@ Models
144142

145143
:param str source: name of the source model of the merge
146144
:param str target: name of the destination model of the merge
147-
:param bool drop_table: if ``True``, drops the source model's table (default: ``True``)
145+
:param bool drop_table: whether the source model's table is dropped
148146
:param dict fields_mapping: Dictionary ``{"source_model_field_1": "target_model_field_1", ...}``
149147
mapping fields with different names on both models
150148
:param list(str) or str ignore_m2m: list of m2m tables ignored to remove from source model.
@@ -155,92 +153,91 @@ Modules
155153
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/modules.py#L218>`_
156154
.. method:: remove_module(cr, module)
157155

158-
Uninstall and remove a module and its references from the database
156+
Uninstall and remove a module and its references from the database.
159157

160158
:param str module: name of the module to remove
161159

162160
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/modules.py#L263>`_
163161
.. method:: rename_module(cr, old, new)
164162

165-
Rename a module and its references from ``old`` to ``new``
163+
Rename a module and its references from ``old`` to ``new``.
166164

167165
:param str old: current name of the module to rename
168166
:param str new: new name of the module to rename
169167

170168
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/modules.py#L323>`_
171169
.. method:: merge_module(cr, old, into, update_dependers=True)
172170

173-
Move all references of module ``old`` into module ``into``
171+
Move all references of module ``old`` into module ``into``.
174172

175173
:param str old: name of the source module of the merge
176174
:param str into: ame of the destination module of the merge
177-
:param bool update_dependers: if ``True``, updates the dependencies of modules that depends on
178-
``old`` (default: ``True``)
175+
:param bool update_dependers: whether the dependencies of modules that depends on ``old`` are
176+
updated
179177

180178
ORM
181179
---
182180

183181
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/orm.py#L43>`_
184182
.. method:: env(cr)
185183

186-
Create a new environment from the cursor
184+
Create a new environment from the cursor.
187185

188186
.. warning::
189187
This function does NOT empty the cache maintained on the cursor for superuser with an empty
190-
environment. A call to invalidate_cache will most probably be necessary every time you
188+
environment. A call to `invalidate_cache` will most probably be necessary every time you
191189
directly modify something in database.
192190

193191
:return: The new environment
194192
:rtype: :class:`~odoo.api.Environment`
195193

196194
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/orm.py#L218>`_
197-
.. method:: recompute_fields(cr, model, fields[, ids=None][, logger=_logger][, chunk_size=256][, strategy="auto"])
195+
.. method:: recompute_fields(cr, model, fields, ids=None, logger=_logger, chunk_size=256, strategy="auto")
198196

199-
Recompute field values
197+
Recompute field values.
200198

201199
:param str model: model name of the field(s) to recompute
202200
:param list(str) fields: list of field names to recompute
203201
:param list(int) ids: list of record IDs to recompute
204202
:param logger: Logger used to print the progress of the function
205-
:type: logger: :class:`logging.Logger`
203+
:type logger: :class:`logging.Logger`
206204
:param int chunk_size: size of the chunk used to split the records for better processing
207-
(default: ``256``)
208-
:param str strategy: strategy used to process the recomputation (default: ``auto``):
205+
:param str strategy: strategy used to process the recomputation:
209206

210207
- ``flush``: Flush the recomputation when it's finished
211208
- ``commit``: Commit the recomputation when it's finished
212209
- ``auto``: The function chooses the best alternative for the recomputation based on the
213-
number of records to recompute and the fields traceability.
210+
number of records to recompute and the fields traceability
214211

215212
Records
216213
-------
217214

218215
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/records.py#L612>`_
219216
.. method:: ref(cr, xmlid)
220217

221-
Return the id corresponding to the given :term:`xml_id <external identifier>`
218+
Return the id corresponding to the given :term:`xml_id <external identifier>`.
222219

223220
:param str xml_id: Record xml_id, under the format ``<module.id>``
224-
:return: Found record id or None
225-
:rtype: int
221+
:return: Found record id, if any
222+
:rtype: int or `None`
226223

227224
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/records.py#L281>`_
228225
.. method:: remove_record(cr, name)
229226

230-
Remove a record and its references corresponding to the given :term:`xml_id <external identifier>`
227+
Remove a record and its references corresponding to the given
228+
:term:`xml_id <external identifier>`.
231229

232230
:param str name: record xml_id, under the format ``<module.id>``
233231

234232
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/records.py#L548>`_
235-
.. method:: rename_xmlid(cr, old, new[, noupdate=None][, on_collision="fail"])
233+
.. method:: rename_xmlid(cr, old, new, noupdate=None, on_collision="fail")
236234

237-
Rename the :term:`external Identifier` of a record
235+
Rename the :term:`external Identifier` of a record.
238236

239237
:param str old: current xml_id of the record, under the format ``<module.id>``
240238
:param str new: new xml_id of the record, under the format ``<module.id>``
241-
:param bool noupdate: value to set on the ir_model_data record ``noupdate`` field (default:
242-
``None``)
243-
:param str on_collision: action to take if the new xml_id already exists (default: ``fail``)
239+
:param bool noupdate: value to set on the ir_model_data record ``noupdate`` field
240+
:param str on_collision: action to take if the new xml_id already exists
244241

245242
- ``fail``: raise ``MigrationError`` and prevent renaming
246243
- ``merge``: renames the external Identifier and removes the old one
@@ -267,17 +264,15 @@ Records
267264
:rtype: str
268265

269266
.. `[source] <https://github.com/odoo/upgrade-util/blob/master/src/util/records.py#L720>`_
270-
.. method:: update_record_from_xml(cr, xmlid[, reset_write_metadata=True][, force_create=True][, from_module=None][, reset_translations=()])
267+
.. method:: update_record_from_xml(cr, xmlid, reset_write_metadata=True, force_create=True, from_module=None, reset_translations=())
271268

272269
Update a record based on its definition in the :doc:`/developer/reference/backend/data`.
273270

274271
Useful to update ``noupdate`` records, in order to reset them for the upgraded version.
275272

276273
:param str xmlid: record xml_id, under the format ``<module.id>``
277-
:param bool reset_write_metadata: if ``True``, the metadata before the record update is kept
278-
(default: ``True``)
279-
:param bool force_create: if ``True``, creates the record if it does not exist. (default:
280-
``True``)
274+
:param bool reset_write_metadata: whether the metadata before the record update is kept
275+
:param bool force_create: whether the record is created if it does not exist
281276
:param str from_module: name of the module from which to update the record. Useful when the
282277
record is rewritten in another module.
283-
:param set of str reset_translations: set of field names whose translations get reset.
278+
:param set of str reset_translations: set of field names whose translations get reset

0 commit comments

Comments
 (0)