Skip to content

Commit bad3469

Browse files
authored
Merge pull request #607 from OpenSPP/async_importing_fix
fix async importing
2 parents be7f4c0 + ab01ced commit bad3469

File tree

1 file changed

+46
-79
lines changed

1 file changed

+46
-79
lines changed
Lines changed: 46 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,49 @@
1-
odoo.define("spp_import_match.import", function (require) {
2-
var rpc = require("web.rpc");
3-
var DataImport = require("base_import.import").DataImport;
4-
5-
DataImport.include({
6-
events: _.extend({}, DataImport.prototype.events, {
7-
"change input.oe_import_match": "_onImportMatchChanges",
8-
}),
9-
10-
init: function () {
11-
this._super.apply(this, arguments);
12-
this.importMatchIds = [];
13-
},
14-
15-
import_options: function () {
16-
var options = this._super.apply(this, arguments);
17-
options.use_queue = this.$("input.oe_import_queue").prop("checked");
18-
options.import_match_ids = this.importMatchIds;
19-
return options;
20-
},
21-
22-
onimported: function () {
23-
if (this.$("input.oe_import_queue").prop("checked")) {
24-
this.displayNotification({
25-
title: "Your request is being processed",
26-
message: "You can check the status of this job in menu 'Queue / Jobs'.",
27-
type: "success",
28-
});
29-
this.exit();
30-
} else {
31-
this._super.apply(this, arguments);
32-
}
33-
},
34-
35-
exit: function () {
36-
this.trigger_up("history_back");
37-
},
38-
39-
start: function () {
40-
var sup = this._super.apply(this, arguments);
41-
this.setup_import_match_selection();
42-
return sup;
43-
},
44-
45-
setup_import_match_selection: function () {
46-
var self = this;
47-
48-
rpc.query({
49-
model: "spp.import.match",
50-
method: "search_read",
51-
args: [[["model_id.model", "=", this.res_model]]],
52-
fields: ["id", "name"],
53-
}).then(function (data) {
54-
if (data.length <= 0) {
55-
self.$("div#oe_config_import_matching").hide();
56-
return;
57-
}
58-
var content = "";
59-
for (const [, value] of Object.entries(data)) {
60-
const id_for_label = "o_config_checkbox_import_match_" + value.id;
61-
content += `
62-
<div class="custom-control custom-checkbox">
63-
<input type="checkbox" id="${id_for_label}" class="custom-control-input oe_import_match"/>
64-
<label for="${id_for_label}" class="custom-control-label o_form_label">${value.name}</label>
65-
</div>`;
66-
}
67-
self.$("div#oe_import_match").html(content);
1+
/** @odoo-module */
2+
import {BaseImportModel} from "@base_import/import_model";
3+
import {patch} from "@web/core/utils/patch";
4+
import {_t} from "@web/core/l10n/translation";
5+
6+
patch(BaseImportModel.prototype, {
7+
setup() {
8+
super.setup();
9+
},
10+
11+
async _callImport(dryrun, args) {
12+
try {
13+
const res = await this.orm.silent.call("base_import.import", "execute_import", args, {
14+
dryrun,
15+
context: {
16+
...this.context,
17+
tracking_disable: this.importOptions.tracking_disable,
18+
},
6819
});
69-
},
70-
71-
_onImportMatchChanges: function (ev) {
72-
const targetIdSplited = ev.target.id.split("_");
73-
const importMatchId = parseInt(targetIdSplited[targetIdSplited.length - 1], 10);
74-
const importMatchIdIndex = this.importMatchIds.indexOf(importMatchId);
75-
if (importMatchIdIndex === -1) {
76-
this.importMatchIds.push(importMatchId);
77-
} else {
78-
this.importMatchIds.splice(importMatchIdIndex, 1);
20+
if ("async" in res) {
21+
if (res.async === true) {
22+
this.displayNotification(_t("Successfully added on Queue"));
23+
history.go(-1);
24+
}
7925
}
80-
},
81-
});
26+
console.log(res);
27+
return res;
28+
} catch (error) {
29+
// This pattern isn't optimal but it is need to have
30+
// similar behaviours as in legacy. That is, catching
31+
// all import errors and showing them inside the top
32+
// "messages" area.
33+
return {error};
34+
}
35+
},
36+
37+
displayNotification(message) {
38+
this.env.services.action.doAction({
39+
type: "ir.actions.client",
40+
tag: "display_notification",
41+
params: {
42+
title: "Queued",
43+
message: message,
44+
type: "success",
45+
sticky: false,
46+
},
47+
});
48+
},
8249
});

0 commit comments

Comments
 (0)