diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 5a3bd699a7c..344f7174c54 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -482,6 +482,7 @@ var FieldMonetary = InputField.extend({ * @override * @private * @param {float} value + * @returns {string} */ _formatValue: function (value) { var format = field_utils.format[this.mode === 'edit' ? "float" : "monetary"]; @@ -598,6 +599,10 @@ var FieldBoolean = AbstractField.extend({ var FieldInteger = InputField.extend({ supportedFieldTypes: ['integer'], + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + /** * For integer fields, 0 is a valid value. * @@ -606,6 +611,34 @@ var FieldInteger = InputField.extend({ isSet: function () { return this.value === 0 || this._super.apply(this, arguments); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Format integer value + * + * Note: We have to overwrite this method to allow virtual ids. A virtual id + * is a character string composed of an integer and has a dash and other + * information. + * E.g: in calendar, the recursive event have virtual id linked to a real id + * virtual event id "23-20170418020000" is linked to the event id 23 + * + * @override + * @private + * @param {integer|string} value + * @returns {string} + */ + _formatValue: function (value) { + if (typeof value === 'string') { + if (!/^[0-9]+-/.test(value)) { + throw new Error('"' + value + '" is not an integer or a virtual id'); + } + return value; + } + return field_utils.format.integer(value, this.field); + }, }); var FieldFloat = InputField.extend({ diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index ef35fee0ca2..1aa4ee9e838 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -292,7 +292,7 @@ return AbstractModel.extend({ return this._rpc({ model: this.modelName, method: 'write', - args: [record.id, data], + args: [[record.id], data], }); }, diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index cd0380d0949..9f2ff12c9e2 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1521,6 +1521,31 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('integer field in form view with virtual id', function(assert) { + assert.expect(2); + var params = { + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + }; + + params.res_id = this.data.partner.records[1].id = "2-20170808020000"; + var form = createView(params); + assert.strictEqual(form.$('.o_form_field').text(), "2-20170808020000", + "Should display virtual id"); + form.destroy(); + + params.res_id = this.data.partner.records[1].id = "2.65-20170808020000"; + try { + form = createView(params); + } catch (error) { + assert.strictEqual(error.message, '"2.65-20170808020000" is not an integer or a virtual id', + "Should throw an exception because it's a wrong value"); + } + form.destroy(); + }); + QUnit.test('integer field in editable list view', function (assert) { assert.expect(4);