[REF] base_import: adapt code after jQuery update
Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Aaron Bohy
Christophe Matthieu
Mathieu Duckerts-Antoine
David Monjoie
Martin Geubelle
svs-odoo
parent
0ab6a62997
commit
8b603cfdb6
@@ -152,7 +152,7 @@ var DataImport = AbstractAction.extend({
|
||||
}).then(function (result) {
|
||||
self.importTemplates = result;
|
||||
});
|
||||
return $.when(this._super.apply(this, arguments), def);
|
||||
return Promise.all([this._super.apply(this, arguments), def]);
|
||||
},
|
||||
start: function () {
|
||||
var self = this;
|
||||
@@ -162,9 +162,9 @@ var DataImport = AbstractAction.extend({
|
||||
this.setup_float_format_picker();
|
||||
this.setup_date_format_picker();
|
||||
|
||||
return $.when(
|
||||
return Promise.all([
|
||||
this._super(),
|
||||
self.create_model().done(function (id) {
|
||||
self.create_model().then(function (id) {
|
||||
self.id = id;
|
||||
self.$('input[name=import_id]').val(id);
|
||||
|
||||
@@ -173,8 +173,8 @@ var DataImport = AbstractAction.extend({
|
||||
cp_content: {$buttons: self.$buttons},
|
||||
};
|
||||
self.updateControlPanel(status);
|
||||
})
|
||||
);
|
||||
}),
|
||||
]);
|
||||
},
|
||||
create_model: function() {
|
||||
return this._rpc({
|
||||
@@ -346,7 +346,7 @@ var DataImport = AbstractAction.extend({
|
||||
method: 'parse_preview',
|
||||
args: [this.id, this.import_options()],
|
||||
kwargs: {context: session.user_context},
|
||||
}).done(function (result) {
|
||||
}).then(function (result) {
|
||||
var signal = result.error ? 'preview_failed' : 'preview_succeeded';
|
||||
self[signal](result);
|
||||
});
|
||||
@@ -567,7 +567,9 @@ var DataImport = AbstractAction.extend({
|
||||
method: 'do',
|
||||
args: [this.id, fields, columns, this.import_options()],
|
||||
kwargs : kwargs,
|
||||
}).then(null, function (error, event) {
|
||||
}).then(null, function (reason) {
|
||||
var error = reason.message;
|
||||
var event = reason.event;
|
||||
// In case of unexpected exception, convert
|
||||
// "JSON-RPC error" to an import failure, and
|
||||
// prevent default handling (warning dialog)
|
||||
@@ -588,7 +590,7 @@ var DataImport = AbstractAction.extend({
|
||||
|| error.message;
|
||||
}
|
||||
|
||||
return $.when({'messages': [{
|
||||
return Promise.resolve({'messages': [{
|
||||
type: 'error',
|
||||
record: false,
|
||||
message: msg,
|
||||
@@ -596,12 +598,14 @@ var DataImport = AbstractAction.extend({
|
||||
}) ;
|
||||
},
|
||||
onvalidate: function () {
|
||||
return this.call_import({ dryrun: true, tracking_disable: true })
|
||||
.done(this.proxy('validated'));
|
||||
var prom = this.call_import({ dryrun: true, tracking_disable: true });
|
||||
prom.then(this.proxy('validated'));
|
||||
return prom;
|
||||
},
|
||||
onimport: function () {
|
||||
var self = this;
|
||||
return this.call_import({ dryrun: false }).done(function (results) {
|
||||
var prom = this.call_import({ dryrun: false });
|
||||
prom.then(function (results) {
|
||||
var message = results.messages;
|
||||
if (!_.any(message, function (message) {
|
||||
return message.type === 'error'; })) {
|
||||
@@ -610,6 +614,7 @@ var DataImport = AbstractAction.extend({
|
||||
}
|
||||
self['import_failed'](results);
|
||||
});
|
||||
return prom;
|
||||
},
|
||||
onimported: function (event, from, to, results) {
|
||||
this.do_notify(_t("Import completed"), _.str.sprintf(_t("%d records were successfully imported"), results.ids.length));
|
||||
|
||||
@@ -19,10 +19,10 @@ QUnit.module('Base Import Mobile Tests', {
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('import button should be hidden in list on mobile screens', function (assert) {
|
||||
QUnit.test('import button should be hidden in list on mobile screens', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var list = createView({
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
@@ -34,10 +34,10 @@ QUnit.test('import button should be hidden in list on mobile screens', function
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('import button should be hidden in kanban on mobile screens', function (assert) {
|
||||
QUnit.test('import button should be hidden in kanban on mobile screens', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var kanban = createView({
|
||||
var kanban = await createView({
|
||||
View: KanbanView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
|
||||
@@ -22,31 +22,31 @@ QUnit.module('Base Import Tests', {
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('add import button in list', function(assert) {
|
||||
QUnit.test('add import button in list', async function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var list = createView({
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree><field name="foo"/></tree>',
|
||||
});
|
||||
|
||||
assert.ok(list.$buttons.find('.o_button_import:contains(Import)').is(':visible'),
|
||||
assert.isVisible(list.$buttons.find('.o_button_import:contains(Import)'),
|
||||
"should have a visible Import button");
|
||||
|
||||
testUtils.mock.intercept(list, 'do_action', function() {
|
||||
assert.ok(true, "should have triggered a do_action");
|
||||
});
|
||||
|
||||
testUtils.dom.click(list.$buttons.find('.o_button_import:contains(Import)'));
|
||||
await testUtils.dom.click(list.$buttons.find('.o_button_import:contains(Import)'));
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('list without import button', function(assert) {
|
||||
QUnit.test('list without import button', async function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var list = createView({
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
@@ -56,14 +56,14 @@ QUnit.test('list without import button', function(assert) {
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(!list.$buttons.find('.o_button_import').length, "should not have an Import button");
|
||||
assert.containsNone(list.$buttons, '.o_button_import', 'should not have an Import button');
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('add import button in kanban', function(assert) {
|
||||
QUnit.test('add import button in kanban', async function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var kanban = createView({
|
||||
var kanban = await createView({
|
||||
View: KanbanView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
@@ -74,21 +74,21 @@ QUnit.test('add import button in kanban', function(assert) {
|
||||
'</t></templates></kanban>',
|
||||
});
|
||||
|
||||
assert.ok(kanban.$buttons.find('.o_button_import:contains(Import)').is(':visible'),
|
||||
assert.isVisible(kanban.$buttons.find('.o_button_import:contains(Import)'),
|
||||
"should have a visible Import button");
|
||||
|
||||
testUtils.mock.intercept(kanban, 'do_action', function() {
|
||||
assert.ok(true, "should have triggered a do_action");
|
||||
});
|
||||
|
||||
testUtils.dom.click(kanban.$buttons.find('.o_button_import:contains(Import)'));
|
||||
await testUtils.dom.click(kanban.$buttons.find('.o_button_import:contains(Import)'));
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('kanban without import button', function(assert) {
|
||||
QUnit.test('kanban without import button', async function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var kanban = createView({
|
||||
var kanban = await createView({
|
||||
View: KanbanView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
@@ -102,7 +102,7 @@ QUnit.test('kanban without import button', function(assert) {
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(!kanban.$buttons.find('.o_button_import').length, "should not have an Import button");
|
||||
assert.containsNone(kanban.$buttons, '.o_button_import', "should not have an Import button");
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user