[FIX] web : Fixed datetime filter search based on wrong hours

Reproduce :
(With timezone GMT+3)
- Create any record R1 with previous day's date and time after 21:00.
- Create any record R2 with today's date and time after 21:00.
- Create a filter to show all todays records (Date is between "<TODAY'S DATE> 00:00:00 and <TODAY'S DATE> 23:59:59".

Result :
  Even though R1 is in yesterday's date, it will show in the list.
  R2 will not show in this list.

Explanation :
  This behaviour has been observed in several modules, for any timezone but UTC & only with custom filters default datetime values.
  The search was applied on [datetime(UTC) + 2 * offset] because the timezone wasn't correctly set.

Solution :
  Timezone is now correctly set on default datetime values.

closes odoo/odoo#79516

X-original-commit: 6fd105b89ea30695d6a324a5aa0b2004987c2e47
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Onockx Audric (auon) <auon@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2021-11-08 15:36:19 +00:00
parent 42838b5609
commit e22ffa3e7a
2 changed files with 41 additions and 2 deletions
@@ -120,9 +120,9 @@ odoo.define('web.CustomFilterItem', function (require) {
}
break;
case 'datetime':
condition.value = [moment('00:00:00', 'hh:mm:ss')];
condition.value = [moment('00:00:00', 'hh:mm:ss').utcOffset(0, true)];
if (operator.symbol === 'between') {
condition.value.push(moment('23:59:59', 'hh:mm:ss'));
condition.value.push(moment('23:59:59', 'hh:mm:ss').utcOffset(0, true));
}
break;
case 'selection':
@@ -419,6 +419,45 @@ odoo.define('web.filter_menu_generator_tests', function (require) {
cfi.destroy();
});
QUnit.test('default custom filter datetime', async function (assert) {
assert.expect(5);
class MockedSearchModel extends ActionModel {
dispatch(method, ...args) {
assert.strictEqual(method, 'createNewFilters');
const domain = JSON.parse(args[0][0].domain);
assert.strictEqual(domain[0][2].split(' ')[1],
'04:00:00',
"domain should be in UTC format");
assert.strictEqual(domain[1][2].split(' ')[1],
'03:59:59',
"domain should be in UTC format");
}
}
const searchModel = new MockedSearchModel();
const cfi = await createComponent(CustomFilterItem, {
props: {
fields: this.fields,
},
session: {
getTZOffset() {
return -240;
},
},
env: { searchModel },
});
await toggleAddCustomFilterStandalone(cfi);
await testUtils.fields.editSelect(cfi.el.querySelector('.o_generator_menu_field'), 'date_time_field');
assert.strictEqual(cfi.el.querySelector('.o_generator_menu_field').value, 'date_time_field');
assert.strictEqual(cfi.el.querySelector('.o_generator_menu_operator').value, 'between');
await cpHelpers.applyFilter(cfi);
cfi.destroy();
});
QUnit.test('input value parsing', async function (assert) {
assert.expect(7);