diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index f4f5496006c..d3dab0fe647 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -383,8 +383,14 @@ var FieldBoolean = AbstractField.extend({ var FieldInteger = InputField.extend({ supportedFieldTypes: ['integer'], + + /** + * For integer fields, 0 is a valid value. + * + * @override + */ isSet: function () { - return this.value !== false; + return this.value === 0 || this._super.apply(this, arguments); }, }); diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js index 1e79bdda753..b9f01d6a654 100644 --- a/addons/web/static/test/fields/basic_fields_tests.js +++ b/addons/web/static/test/fields/basic_fields_tests.js @@ -46,7 +46,7 @@ QUnit.module('basic_fields', { display_name: "second record", bar: true, foo: "blip", - int_field: 9, + int_field: 0, qux: 13, p: [], timmy: [], @@ -57,6 +57,7 @@ QUnit.module('basic_fields', { display_name: "aaa", foo: "abc", sequence: 9, + int_field: false, }, {id: 3, bar: true, foo: "gnap", int_field: 17, qux: -3, m2o: 1, m2m: []}, {id: 4, bar: false, foo: "blip", int_field: -4, qux: 9, m2o: 1, m2m: [1]}], @@ -895,6 +896,90 @@ QUnit.module('basic_fields', { list.destroy(); }); + + QUnit.module('FieldInteger'); + + QUnit.test('integer field when unset', function(assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 4, + }); + + assert.ok(form.$('.o_form_field').hasClass('o_form_field_empty'), + 'Non-set integer field should be recognized as unset.'); + + form.destroy(); + }); + + QUnit.test('integer field in form view', function(assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'', + res_id: 2, + }); + + assert.ok(!form.$('.o_form_field').hasClass('o_form_field_empty'), + 'Integer field should be considered set for value 0.'); + + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('input.o_form_input').val(), '0', + 'The value should be rendered correctly in edit mode.') + + form.$('input.o_form_input').val('-18').trigger('input'); + assert.strictEqual(form.$('input.o_form_input').val(), '-18', + 'The value should be correctly displayed in the input.') + + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('.o_form_field').text(), '-18', + 'The new value should be saved and displayed properly.') + + form.destroy(); + }); + + QUnit.test('integer field in editable list view', function (assert) { + assert.expect(4); + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '