Skip to content

[IMP] developer/reference/backend: dynamic dates #14105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions content/developer/reference/backend/orm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -950,26 +950,20 @@ A domain can be a simple condition ``(field_expr, operator, value)`` where:
``=?``
unset or equals to (returns true if ``value`` is either ``None`` or
``False``, otherwise behaves like ``=``)
``=like``
``=like`` (and ``not =like``)
matches ``field_expr`` against the ``value`` pattern. An underscore
``_`` in the pattern stands for (matches) any single character; a
percent sign ``%`` matches any string of zero or more characters.
``like``
``like`` (and ``not like``)
matches ``field_expr`` against the ``%value%`` pattern. Similar to
``=like`` but wraps ``value`` with '%' before matching
``not like``
doesn't match against the ``%value%`` pattern
``ilike``
``ilike`` (and ``not ilike``)
case insensitive ``like``
``not ilike``
case insensitive ``not like``
``=ilike``
``=ilike`` (and ``not =ilike``)
case insensitive ``=like``
``in``
``in`` (and ``not in``)
is equal to any of the items from ``value``, ``value`` should be a
collection of items
``not in``
is unequal to all of the items from ``value``
``child_of``
is a child (descendant) of a ``value`` record (value can be either
one item or a list of items).
Expand All @@ -984,17 +978,14 @@ A domain can be a simple condition ``(field_expr, operator, value)`` where:
Takes the semantics of the model into account (i.e following the
relationship field named by
:attr:`~odoo.models.Model._parent_name`).
``any``
``any`` (and ``not any``)
matches if any record in the relationship traversal through
``field_expr`` (:class:`~odoo.fields.Many2one`,
:class:`~odoo.fields.One2many`, or :class:`~odoo.fields.Many2many`)
satisfies the provided domain ``value``.
The ``field_expr`` should be a field name.
``not any``
matches if no record in the relationship traversal through
``field_expr`` (:class:`~odoo.fields.Many2one`,
:class:`~odoo.fields.One2many`, or :class:`~odoo.fields.Many2many`)
satisfies the provided domain ``value``.
``any!`` (and ``not any!``)
like ``any``, but bypasses access checks.

* ``value``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, you could move the explanation of dynamic values after this point here, before the example of domains usage.
Basically, what you introduce is a specific type of value, so it would make sense to show it here, and add a example to the existing examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Search domains" is already a level-3 heading, so is the "Dynamic time values". I thought of moving it there, but that's nested too deep and then I would anther header for examples and the continuation of the description.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it needed a dedicated heading TBH, but not worth blocking the merge, the whole ORM page should be rewritten anyway.

variable type, must be comparable (through ``operator``) to the named
Expand Down Expand Up @@ -1043,6 +1034,37 @@ and you can negate 1 using ``'!'`` (NOT).

.. automethod:: odoo.fields.Domain.validate

.. _reference/orm/dynamic_values:

Dynamic time values
~~~~~~~~~~~~~~~~~~~

In the context of search domains, for
:ref:`date and datetime fields <reference/fields/date>`, the value can be a
moment relative to *now* in the timezone of the user. A simple language is
provided to specify these dates. It is a space-separated string of terms.
The first term is optional and is "today" (at midnight) or "now".
Then, each term starts with "+" (add), "-" (subtract) or "=" (set), followed by
an integer and date unit or a lower-case weekday.

The date units are: "d" (days), "w" (weeks), "m" (months), "y" (years),
"H" (hours), "M" (minutes), "S" (seconds).
For weekdays, "+" and "-" mean next and previous weekday (unless we are already
in that weekday) and "=" means in current week starting on Monday.
When setting a date, the lower-units (hours, minutes and seconds) are set to 0.

.. example::

.. code-block:: python

Domain('some_date', '<', 'now') # now
Domain('some_date', '<', 'today') # today at midnight
Domain('some_date', '<', '-3d +1H') # now - 3 days + 1 hour
Domain('some_date', '<', '=3H') # today at 3:00:00
Domain('some_date', '<', '=5d') # 5th day of current month at midnight
Domain('some_date', '<', '=1m') # January, same day of month at midnight
Domain('some_date', '>=', '=monday -1w') # Monday of the previous week

Unlink
------

Expand Down
13 changes: 13 additions & 0 deletions content/developer/reference/backend/orm/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
Changelog
=========

Odoo version 19.0
=================

- Add support for ``GROUPING SETS`` for pivot views.
See `#194413 <https://github.com/odoo/odoo/pull/194413>`_.
- Adding support for dynamic dates in domains.
See `#216665 <https://github.com/odoo/odoo/pull/216665>`_.
- Deprecated `odoo.osv` in `#217708 <https://github.com/odoo/odoo/pull/217708>`_.
- Deprecated `record._cr`, `record._context`, `record._uid` in `#193636 <https://github.com/odoo/odoo/pull/193636>`_.


Odoo Online version 18.4
========================

- The `reinit` option is added to the CLI to reinitialize modules.
See `#206408 <https://github.com/odoo/odoo/pull/206408>`_.
- Possibility to write and combine custom domains for injecting arbitrary SQL.
See `#205208 <https://github.com/odoo/odoo/pull/205208>`_.

Odoo Online version 18.3
========================
Expand Down