Skip to content

Commit 1fd65c3

Browse files
committed
[IMP] developer/reference/backend: dynamic dates
Examples of how to specify dynamic dates in domains.
1 parent 7e22325 commit 1fd65c3

File tree

1 file changed

+31
-0
lines changed
  • content/developer/reference/backend

1 file changed

+31
-0
lines changed

content/developer/reference/backend/orm.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,37 @@ and you can negate 1 using ``'!'`` (NOT).
10341034

10351035
.. automethod:: odoo.fields.Domain.validate
10361036

1037+
.. _reference/orm/dynamic_values:
1038+
1039+
Dynamic time values
1040+
~~~~~~~~~~~~~~~~~~~
1041+
1042+
In the context of search domains, for
1043+
:ref:`date and datetime fields <reference/fields/date>`, the value can be a
1044+
moment relative to *now* in the timezone of the user. A simple language is
1045+
provided to specify these dates. It is a space-separated string of terms.
1046+
The first term is optional and is "today" (at midnight) or "now".
1047+
Then, each term starts with "+" (add), "-" (subtract) or "=" (set), followed by
1048+
an integer and date unit or a lower-case weekday.
1049+
1050+
The date units are: "d" (days), "w" (weeks), "m" (months), "y" (years),
1051+
"H" (hours), "M" (minutes), "S" (seconds).
1052+
For weekdays, "+" and "-" mean next and previous weekday (unless we are already
1053+
in that weekday) and "=" means in current week starting on Monday.
1054+
When setting a date, the lower-units (hours, minutes and seconds) are set to 0.
1055+
1056+
.. example::
1057+
1058+
.. code-block:: python
1059+
1060+
Domain('some_date', '<', 'now') # now
1061+
Domain('some_date', '<', 'today') # today at midnight
1062+
Domain('some_date', '<', '-3d +1H') # now - 3 days + 1 hour
1063+
Domain('some_date', '<', '=3H') # today at 3:00:00
1064+
Domain('some_date', '<', '=5d') # 5th day of current month at midnight
1065+
Domain('some_date', '<', '=1m') # January, same day of month at midnight
1066+
Domain('some_date', '>=', '=monday -1w') # Monday of the previous week
1067+
10371068
Unlink
10381069
------
10391070

0 commit comments

Comments
 (0)