[FIX] listview display when action button deletes the corresponding record

if a record has disappeared between activating a button and refreshing
the record, remove it from the list view

lp bug: https://launchpad.net/bugs/1042718 fixed

bzr revid: xmo@openerp.com-20121113104407-n924vinluqfdtesf
This commit is contained in:
Xavier Morel 2012-11-13 11:44:07 +01:00
parent 7d745f7195
commit 22edf6193d
3 changed files with 74 additions and 0 deletions

View File

@ -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});
});

View File

@ -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);
});
});
});

View File

@ -58,5 +58,6 @@
<script type="text/javascript" src="/web/static/test/evals.js"></script>
<script type="text/javascript" src="/web/static/test/search.js"></script>
<script type="text/javascript" src="/web/static/test/Widget.js"></script>
<script type="text/javascript" src="/web/static/test/list.js"></script>
<script type="text/javascript" src="/web/static/test/list-editable.js"></script>
</html>