diff options
| author | Julien Mougenot <jum@odoo.com> | 2020-06-02 15:03:52 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2020-07-14 09:10:32 +0000 |
| commit | 669c2ebaec701055a15dc56ea90bf2d64bc38154 (patch) | |
| tree | 6711c374432f030d3c375825b65943cdc0186bdc /addons/web/static/tests/views/basic_model_tests.js | |
| parent | b9ad60d5ebe73ee47eba64145ebe27d483a7f33a (diff) | |
[IMP] web: improve eval context dates
This commit handles 2 things:
1) the merging of the `py_utils.context()` into the evaluation context
returned by `BasicModel._getEvalContext` to access the same time-related
keys,
2) the addition of 2 new keys into the `py_utils.context` (thus
transmitted to the basic model): `today` (an alias for the already
present `current_date`) and `now` which represents the current date and
time value.
Task 2269697
Diffstat (limited to 'addons/web/static/tests/views/basic_model_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/basic_model_tests.js | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index f57478e1252..b533c6587e9 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -2037,8 +2037,9 @@ odoo.define('web.basic_model_tests', function (require) { }); QUnit.test('has a proper evaluation context', async function (assert) { - assert.expect(1); + assert.expect(6); + const unpatchDate = testUtils.mock.patchDate(1997, 0, 9, 12, 0, 0); this.params.fieldNames = Object.keys(this.data.partner.fields); this.params.res_id = 1; @@ -2048,8 +2049,24 @@ odoo.define('web.basic_model_tests', function (require) { }); var resultID = await model.load(this.params); - var record = model.get(resultID); - assert.deepEqual(record.evalContext, { + const { evalContext } = model.get(resultID); + assert.strictEqual(typeof evalContext.datetime, "object"); + assert.strictEqual(typeof evalContext.relativedelta, "object"); + assert.strictEqual(typeof evalContext.time, "object"); + assert.strictEqual(typeof evalContext.context_today, "function"); + assert.strictEqual(typeof evalContext.tz_offset, "function"); + const blackListedKeys = [ + "time", + "datetime", + "relativedelta", + "context_today", + "tz_offset", + ]; + // Remove uncomparable values from the evaluation context + for (const key of blackListedKeys) { + delete evalContext[key]; + } + assert.deepEqual(evalContext, { active: true, active_id: 1, active_ids: [1], @@ -2058,6 +2075,8 @@ odoo.define('web.basic_model_tests', function (require) { category: [12], current_company_id: false, current_date: moment().format('YYYY-MM-DD'), + today: moment().format('YYYY-MM-DD'), + now: moment().utc().format('YYYY-MM-DD HH:mm:ss'), date: "2017-01-25", display_name: "first partner", foo: "blip", @@ -2070,6 +2089,7 @@ odoo.define('web.basic_model_tests', function (require) { x_active: true, }, "should use the proper eval context"); model.destroy(); + unpatchDate(); }); QUnit.test('x2manys in contexts and domains are correctly evaluated', async function (assert) { |
