diff options
| author | Pierre Masereel <pim@odoo.com> | 2017-04-14 13:30:04 +0200 |
|---|---|---|
| committer | Pierre Masereel <pim@odoo.com> | 2017-04-18 13:14:50 +0200 |
| commit | 2b22ceea6fd5f1e8e999235bcf5f3d3e15206710 (patch) | |
| tree | 5f1a4466230989179114338050a47d0e700a0b34 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | a055d5f2266e2a8490808474639814ccf8bc9c54 (diff) | |
[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
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 74 |
1 files changed, 74 insertions, 0 deletions
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:'<form string="Partners"><field name="date"/></form>', + 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:'<form string="Partners"><field name="datetime"/></form>', + 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'); |
