[FIX] web: prevent crash with invisible x2m and onchanges
When an invisible x2many field is modified by an onchange, we had a crash because the reset function did not return a deferred in that case. This happens because the signature of _render in AbstractField allow for an undefined return value, but the reset method should return a deferred. This was an issue for example in stock: editing the pack_operation_product_ids one2many field in a stock.picking could trigger an onchange on another invisible one2many (with no inline views).
This commit is contained in:
committed by
Martin Geubelle
parent
7dc731db83
commit
56dae80994
@@ -273,7 +273,7 @@ var AbstractField = Widget.extend({
|
||||
*/
|
||||
reset: function (record, event) {
|
||||
this._reset(record, event);
|
||||
return this._render();
|
||||
return this._render() || $.when();
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -684,7 +684,7 @@ var FieldX2Many = AbstractField.extend({
|
||||
*
|
||||
* @override
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
* @returns {Deferred|undefined}
|
||||
*/
|
||||
_render: function () {
|
||||
if (!this.view) {
|
||||
|
||||
@@ -4763,6 +4763,38 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('resetting invisible one2manys', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.records[0].turtles = [];
|
||||
this.data.partner.onchanges.foo = function (obj) {
|
||||
obj.turtles = [[5], [4, 1]];
|
||||
};
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<field name="foo"/>' +
|
||||
'<field name="turtles" invisible="1"/>' +
|
||||
'</form>',
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
res_id: 1,
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method);
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
form.$('input[name="foo"]').val('abcd').trigger('input');
|
||||
assert.verifySteps(['read', 'onchange']);
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldMany2Many');
|
||||
|
||||
QUnit.test('many2many kanban: edition', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user