[FIX] web: use latin number date domain in comparison menu

When using eg. arabic locale, the figures inside dates were replaced by
arabic figures which are not supported server side (they are almost
always sent in latin figures).

With this changeset, the we are using english locale to get date in
domains.

Without the change, added test fails with:

  Numbers in domain should not use addoneForTest locale
  Expected:...[date_field, >=, 2020-06-01], [date_field, <=, 2020-06-30]
  Result:...[date_field, >=, 3131-17-12], [date_field, <=, 3131-17-41]

opw-2370392
closes #61354

closes odoo/odoo#61443

X-original-commit: 74ea66a107cfc98cce8e52903ec21e3d752fb4fb
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2020-11-05 17:44:49 +00:00
parent ad723ac0c6
commit 795c6723df
2 changed files with 28 additions and 2 deletions
@@ -287,8 +287,8 @@ odoo.define('web.searchUtils', function (require) {
const date = referenceMoment.clone().set(setParam).add(addParam || {});
// compute domain
let leftBound = date.clone().startOf(granularity);
let rightBound = date.clone().endOf(granularity);
let leftBound = date.clone().locale('en').startOf(granularity);
let rightBound = date.clone().locale('en').endOf(granularity);
if (fieldType === 'date') {
leftBound = leftBound.format('YYYY-MM-DD');
rightBound = rightBound.format('YYYY-MM-DD');
@@ -332,5 +332,31 @@ odoo.define('web.search_utils_tests', function (require) {
testUtils.mock.unpatch(_t.database.db);
testUtils.mock.unpatch(_t.database.parameters);
});
QUnit.test("Moment.js localization does not affect formatted domain dates", async function (assert) {
assert.expect(1);
const unpatchDate = patchDate(2020, 5, 1, 13, 0, 0);
const initialLocale = moment.locale();
moment.defineLocale('addoneForTest', {
postformat: function (string) {
return string.replace(/\d/g, match => (1 + parseInt(match)) % 10);
}
});
const referenceMoment = moment().locale('addoneForTest');
assert.deepEqual(
constructDateDomain(referenceMoment, 'date_field', 'date', ['this_month', 'this_year']),
{
domain: `["&", ["date_field", ">=", "2020-06-01"], ["date_field", "<=", "2020-06-30"]]`,
description: "June 3131",
},
"Numbers in domain should not use addoneForTest locale"
);
moment.locale(initialLocale);
moment.updateLocale("addoneForTest", null);
unpatchDate();
});
});
});