Skip to content

Commit

Permalink
[MIG] base_export_async: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coronel committed Jul 11, 2023
1 parent 6e4a890 commit a2a2dc1
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 97 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_export_async/|
^queue_job_subscribe/|
^test_base_import_async/|
# END NOT INSTALLABLE ADDONS
Expand Down
7 changes: 3 additions & 4 deletions base_export_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Base Export Async",
"summary": "Asynchronous export with job queue",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
Expand All @@ -18,10 +18,9 @@
],
"demo": [],
"assets": {
"web.assets_qweb": [
"base_export_async/static/src/xml/base.xml",
],
"web.assets_backend": [
"base_export_async/static/src/xml/base.xml",
"base_export_async/static/src/js/list_controller.js",
"base_export_async/static/src/js/data_export.js",
],
},
Expand Down
3 changes: 1 addition & 2 deletions base_export_async/models/delay_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError

from odoo.addons.web.controllers.main import CSVExport, ExcelExport
from odoo.addons.web.controllers.export import CSVExport, ExcelExport


class DelayExport(models.Model):

_name = "delay.export"
_description = "Asynchronous Export"

Expand Down
30 changes: 30 additions & 0 deletions base_export_async/static/src/js/data_export.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @odoo-module */

import {ExportDataDialog} from "@web/views/view_dialogs/export_data_dialog";
import {patch} from "@web/core/utils/patch";

patch(ExportDataDialog.prototype, "base_export_async", {
setup() {
this._super();
this.state.async = false;
},
onToggleExportAsync(value) {
this.state.async = value;
},
async onClickExportButton() {
if (!this.state.exportList.length) {
return this.notification.add(
this.env._t("Please select fields to save export list..."),
{
type: "danger",
}
);
}
await this.props.download(
this.state.exportList,
this.state.isCompatible,
this.availableFormats[this.state.selectedFormat].tag,
this.state.async
);
},
});
74 changes: 0 additions & 74 deletions base_export_async/static/src/js/data_export.js

This file was deleted.

73 changes: 73 additions & 0 deletions base_export_async/static/src/js/list_controller.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** @odoo-module **/

import {download} from "@web/core/network/download";
import {ListController} from "@web/views/list/list_controller";
import {patch} from "@web/core/utils/patch";
import framework from "@web.framework";
import Dialog from "@web.Dialog";
import core from "@web.core";
const _t = core._t;

patch(ListController.prototype, "base_export_async", {
async downloadExport(fields, import_compat, format, async = false) {
let ids = false;
if (!this.isDomainSelected) {
const resIds = await this.getSelectedResIds();
ids = resIds.length > 0 && resIds;
}
const exportedFields = fields.map((field) => ({
name: field.name || field.id,
label: field.label || field.string,
store: field.store,
type: field.field_type || field.type,
}));
if (import_compat) {
exportedFields.unshift({name: "id", label: this.env._t("External ID")});
}
if (async) {
/*
Call the delay export if Async is checked
*/
framework.blockUI();
const args = [
{
data: JSON.stringify({
format: format,
model: this.model.root.resModel,
fields: exportedFields,
ids: ids,
domain: this.model.root.domain,
context: this.props.context,
import_compat: import_compat,
user_ids: [this.props.context.uid],
}),
},
];
const orm = this.env.services.orm;
orm.call("delay.export", "delay_export", args).then(function () {
framework.unblockUI();
Dialog.alert(
this,
_t(
"You will receive the export file by email as soon as it is finished."
)
);
});
} else {
await download({
data: {
data: JSON.stringify({
import_compat,
context: this.props.context,
domain: this.model.root.domain,
fields: exportedFields,
groupby: this.model.root.groupBy,
ids,
model: this.model.root.resModel,
}),
},
url: `/web/export/${format}`,
});
}
},
});
31 changes: 15 additions & 16 deletions base_export_async/static/src/xml/base.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<templates xml:space="preserve">

<t t-extend="ExportDialog">
<t t-jquery="div.o_import_compat" t-operation="after">
<div class="form-check">
<input
class="form-check-input"
id="async_export"
type="checkbox"
name="async_export"
/>
<label class="form-check-label" for="async_export">
<strong
>Asynchronous export </strong> (You will receive the export by email)
</label>
</div>
</t>
<t
t-name="base_export_async.ExportDataDialogAsync"
t-inherit="web.ExportDataDialog"
t-inherit-mode="extension"
>
<xpath expr="//div[hasclass('o_import_compat')]" position="after">
<CheckBox
id="async_export"
value="state.async"
onChange.bind="onToggleExportAsync"
>
<strong>Asynchronous export </strong> (You will receive the export by email)
</CheckBox>
</xpath>
</t>

</templates>
1 change: 1 addition & 0 deletions setup/base_export_async/odoo/addons/base_export_async
6 changes: 6 additions & 0 deletions setup/base_export_async/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit a2a2dc1

Please sign in to comment.