From b51b0d66c2f71593d5eb3f153d55b1b97d979da7 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 21 Sep 2017 12:22:43 +0200 Subject: [PATCH] [FIX] web: open domain selector's datepicker at the right position Before this commit, and since the combination of new views + datepicker library update, the datepicker opened at the top left of the window when using it in a domain selector. It also could not be used at all. This was because the current scenario occured: 1) Click on the datepicker 2) The datepicker triggers that it has changed on opening 3) The whole domain selector is rerendered 4) The datepicker computes where it should open... on basis of the old destroyed domain selector As the main cause of the problem here was the (2), this commit changes the datepicker odoo widget to only notifies that it has changed when it has really changed. --- addons/web/static/src/js/widgets/date_picker.js | 11 +++++++++-- .../static/tests/widgets/domain_selector_tests.js | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js index 76281d9366a..b95a1c4f936 100644 --- a/addons/web/static/src/js/widgets/date_picker.js +++ b/addons/web/static/src/js/widgets/date_picker.js @@ -74,9 +74,16 @@ var DateWidget = Widget.extend({ * set datetime value */ changeDatetime: function () { - if(this.isValid()) { + if (this.isValid()) { + var oldValue = this.getValue(); this._setValueFromUi(); - this.trigger("datetime_changed"); + var newValue = this.getValue(); + + if (!oldValue !== !newValue || oldValue && newValue && !oldValue.isSame(newValue)) { + // The condition is strangely written; this is because the + // values can be false/undefined + this.trigger("datetime_changed"); + } } }, /** diff --git a/addons/web/static/tests/widgets/domain_selector_tests.js b/addons/web/static/tests/widgets/domain_selector_tests.js index 19731156a2c..77d8eeb24da 100644 --- a/addons/web/static/tests/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/widgets/domain_selector_tests.js @@ -151,7 +151,7 @@ QUnit.module('DomainSelector', { }); QUnit.test("building a domain with a datetime", function (assert) { - assert.expect(1); + assert.expect(2); var $target = $("#qunit-fixture"); @@ -163,8 +163,16 @@ QUnit.module('DomainSelector', { domainSelector.appendTo($target); // Check that there is a datepicker to choose the date - assert.strictEqual(domainSelector.$(".o_datepicker:visible").length, 1, + var $datepicker = domainSelector.$(".o_datepicker:visible"); + assert.strictEqual($datepicker.length, 1, "there should be a datepicker"); + + var val = $datepicker.find('input').focus().click().val(); + $('.bootstrap-datetimepicker-widget :not(.today)[data-action="selectDay"]').click(); + assert.notEqual(domainSelector.$(".o_datepicker:visible input").val(), val, + "datepicker value should have changed"); + + domainSelector.destroy(); }); }); });