Skip to content

Commit 897bd3a

Browse files
committed
[FIX] util/fields: fix documenation
* Correct references to `adapt_domains` * Explain domain adapters better * Typos and wording improvements closes #89 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 688b6a4 commit 897bd3a

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/util/domains.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def clean_term(term):
307307

308308
def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adapt=False):
309309
"""
310-
Replace `old` by `new` in all domains of `model` and all its inheriting models using an `adapter` callback.
310+
Replace `old` by `new` in domains using `model` and inheriting models.
311311
312312
`adapter` is a callback function to adapt leaves. Adapter functions must take three
313313
arguments and return a `domain <reference/orm/domains>`_ that substitutes the original
@@ -330,12 +330,16 @@ def adapter(leaf, in_or, negated):
330330
return [(left, "=", ko)]
331331
return [leaf]
332332
333-
`adapter` is called only on leafs that use the `old` field of `model` as **last** part
334-
of the `left` part of leaves, unless `force_adapt` is `True`. The domains returned by
335-
an adapter do not need to have the `old` field replaced by `new` in the `left` part of
336-
the input leaf. The replace will be done anyway to the whole domain returned by the
337-
adapter. The purpose of the `adapter` is to modify the operator and the `right` part
338-
of the input leaf.
333+
`adapter` is called only on leaves that use the `old` field of `model` as **last**
334+
part of the `left` part of leaves, unless `force_adapt` is `True`. In the latter case
335+
the adapter is called if the field appears anywhere in the path, useful for relational
336+
fields only.
337+
338+
The domains returned by an adapter do not need to have the `old` field replaced by
339+
`new` in the `left` part of the input leaf. The replace will be done anyway to the
340+
whole domain returned by the adapter. The usual purpose of the `adapter` is to modify
341+
the operator and the `right` part of the input leaf. When `adapter` is not set only
342+
the replacement takes place.
339343
340344
.. example::
341345
When replacing `"field1"` by `"field2"`, the following happens:
@@ -355,9 +359,9 @@ def adapter(leaf, in_or, negated):
355359
:param str new: name of the field that should replace `old`
356360
:param function adapter: adapter for leaves
357361
:param list(str) skip_inherit: list of inheriting model names to don't adapt (skip)
358-
:param bool force_adapt: when `True, run the `adapter` on all leaves having `new` in
359-
`left` part of the leaf (path), useful when deleting a
360-
field (in which case `new` is ignored).
362+
:param bool force_adapt: when `True`, run the `adapter` on all leaves having `new` in
363+
`left` part of the leaf (path), useful when deleting a field
364+
(in which case `new` is ignored).
361365
"""
362366
_validate_model(model)
363367
target_model = model

src/util/fields.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,21 +430,25 @@ def move_field_to_module(cr, model, fieldname, old_module, new_module, skip_inhe
430430

431431
def rename_field(cr, model, old, new, update_references=True, domain_adapter=None, skip_inherit=()):
432432
"""
433-
Rename a field and its references from `old` to `new` on the given `model` and all inheriting models, unless exceptions are specified in `skip_inherit`.
433+
Rename a field and its references from `old` to `new` on the given `model`.
434+
435+
The field is updated in all inheriting models, except for models specified in
436+
`skip_inherit`.
434437
435438
This functions also updates references, indirect or direct ones, including filters,
436439
server actions, related fields, emails, dashboards, domains, and many more. See
437-
:func:`update_field_usage`
440+
:func:`~odoo.upgrade.util.fields.update_field_usage`
438441
439442
For the update of domains a special adapter function can be used. The default adapter
440-
just replaces `old` by `new` in each domain leaf. Refer to :func:`adapt_domains` for
441-
information about domain adapters.
443+
just replaces `old` by `new` in each domain leaf. Refer to
444+
:func:`~odoo.upgrade.util.domains.adapt_domains` for information about domain adapters.
442445
443446
:param str model: model name of the field to rename
444447
:param str old: current name of the field to rename
445448
:param str new: new name of the field to rename
446449
:param bool update_references: whether to update all references
447-
:param function domain_adapter: adapter to use for domains, see :func:`adapt_domains`
450+
:param function domain_adapter: adapter to use for domains, see
451+
:func:`~odoo.upgrade.util.domains.adapt_domains`
448452
:param list(str) or str skip_inherit: models to skip when renaming the field in
449453
inheriting models, use `"*"` to skip all
450454
"""
@@ -932,13 +936,14 @@ def update_field_usage(cr, model, old, new, domain_adapter=None, skip_inherit=()
932936
933937
This function can be used to replace the usage of a field by another. Domains are
934938
updated using the `domain_adapter`. By default the domain adapter just replaces `old`
935-
by `new` in domain leaves. See :func:`adapt_domains` for more information about domain
936-
adapters.
939+
by `new` in domain leaves. See :func:`~odoo.upgrade.util.domains.adapt_domains` for
940+
more information about domain adapters.
937941
938942
:param str model: model name of the field
939943
:param str old: source name of the field to replace
940944
:param str new: target name of the field to set
941-
:param function domain_adapter: adapter to use for domains, see :func:`adapt_domains`
945+
:param function domain_adapter: adapter to use for domains, see
946+
:func:`~odoo.upgrade.util.domains.adapt_domains`
942947
:param list(str) or str skip_inherit: models to skip when renaming the field in
943948
inheriting models, use `"*"` to skip all
944949
"""

0 commit comments

Comments
 (0)