Skip to content

Commit 32f57c0

Browse files
committed
[IMP] orm: dynamic dates
1 parent 7117bf8 commit 32f57c0

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 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 string separated by spaces.
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+
1055+
When setting a date, the lower-units (hours, minutes and seconds) are set to 0.
1056+
"=3H" means *at 3:00:00*, "=5d" means *5th day of current month at midnight*,
1057+
"=1m" means *January, same day of month, at midnight*.
1058+
1059+
.. example::
1060+
1061+
.. code-block:: python
1062+
1063+
Domain('some_date', '=', 'today') # today
1064+
Domain('some_date', '=', '=1d') # first day of month (at midnight)
1065+
Domain('create_date', '>', '-3d +1H') # now - 3 days + 1 hour
1066+
Domain('create_date', '>=', '=monday -1w') # Monday of the previous week
1067+
10371068
Unlink
10381069
------
10391070

0 commit comments

Comments
 (0)