Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions export_bg/models/export_bg_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ def _export_chunk_bg(self, data, export_id, export_format):

# Extract field names considering import_compat mode
import_compat = params.get("import_compat", True)

# For field_names (data extraction), always use the technical field name
# Only use 'value' as fallback when import_compat=True (for import compatibility)
field_names = [f["name"] for f in params["fields"]]
if import_compat:
field_names = [f.get("name") or f.get("value") or f.get("id") for f in params["fields"]]
field_labels = field_names # Use field names as headers for import compatibility
field_labels = field_names
else:
# When not import_compat, use only 'name' or 'id' for field_names, not 'value'
field_names = [f.get("name") or f.get("id") for f in params["fields"]]
field_labels = [f.get("label") or f.get("string") for f in params["fields"]]
field_labels = [((f.get("label") or "").strip()) for f in params["fields"]]

export_data = self.export_data(field_names).get("datas", [])

Expand Down Expand Up @@ -97,20 +92,28 @@ def web_export(self, data, export_format):
The last job combines all chunks into the final export file.
"""
params = json.loads(data)
Model = self.env[params["model"]].with_context(**params.get("context", {}))
import_compat = params.get("import_compat", True)
Model = self.env[params["model"]].with_context(import_compat=import_compat, **params.get("context", {}))
ids = params.get("ids")
domain = params.get("domain", [])
records = Model.browse(ids) if ids else Model.search(domain)

export_id = str(uuid.uuid4())

return self.env["base.bg"].bg_enqueue_records(
records,
"_export_chunk_bg",
threshold=self.get_export_threshold(),
data=data,
export_id=export_id,
export_format=export_format,
# base.bg serializes its own env context into the job; propagate the
# exact model context used for export so nested relational fields are
# resolved exactly as in synchronous exports.
return (
self.env["base.bg"]
.with_context(**Model.env.context)
.bg_enqueue_records(
records,
"_export_chunk_bg",
threshold=self.get_export_threshold(),
data=data,
export_id=export_id,
export_format=export_format,
)
)

def _combine_chunks(self, export_id, export_format):
Expand Down
26 changes: 26 additions & 0 deletions export_bg/static/src/views/list_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @odoo-module **/

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

Expand Down Expand Up @@ -27,6 +28,10 @@ patch(ExportDataDialog.prototype, {
const exportedFields = this.state.exportList.map((field) => ({
string: field.label || field.string,
value: field.name || field.id,
name: field.name || field.id,
label: field.label || field.string,
store: field.store,
type: field.field_type || field.type,
}));

const data = {
Expand All @@ -38,6 +43,7 @@ patch(ExportDataDialog.prototype, {
domain: root.domain,
context: root.context,
import_compat: this.isCompatible,
groupby: root.groupBy,
};

this.state.disabled = true;
Expand All @@ -56,8 +62,28 @@ patch(ExportDataDialog.prototype, {
if (actionResult && actionResult.type) {
this.env.services.action.doAction(actionResult);
}

return { closeWizard: true };
} else {
await super.onClickExportButton();
}
},

async onExportData() {
let closeDialog;
const dialogProps = {
context: this.props.context,
defaultExportList: this.defaultExportList,
download: async (...args) => {
const result = await this.downloadExport(...args);
if (result && result.closeWizard && closeDialog) {
closeDialog();
}
return result;
},
getExportedFields: this.getExportedFields.bind(this),
root: this.model.root,
};
closeDialog = this.dialogService.add(ExportDataDialog, dialogProps);
},
});
Loading