[FIX] web: do not warn on empty field
If no value is specified on the datefield, do not set a warnfuture message
Remove code comment that was referring the condition present at b51b0d66c2
but no longer present.
Add tests
Fixes #27551
closes odoo/odoo#27593
This commit is contained in:
@@ -93,8 +93,6 @@ var DateWidget = Widget.extend({
|
||||
}
|
||||
}
|
||||
if (hasChanged) {
|
||||
// The condition is strangely written; this is because the
|
||||
// values can be false/undefined
|
||||
if (this.options.warn_future) {
|
||||
this._warnFuture(newValue);
|
||||
}
|
||||
@@ -182,7 +180,7 @@ var DateWidget = Widget.extend({
|
||||
this.$warning.attr('title', title);
|
||||
this.$input.after(this.$warning);
|
||||
}
|
||||
if (currentDate.isAfter(moment())) {
|
||||
if (currentDate && currentDate.isAfter(moment())) {
|
||||
this.$warning.show();
|
||||
} else {
|
||||
this.$warning.hide();
|
||||
|
||||
@@ -2590,6 +2590,40 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('date field with warn_future option', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form string="Partners">' +
|
||||
'<field name="date" options="{\'datepicker\': {\'warn_future\': true}}"/>' +
|
||||
'</form>',
|
||||
res_id: 4,
|
||||
});
|
||||
|
||||
// switch to edit mode
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
// open datepicker and select another value
|
||||
testUtils.openDatepicker(form.$('.o_datepicker'));
|
||||
$('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection
|
||||
$('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection
|
||||
$('.bootstrap-datetimepicker-widget .year').eq(11).click(); // last year
|
||||
$('.bootstrap-datetimepicker-widget .month').eq(11).click(); // December
|
||||
$('.day:contains(31)').click(); // select the 31 December
|
||||
|
||||
var $warn = form.$('.o_datepicker_warning:visible');
|
||||
assert.strictEqual($warn.length, 1, "should have a warning in the form view");
|
||||
|
||||
form.$('.o_field_widget[name=date] input').val('').trigger('change'); // remove the value
|
||||
|
||||
$warn = form.$('.o_datepicker_warning:visible');
|
||||
assert.strictEqual($warn.length, 0, "the warning in the form view should be hidden");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('date field in editable list view', function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
|
||||
@@ -24,13 +24,12 @@ var BaseSettingRenderer = FormRenderer.extend({
|
||||
},
|
||||
|
||||
start: function () {
|
||||
var res = this._super.apply(this, arguments);
|
||||
this._super.apply(this, arguments);
|
||||
if (config.device.isMobile) {
|
||||
core.bus.on("DOM_updated", this, function () {
|
||||
this._moveToTab(this.currentIndex || this._currentAppIndex());
|
||||
});
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -267,16 +266,14 @@ var BaseSettingRenderer = FormRenderer.extend({
|
||||
},
|
||||
|
||||
_render: function () {
|
||||
var self = this;
|
||||
var res = this._super.apply(this, arguments);
|
||||
return res.then(function () {
|
||||
self._initModules();
|
||||
self._renderLeftPanel();
|
||||
self._initSearch();
|
||||
if (config.device.isMobile) {
|
||||
self._enableSwipe();
|
||||
}
|
||||
});
|
||||
this._initModules();
|
||||
this._renderLeftPanel();
|
||||
this._initSearch();
|
||||
if (config.device.isMobile) {
|
||||
this._enableSwipe();
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
_renderLeftPanel: function () {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
odoo.define('base.settings_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
var field_registry = require('web.field_registry');
|
||||
var testUtils = require('web.test_utils');
|
||||
var view_registry = require('web.view_registry');
|
||||
|
||||
var createAsyncView = testUtils.createAsyncView;
|
||||
var createView = testUtils.createView;
|
||||
var BaseSettingsView = view_registry.get('base_settings');
|
||||
var createActionManager = testUtils.createActionManager;
|
||||
@@ -180,82 +178,5 @@ QUnit.module('base_settings_tests', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('settings view works with deferred field', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
var def = $.Deferred();
|
||||
testUtils.patch(field_registry.map.boolean, {
|
||||
willStart: function () {
|
||||
var res = this._super.apply(this, arguments);
|
||||
return $.when(def, res);
|
||||
}
|
||||
});
|
||||
|
||||
createAsyncView({
|
||||
View: BaseSettingsView,
|
||||
model: 'project',
|
||||
data: this.data,
|
||||
arch: '<form string="Settings" class="oe_form_configuration o_base_settings">' +
|
||||
'<div class="o_control_panel">' +
|
||||
'<div class="o_panel">' +
|
||||
'<div class="o_setting_search">' +
|
||||
'<input type="text" class="searchInput" placeholder="Search..."/>' +
|
||||
'<span class="searchIcon"><i class="fa fa-search" role="img" aria-label="Search" title="Search"/></span>' +
|
||||
'</div> ' +
|
||||
'</div> ' +
|
||||
'<header>' +
|
||||
'<button string="Save" type="object" name="execute" class="oe_highlight" />' +
|
||||
'<button string="Cancel" type="object" name="cancel" class="oe_link" />' +
|
||||
'</header>' +
|
||||
'</div>' +
|
||||
'<div class="o_setting_container">' +
|
||||
'<div class="settings_tab"/>'+
|
||||
'<div class="settings">' +
|
||||
'<div class="notFound o_hidden">No Record Found</div>' +
|
||||
'<div class="app_settings_block" string="CRM" data-key="crm">' +
|
||||
'<div class="o_setting_left_pane">' +
|
||||
'<field name="foo"/>'+
|
||||
'</div>'+
|
||||
'<div class="o_setting_right_pane">'+
|
||||
'<label for="foo"/>'+
|
||||
'<div class="text-muted">'+
|
||||
'this is foo'+
|
||||
'</div>'+
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="app_settings_block" string="Other App" data-key="otherapp">' +
|
||||
'<div class="o_setting_left_pane">' +
|
||||
'<field name="bar"/>'+
|
||||
'</div>'+
|
||||
'<div class="o_setting_right_pane">'+
|
||||
'<label for="bar"/>'+
|
||||
'<div class="text-muted">'+
|
||||
'this is bar'+
|
||||
'</div>'+
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</form>',
|
||||
}).then(function (form) {
|
||||
assert.notOk(form.$('.oe_form_configuration').is(':empty'),
|
||||
"render should finish once deferred fields are resolved");
|
||||
assert.ok(form.$('.tab.selected').is('[data-key="crm"]'));
|
||||
assert.ok(form.$('.tab').is('[data-key="otherapp"]'));
|
||||
assert.ok(form.$('.app_settings_block[data-key="crm"]').is(':visible'));
|
||||
assert.ok(form.$('.app_settings_block[data-key="otherapp"]').is(':hidden'));
|
||||
assert.ok($(document.activeElement).is('.searchInput'), "search has focus");
|
||||
form.destroy();
|
||||
}).always(function () {
|
||||
testUtils.unpatch(field_registry.map.boolean);
|
||||
});
|
||||
|
||||
assert.strictEqual($('.oe_form_configuration').length, 0,
|
||||
"view is not attached until deferred are resolved");
|
||||
|
||||
// resolve fields widget deferred so view is attached
|
||||
def.resolve();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user