[FIX] web: correctly apply onchange on boolean field
When an onchange sets a boolean field to 'true', if this boolean was set to 'false' previously, the old value was used instead of 'false'.
This commit is contained in:
@@ -1235,7 +1235,7 @@ var BasicModel = AbstractModel.extend({
|
||||
record._rawChanges[name] = val;
|
||||
return;
|
||||
}
|
||||
var oldValue = record._changes[name] || record.data[name];
|
||||
var oldValue = name in record._changes ? record._changes[name] : record.data[name];
|
||||
var id;
|
||||
if (field.type === 'many2one') {
|
||||
id = false;
|
||||
|
||||
@@ -2123,4 +2123,47 @@ QUnit.module('Views', {
|
||||
model.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('onchange on a boolean field', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var newFields = {
|
||||
foobool: {
|
||||
type: 'boolean',
|
||||
string: 'foobool',
|
||||
},
|
||||
foobool2: {
|
||||
type: 'boolean',
|
||||
string: 'foobool2',
|
||||
},
|
||||
};
|
||||
_.extend(this.data.partner.fields, newFields);
|
||||
|
||||
this.data.partner.onchanges.foobool = function (obj) {
|
||||
if (obj.foobool) {
|
||||
obj.foobool2 = true;
|
||||
}
|
||||
};
|
||||
|
||||
this.data.partner.records[0].foobool = false;
|
||||
this.data.partner.records[0].foobool2 = true;
|
||||
|
||||
this.params.res_id = 1;
|
||||
this.params.fieldNames = ['foobool', 'foobool2'];
|
||||
this.params.fields = this.data.partner.fields;
|
||||
var model = createModel({
|
||||
Model: BasicModel,
|
||||
data: this.data,
|
||||
});
|
||||
|
||||
model.load(this.params).then(function (resultID) {
|
||||
var record = model.get(resultID);
|
||||
model.notifyChanges(resultID, {foobool2: false});
|
||||
record = model.get(resultID);
|
||||
assert.strictEqual(record.data.foobool2, false, "foobool2 field should be false");
|
||||
model.notifyChanges(resultID, {foobool: true});
|
||||
record = model.get(resultID);
|
||||
assert.strictEqual(record.data.foobool2, true, "foobool2 field should be true");
|
||||
});
|
||||
model.destroy();
|
||||
});
|
||||
});});
|
||||
|
||||
Reference in New Issue
Block a user