diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 3d777b381bb..321faf40c0f 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -503,12 +503,17 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi return this.reload_content(); }, reload_record: function (record) { + var self = this; return this.dataset.read_ids( [record.get('id')], _.pluck(_(this.columns).filter(function (r) { return r.tag === 'field'; }), 'name') ).done(function (records) { + if (!records[0]) { + self.records.remove(record); + return; + } _(records[0]).each(function (value, key) { record.set(key, value, {silent: true}); }); diff --git a/addons/web/static/test/list.js b/addons/web/static/test/list.js new file mode 100644 index 00000000000..63cc16a5022 --- /dev/null +++ b/addons/web/static/test/list.js @@ -0,0 +1,68 @@ +$(document).ready(function () { + var instance; + var $fix = $('#qunit-fixture'); + + module('list.buttons', { + setup: function () { + instance = openerp.testing.instanceFor('list'); + + openerp.testing.loadTemplate(instance); + + openerp.testing.mockifyRPC(instance); + } + }); + asyncTest('record-deletion', 2, function () { + instance.session.responses['/web/view/load'] = function () { + return {result: { + type: 'tree', + fields: { + a: {type: 'char', string: "A"} + }, + arch: { + tag: 'tree', + attrs: { }, + children: [ + {tag: 'field', attrs: {name: 'a'}}, + {tag: 'button', attrs: {type: 'object', name: 'foo'}} + ] + } + }}; + }; + instance.session.responses['/web/dataset/call_kw:read'] = function (req) { + var args = req.params.args[0]; + if (_.isEqual(args, [1, 2, 3])) { + return {result: [ + {id: 1, a: 'foo'}, {id: 2, a: 'bar'}, {id: 3, a: 'baz'} + ]}; + } else if (_.isEqual(args, [2])) { + // button action virtually removed record + return {result: []}; + } + throw new Error(JSON.stringify(req.params)); + }; + instance.session.responses['/web/dataset/call_button'] = function () { + return {result: false}; + }; + var ds = new instance.web.DataSetStatic(null, 'demo', null, [1, 2, 3]); + var l = new instance.web.ListView({}, ds, false, {editable: 'top'}); + l.appendTo($fix) + .then(l.proxy('reload_content')) + .then(function () { + var d = $.Deferred(); + l.records.bind('remove', function () { + d.resolve(); + }); + $fix.find('table tbody tr:eq(1) button').click(); + return d.promise(); + }) + .always(function () { start(); }) + .then(function () { + strictEqual(l.records.length, 2, + "should have 2 records left"); + strictEqual($fix.find('table tbody tr[data-id]').length, 2, + "should have 2 rows left"); + }, function (e) { + ok(false, e && e.message || e); + }); + }); +}); diff --git a/addons/web/static/test/test.html b/addons/web/static/test/test.html index 185125659cc..275db0f37a7 100644 --- a/addons/web/static/test/test.html +++ b/addons/web/static/test/test.html @@ -58,5 +58,6 @@ +