From 708c1c2915563a40a1e4c736b4fd11ffd89280f8 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 13 Jun 2017 08:46:15 +0200 Subject: [PATCH] [FIX] web: false id should remain false in evalContext 'id' is a particular field that should not be considered like other integer fields. For instance, in the evalContext, its value should not fallback to 0 if it is false. This would break domains in attrs like ['id', '=', False], which is supposed to be true on new (not saved yet) records. This was for example the case in the Product form view: go to Sales Orders form view, add a line, on the product field choose 'Create and Edit', try to save the product -> error: field Product Template is required but not set (actually it is invisible), as its required modifier says ['id', '!=', False], which was always the case. --- .../static/src/js/views/basic/basic_model.js | 2 +- addons/web/static/tests/views/form_tests.js | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 20066b858f1..6c23550ba2e 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2176,7 +2176,7 @@ var BasicModel = AbstractModel.extend({ if (context[fieldName] === null) { context[fieldName] = false; } - if (!field) { + if (!field || field.name === 'id') { continue; } if (field.type === 'float' || diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index d9fbfe2f3a4..75663e59b15 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -5039,5 +5039,30 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('id is False in evalContext for new records', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '', + }); + + assert.ok(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + "foo should be readonly in 'Create' mode"); + + form.$buttons.find('.o_form_button_save').click(); + form.$buttons.find('.o_form_button_edit').click(); + + assert.notOk(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + "foo should not be readonly anymore"); + + form.destroy(); + }); }); });