Skip to content

Commit af3b019

Browse files
[18.0][MIG] base_export_async: migrate
1 parent 7564bed commit af3b019

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

base_export_async/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Base Export Async",
66
"summary": "Asynchronous export with job queue",
7-
"version": "16.0.1.1.0",
7+
"version": "18.0.1.0.0",
88
"license": "AGPL-3",
99
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/queue",

base_export_async/data/cron.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
<field name="code">model.cron_delete()</field>
88
<field name='interval_number'>1</field>
99
<field name='interval_type'>days</field>
10-
<field name="numbercall">-1</field>
1110
</record>
1211
</odoo>

base_export_async/models/delay_export.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
from dateutil.relativedelta import relativedelta
99

10-
from odoo import _, api, fields, models
10+
from odoo import api, fields, models
1111
from odoo.exceptions import UserError
12+
from odoo.http import request
1213

1314
from odoo.addons.web.controllers.export import CSVExport, ExcelExport
1415

@@ -27,7 +28,7 @@ def delay_export(self, data):
2728
"""Delay the export, called from js"""
2829
params = json.loads(data.get("data"))
2930
if not self.env.user.email:
30-
raise UserError(_("You must set an email address to your user."))
31+
raise UserError(self.env._("You must set an email address to your user."))
3132
self.with_delay().export(params)
3233

3334
@api.model
@@ -59,10 +60,12 @@ def _get_file_content(self, params):
5960

6061
if export_format == "csv":
6162
csv = CSVExport()
62-
return csv.from_data(columns_headers, import_data)
63+
return csv.from_data(field_names, columns_headers, import_data).encode(
64+
"utf-8"
65+
)
6366
else:
6467
xls = ExcelExport()
65-
return xls.from_data(columns_headers, import_data)
68+
return xls.from_data(field_names, columns_headers, import_data)
6669

6770
@api.model
6871
def export(self, params):
@@ -80,6 +83,10 @@ def export(self, params):
8083
* import_compat: if the export is export/import compatible (boolean)
8184
* user_ids: optional list of user ids who receive the file
8285
"""
86+
87+
# `ExportXlsxWriter` gets the environment from `request.env`
88+
if request:
89+
request.update_env(user=self.env.user)
8390
content = self._get_file_content(params)
8491

8592
items = operator.itemgetter("model", "context", "format", "user_ids")(params)

base_export_async/static/src/js/data_export.esm.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {ExportDataDialog} from "@web/views/view_dialogs/export_data_dialog";
22
import {patch} from "@web/core/utils/patch";
33

4-
patch(ExportDataDialog.prototype, "base_export_async", {
4+
patch(ExportDataDialog.prototype, {
5+
patchName: "base_export_async",
56
setup() {
6-
this._super();
7+
super.setup();
78
this.state.async = false;
89
},
910
onToggleExportAsync(value) {

base_export_async/static/src/js/list_controller.esm.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {blockUI, unblockUI} from "web.framework";
2-
3-
import Dialog from "web.Dialog";
1+
import {AlertDialog} from "@web/core/confirmation_dialog/confirmation_dialog";
42
import {ListController} from "@web/views/list/list_controller";
5-
import {_t} from "web.core";
3+
import {_t} from "@web/core/l10n/translation";
64
import {download} from "@web/core/network/download";
75
import {patch} from "@web/core/utils/patch";
86

9-
patch(ListController.prototype, "base_export_async", {
7+
patch(ListController.prototype, {
8+
patchName: "base_export_async",
109
async downloadExport(fields, import_compat, format, async = false) {
10+
const uiService = this.env.services.ui;
1111
let ids = false;
1212
if (!this.isDomainSelected) {
1313
const resIds = await this.getSelectedResIds();
@@ -26,7 +26,7 @@ patch(ListController.prototype, "base_export_async", {
2626
/*
2727
Call the delay export if Async is checked
2828
*/
29-
blockUI();
29+
uiService.block();
3030
const args = [
3131
{
3232
data: JSON.stringify({
@@ -42,14 +42,14 @@ patch(ListController.prototype, "base_export_async", {
4242
},
4343
];
4444
const orm = this.env.services.orm;
45-
orm.call("delay.export", "delay_export", args).then(function () {
46-
unblockUI();
47-
Dialog.alert(
48-
this,
49-
_t(
45+
orm.call("delay.export", "delay_export", args).then(() => {
46+
uiService.unblock();
47+
this.env.services.dialog.add(AlertDialog, {
48+
title: _t("Exported Files"),
49+
body: _t(
5050
"You will receive the export file by email as soon as it is finished."
51-
)
52-
);
51+
),
52+
});
5353
});
5454
} else {
5555
await download({

0 commit comments

Comments
 (0)