[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.
This commit is contained in:
Aaron Bohy
2017-06-13 09:26:40 +02:00
parent ebd17217c4
commit 708c1c2915
2 changed files with 26 additions and 1 deletions
@@ -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' ||
@@ -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: '<form string="Partners">' +
'<field name="id"/>' +
'<field name="foo" attrs="{\'readonly\': [[\'id\', \'=\', False]]}"/>' +
'</form>',
});
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();
});
});
});