diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index 4e6adbf99cb..aa970c31649 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -1694,6 +1694,7 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{
proxy.reset();
});
this._proxies = {};
+ _(this.records).invoke('unbind', null, this._onRecordEvent);
this.length = 0;
this.records = [];
this._byId = {};
@@ -1712,7 +1713,6 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{
* @returns this
*/
remove: function (record) {
- var self = this;
var index = _(this.records).indexOf(record);
if (index === -1) {
_(this._proxies).each(function (proxy) {
@@ -1721,6 +1721,7 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{
return this;
}
+ record.unbind(null, this._onRecordEvent);
this.records.splice(index, 1);
delete this._byId[record.get('id')];
this.length--;
diff --git a/addons/web/static/test/list-utils.js b/addons/web/static/test/list-utils.js
index f71da82a560..8cc34454cd5 100644
--- a/addons/web/static/test/list-utils.js
+++ b/addons/web/static/test/list-utils.js
@@ -170,6 +170,16 @@ $(document).ready(function () {
equal(c.get(2), undefined);
strictEqual(c.at(1).get('value'), 20);
});
+ test('Remove unbind', function () {
+ var changed = false,
+ c = new openerp.web.list.Collection([ {id: 1, value: 5} ]);
+ c.bind('change', function () { changed = true; });
+ var record = c.get(1);
+ c.remove(record);
+ record.set('value', 42);
+ ok(!changed, 'removed records should not trigger events in their ' +
+ 'parent collection');
+ });
test('Reset', function () {
var event, obj, c = new openerp.web.list.Collection([
{id: 1, value: 5},
@@ -190,6 +200,16 @@ $(document).ready(function () {
strictEqual(c.length, 1);
strictEqual(c.get(42).get('value'), 55);
});
+ test('Reset unbind', function () {
+ var changed = false,
+ c = new openerp.web.list.Collection([ {id: 1, value: 5} ]);
+ c.bind('change', function () { changed = true; });
+ var record = c.get(1);
+ c.reset();
+ record.set('value', 42);
+ ok(!changed, 'removed records should not trigger events in their ' +
+ 'parent collection');
+ });
test('Events propagation', function () {
var values = [];
diff --git a/addons/web/static/test/test.html b/addons/web/static/test/test.html
index b1018bc00ca..da06aba2364 100644
--- a/addons/web/static/test/test.html
+++ b/addons/web/static/test/test.html
@@ -14,6 +14,7 @@
+