From 83dab2d0dcab28607b82550190ea295bd31c167e Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Mon, 27 Mar 2017 11:23:17 +0200 Subject: [PATCH] [REM] web: remove id widget The original reason why this widget was created is because sometimes, the id is a virtual one, represented by string in the webclient. As such, the integer widget could not render it properly since it could not parse the integer from the string. This led to the following bug, which in turn led to the creation of the id widget: https://bugs.launchpad.net/openerp-web/+bug/919184 Now, virtual ids are not handled within the record data itself anymore, making it a non-issue to render the id field in the webclient since it is not given a value until a proper id is created. The virtual id management is completely out of the view scope now, rendering this widget useless. --- .../web/static/src/js/fields/basic_fields.js | 9 --- .../static/src/js/fields/field_registry.js | 1 - .../web/static/src/js/fields/field_utils.js | 13 ---- .../static/src/js/services/data_manager.js | 7 -- .../test/fields/relational_fields_tests.js | 77 +++++++++++++++++++ 5 files changed, 77 insertions(+), 30 deletions(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 28aae294dcf..8bee0daffac 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1240,14 +1240,6 @@ var FieldBooleanButton = AbstractField.extend({ }, }); -var FieldID = InputField.extend({ - supportedFieldTypes: ['id'], - init: function () { - this._super.apply(this, arguments); - this.mode = 'readonly'; - }, -}); - var StatInfo = AbstractField.extend({ supportedFieldTypes: ['integer', 'float'], _render: function () { @@ -1902,7 +1894,6 @@ return { FieldFloat: FieldFloat, FieldFloatTime: FieldFloatTime, FieldHtml: FieldHtml, - FieldID: FieldID, FieldInteger: FieldInteger, FieldMonetary: FieldMonetary, FieldPercentPie: FieldPercentPie, diff --git a/addons/web/static/src/js/fields/field_registry.js b/addons/web/static/src/js/fields/field_registry.js index 0130d20a211..83d28c1649f 100644 --- a/addons/web/static/src/js/fields/field_registry.js +++ b/addons/web/static/src/js/fields/field_registry.js @@ -40,7 +40,6 @@ registry .add('label_selection', basic_fields.LabelSelection) .add('state_selection', basic_fields.StateSelectionWidget) .add('boolean_button', basic_fields.FieldBooleanButton) - .add('id', basic_fields.FieldID) .add('statinfo', basic_fields.StatInfo) .add('percentpie', basic_fields.FieldPercentPie) .add('float_time', basic_fields.FieldFloatTime) diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 9c5afb71dd9..cc9580c4baf 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -142,17 +142,6 @@ function formatFloatTime(value) { return _.str.sprintf(pattern, hour, min); } -/** - * Returns a string representing an ID. If the value is false, then we - * return an empty string. - * - * @param {integer|false} value - * @returns {string} - */ -function formatID(value) { - return value ? value.toString() : ''; -} - /** * Returns a string representing an integer. If the value is false, then we * return an empty string. @@ -390,7 +379,6 @@ return { float: formatFloat, float_time: formatFloatTime, html: _.identity, // todo - id: formatID, integer: formatInteger, many2many: formatMany2Many, many2one: formatMany2one, @@ -409,7 +397,6 @@ return { float: parseFloat, float_time: parseFloatTime, html: _.identity, // todo - id: _.identity, integer: parseInteger, many2many: _.identity, // todo many2one: parseMany2one, diff --git a/addons/web/static/src/js/services/data_manager.js b/addons/web/static/src/js/services/data_manager.js index cb2773fd2be..fa3a2efb231 100644 --- a/addons/web/static/src/js/services/data_manager.js +++ b/addons/web/static/src/js/services/data_manager.js @@ -219,13 +219,6 @@ return core.Class.extend({ var doc = $.parseXML(fields_view.arch).documentElement; fields_view.arch = utils.xml_to_json(doc, (doc.nodeName.toLowerCase() !== 'kanban')); - // Special case for id's - if ('id' in fields_view.fields) { - var id_field = fields_view.fields.id; - id_field.original_type = id_field.type; - id_field.type = 'id'; - } - // Process inner views (x2manys) _.each(fields_view.fields, function(field) { _.each(field.views || {}, function(view) { diff --git a/addons/web/static/test/fields/relational_fields_tests.js b/addons/web/static/test/fields/relational_fields_tests.js index 7ac8e12afee..9b562b1a3a9 100644 --- a/addons/web/static/test/fields/relational_fields_tests.js +++ b/addons/web/static/test/fields/relational_fields_tests.js @@ -2173,6 +2173,83 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('one2many field with virtual ids', function (assert) { + assert.expect(11); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
' + + '' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
', + archs: { + 'partner,false,form': '
' + + '' + + '', + }, + res_id: 4, + }); + + assert.strictEqual(form.$('.o_form_field .o_kanban_view').length, 1, + "should have one inner kanban view for the one2many field"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 0, + "should not have kanban records yet"); + + // // switch to edit mode and create a new kanban record + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_form_field .o-kanban-button-new').click(); + + // save & close the modal + assert.strictEqual($('.modal-content input.o_form_field').val(), 'My little Foo Value', + "should already have the default value for field foo"); + $('.modal-content .btn-primary').first().click(); + + assert.strictEqual(form.$('.o_form_field .o_kanban_view').length, 1, + "should have one inner kanban view for the one2many field"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 1, + "should now have one kanban record"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost) .o_test_id').text(), + '', "should not have a value for the id field"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost) .o_test_foo').text(), + 'My little Foo Value', "should have a value for the foo field"); + + // save the view to force a create of the new record in the one2many + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('.o_form_field .o_kanban_view').length, 1, + "should have one inner kanban view for the one2many field"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 1, + "should now have one kanban record"); + assert.notEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost) .o_test_id').text(), + '', "should now have a value for the id field"); + assert.strictEqual(form.$('.o_form_field .o_kanban_view .o_kanban_record:not(.o_kanban_ghost) .o_test_foo').text(), + 'My little Foo Value', "should still have a value for the foo field"); + + form.destroy(); + }); QUnit.module('FieldMany2Many');