Skip to content

Commit

Permalink
[FIX] web: py.js evaluation of current_date
Browse files Browse the repository at this point in the history
current_date was absent from py_builtin. For that reason, it was
impossible for the search model to evaluate a dynamic domains like
"[('date_deadline', '<', current_date)]"

We add current_date to py_builtin.

closes odoo#77035

X-original-commit: ade082c
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
  • Loading branch information
Polymorphe57 committed Sep 23, 2021
1 parent 31c9bca commit 99e77f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addons/web/static/src/core/py_js/py_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const BUILTINS = {
return PyDate.today();
},

get current_date() {
// deprecated: today should be prefered
return this.today;
},

get today() {
return PyDate.today().strftime("%Y-%m-%d");
},
Expand Down
5 changes: 5 additions & 0 deletions addons/web/static/tests/core/py_js/py_date_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,10 @@ QUnit.module("py", {}, () => {
QUnit.test("now", (assert) => {
assert.ok(check("now", formatDateTime));
});

QUnit.test("current_date", (assert) => {
patchDate(2021, 8, 20, 10, 0, 0);
assert.deepEqual(evaluateExpr("current_date"), "2021-09-20");
});
});
});
2 changes: 2 additions & 0 deletions addons/web/static/tests/search/search_model_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,15 @@ QUnit.module("Search", (hooks) => {
<filter name="filter_0" domain="[('datetime', '=', (datetime.datetime.combine(context_today(), datetime.time(0,0,0)).to_utc()))]"/>
<filter name="filter_1" domain="[('date', '=', context_today() + relativedelta(days=-365))]"/>
<filter name="filter_2" domain="[('create_date', '&gt;', (context_today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d'))]"/>
<filter name="filter_3" domain="[('date_deadline', '&lt;', current_date)]"/>
</search>
`;

const evaluatedDomains = [
[["datetime", "=", "2021-09-16 22:00:00"]],
[["date", "=", "2020-09-17 00:00:00"]],
[["create_date", ">", "2021-09-16"]],
[["date_deadline", "<", "2021-09-17"]],
];

const model = await makeSearchModel({ serverData, searchViewArch });
Expand Down

0 comments on commit 99e77f7

Please sign in to comment.