Skip to content
Snippets Groups Projects
Commit 0059eb90 authored by Achraf (abz)'s avatar Achraf (abz)
Browse files

[FIX] web: Avoid competition in change and hide events from datepicker


If we set a date manually via the input while the datepicker widget is displayed and we click outside the widget while remaining in the dropdown custom filter, a traceback appears.
Because two triggers on datetime-changed are done almost at the same time change.input hide.widget

Now we ignore lib events for `_datetimepicker()`

OPW-2591874

closes odoo/odoo#78394

Signed-off-by: default avatarAaron Bohy (aab) <aab@odoo.com>
parent 1a0fb24e
No related branches found
No related tags found
No related merge requests found
......@@ -81,7 +81,9 @@ odoo.define('web.DatePickerOwl', function (require) {
* @param {...any} args anything that will be passed to the datetimepicker function.
*/
_datetimepicker(...args) {
this.ignoreBootstrapEvents = true;
$(this.el).datetimepicker(...args);
this.ignoreBootstrapEvents = false;
}
/**
......@@ -120,6 +122,9 @@ odoo.define('web.DatePickerOwl', function (require) {
* @private
*/
_onDateTimePickerHide() {
if (this.ignoreBootstrapEvents) {
return;
}
const date = this._parseInput(this.inputRef.el.value);
this.state.warning = date.format('YYYY-MM-DD') > moment().format('YYYY-MM-DD');
this.trigger('datetime-changed', { date });
......@@ -132,6 +137,9 @@ odoo.define('web.DatePickerOwl', function (require) {
* @private
*/
_onDateTimePickerShow() {
if (this.ignoreBootstrapEvents) {
return;
}
this.inputRef.el.select();
}
......
......@@ -4,6 +4,8 @@ odoo.define('web.datepicker_tests', function (require) {
const { DatePicker, DateTimePicker } = require('web.DatePickerOwl');
const testUtils = require('web.test_utils');
const time = require('web.time');
const CustomFilterItem = require('web.CustomFilterItem');
const ActionModel = require('web/static/src/js/views/action_model.js');
const { createComponent } = testUtils;
......@@ -163,6 +165,43 @@ odoo.define('web.datepicker_tests', function (require) {
testUtils.unpatch(time);
});
QUnit.test('custom filter date', async function (assert) {
assert.expect(5);
class MockedSearchModel extends ActionModel {
dispatch(method, ...args) {
assert.strictEqual(method, 'createNewFilters');
const preFilters = args[0];
const preFilter = preFilters[0];
assert.strictEqual(preFilter.description,
'A date is equal to "05/05/2005"',
"description should be in localized format");
assert.deepEqual(preFilter.domain,
'[["date_field","=","2005-05-05"]]',
"domain should be in UTC format");
}
}
const searchModel = new MockedSearchModel();
const date_field = { name: 'date_field', string: "A date", type: 'date', searchable: true };
const cfi = await createComponent(CustomFilterItem, {
props: {
fields: { date_field },
},
env: { searchModel },
});
await testUtils.controlPanel.toggleAddCustomFilter(cfi);
await testUtils.fields.editSelect(cfi.el.querySelector('.o_generator_menu_field'), 'date_field');
const valueInput = cfi.el.querySelector('.o_generator_menu_value .o_input');
await testUtils.dom.click(valueInput);
assert.containsOnce(document.body, '.datepicker');
await testUtils.fields.editSelect(valueInput, '05/05/2005');
await testUtils.controlPanel.applyFilter(cfi);
assert.containsNone(document.body, '.datepicker');
cfi.destroy();
});
QUnit.module('DateTimePicker');
QUnit.test("basic rendering", async function (assert) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment