diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 17e1a04cf7a..1c1c4cc0dfd 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -232,7 +232,9 @@ openerp.web.list_editable = function (instance) { event = event || {}; this.trigger(event_name + ':before', event); if (event.cancel) { - return $.Deferred().reject(); + return $.Deferred().reject({ + message: _.str.sprintf("Event %s:before cancelled", + event_name)}); } return $.when(action.apply(this.editor, args || [])).then(function () { self.trigger.apply(self, [event_name + ':after'] @@ -424,7 +426,8 @@ openerp.web.list_editable = function (instance) { var record = this.record; this.record = null; if (!this.form.can_be_discarded()) { - return $.Deferred().reject().promise(); + return $.Deferred().reject({ + message: "The form's data can not be discarded"}).promise(); } this.form.do_hide(); return $.when(record); diff --git a/addons/web/static/test/list-editable.js b/addons/web/static/test/list-editable.js index 4a8fbae1094..62d9d82ae83 100644 --- a/addons/web/static/test/list-editable.js +++ b/addons/web/static/test/list-editable.js @@ -37,4 +37,66 @@ $(document).ready(function () { "should use default form type"); }); }); + asyncTest('toggle-edition-new', function () { + instance.connection.responses['/web/dataset/call_kw:create'] = function () { + return { result: 42 }; + }; + instance.connection.responses['/web/dataset/call_kw:read'] = function () { + return { result: [{ + id: 42, + a: false, + b: false, + c: false + }]}; + }; + var e = new instance.web.list.Editor({ + do_warn: function (e) { + warning = e; + }, + dataset: new instance.web.DataSetSearch(), + isPrependOnCreate: function () { return false; }, + editionView: function () { + return { + arch: { + tag: 'form', + attrs: { + version: '7.0', + 'class': 'oe_form_container' + }, + children: [ + {tag: 'field', attrs: {name: 'a'}}, + {tag: 'field', attrs: {name: 'b'}}, + {tag: 'field', attrs: {name: 'c'}} + ] + }, + fields: { + a: {type: 'char'}, + b: {type: 'char'}, + c: {type: 'char'} + } + }; + } + }); + var counter = 0; + var warning = null; + e.appendTo($fix) + .pipe(function () { + return e.edit(null, function () { + ++counter; + }); + }) + .pipe(function (form) { + ok(e.isEditing(), "editor is now editing"); + equal(counter, 3, "all fields have been configured"); + strictEqual(form, e.form); + return e.save(); + }) + .always(start) + .fail(function (error) { ok(false, error && error.message); }) + .done(function (record) { + ok(!warning, "should have received no warning"); + ok(!e.isEditing(), "should have stopped editing"); + equal(record.id, 42, "should have newly created id"); + }) + }); }); diff --git a/addons/web/static/test/testing.js b/addons/web/static/test/testing.js index 5b6e27700ab..e9525fc82a0 100644 --- a/addons/web/static/test/testing.js +++ b/addons/web/static/test/testing.js @@ -55,11 +55,16 @@ openerp.testing = (function () { var connection = instance.connection; connection.responses = responses || {}; connection.rpc_function = function (url, payload) { - if (!(url.url in this.responses)) { + var fn = this.responses[url.url + ':' + payload.params.method] + || this.responses[url.url]; + + if (!fn) { return $.Deferred().reject({}, 'failed', - _.str.sprintf("Url %s not found in mock responses", url.url)).promise(); + _.str.sprintf("Url %s not found in mock responses, with arguments %s", + url.url, JSON.stringify(payload.params)) + ).promise(); } - return $.when(this.responses[url.url](payload)); + return $.when(fn(payload)); }; }, /**