From 2b22ceea6fd5f1e8e999235bcf5f3d3e15206710 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Fri, 14 Apr 2017 13:30:04 +0200 Subject: [FIX] web: date_picker empty input field When you try to empty a date or datetime field, you get a traceback saying that 'clone' and 'isSame' are not functions. This error occurs when you empty the field because the value is 'false' and you cannot call 'clone' or 'isSame' on false. To fix this, we ensure that value is not false before calling these methods on it. This bug has been introduced in rev: https://github.com/odoo/odoo/commit/c32724eae06c987e74a0600f1669696e499edc33 --- .../web/static/tests/fields/basic_fields_tests.js | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index cb61e21e376..f32f0b6ac61 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1082,6 +1082,41 @@ QUnit.module('basic_fields', { list.destroy(); }); + QUnit.test('date field remove value', function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 1, + mockRPC: function (route, args) { + if (route === '/web/dataset/call_kw/partner/write') { + assert.strictEqual(args.args[1].date, false, 'the correct value should be saved'); + } + return this._super.apply(this, arguments); + }, + translateParameters: { // Avoid issues due to localization formats + date_format: '%m/%d/%Y', + }, + }); + + // switch to edit mode + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017', + 'the date should be correct in edit mode'); + + $('.o_datepicker_input').val('').trigger('input').trigger('change'); + assert.ok(!form.$('.o_datepicker_input').val()); + + // save + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('.o_form_field_date').text(), '', + 'the selected date should be displayed after saving'); + form.destroy(); + }); + QUnit.module('FieldDatetime'); @@ -1206,6 +1241,45 @@ QUnit.module('basic_fields', { list.destroy(); }); + QUnit.test('datetime field remove value', function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 1, + mockRPC: function (route, args) { + if (route === '/web/dataset/call_kw/partner/write') { + assert.strictEqual(args.args[1].datetime, false, 'the correct value should be saved'); + } + return this._super.apply(this, arguments); + }, + translateParameters: { // Avoid issues due to localization formats + date_format: '%m/%d/%Y', + time_format: '%H:%M:%S', + }, + session: { + tzOffset: 120 + }, + }); + + // switch to edit mode + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017 12:00:00', + 'the date time should be correct in edit mode'); + + $('.o_datepicker_input').val('').trigger('input').trigger('change'); + assert.ok(!form.$('.o_datepicker_input').val()); + + // save + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('.o_form_field_date').text(), '', + 'the selected date should be displayed after saving'); + form.destroy(); + }); + QUnit.module('FieldMonetary'); -- cgit v1.2.3