[FIX] web: properly handle onchanges after discard
When an onchange is resolved after a discard, it caused a traceback. We now make sure that it does not happen. Note: I think that the test is quite neat.
This commit is contained in:
committed by
Aaron Bohy
parent
e3f84e592e
commit
cbc63ca869
@@ -1049,6 +1049,13 @@ var BasicModel = AbstractModel.extend({
|
||||
args: [idList, currentData, fields, onchange_spec, context],
|
||||
})
|
||||
.then(function (result) {
|
||||
if (!record._changes) {
|
||||
// if the _changes key does not exist anymore, it means that
|
||||
// it was removed by discarding the changes after the rpc
|
||||
// to onchange. So, in that case, the proper response is to
|
||||
// ignore the onchange.
|
||||
return;
|
||||
}
|
||||
if (result.warning) {
|
||||
self.trigger_up('warning', {
|
||||
message: result.warning.message,
|
||||
|
||||
@@ -2058,5 +2058,57 @@ QUnit.module('Views', {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('onchanges that complete after discarding', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var def1 = $.Deferred();
|
||||
|
||||
this.data.partner.onchanges = {
|
||||
foo: function (obj) {
|
||||
obj.int_field = obj.foo.length + 1000;
|
||||
},
|
||||
};
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<group><field name="foo"/><field name="int_field"/></group>' +
|
||||
'</form>',
|
||||
res_id: 2,
|
||||
mockRPC: function (route, args) {
|
||||
var result = this._super.apply(this, arguments);
|
||||
if (args.method === 'onchange') {
|
||||
assert.step('onchange is done');
|
||||
return def1.then(function () {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
},
|
||||
});
|
||||
|
||||
// go into edit mode
|
||||
assert.strictEqual(form.$('span[name="foo"]').text(), "blip",
|
||||
"field foo should be displayed to initial value");
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
|
||||
// edit a value
|
||||
form.$('input').first().val("1234").trigger('input');
|
||||
|
||||
// discard changes
|
||||
form.$buttons.find('.o_form_button_cancel').click();
|
||||
$('.modal .modal-footer .btn-primary').click();
|
||||
assert.strictEqual(form.$('span[name="foo"]').text(), "blip",
|
||||
"field foo should still be displayed to initial value");
|
||||
|
||||
// complete the onchange
|
||||
def1.resolve();
|
||||
assert.strictEqual(form.$('span[name="foo"]').text(), "blip",
|
||||
"field foo should still be displayed to initial value");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user