Skip to content

Commit 4b856ea

Browse files
committed
[IMP] export_bg: integrate get_export_threshold method for record limit in export
closes #340 Signed-off-by: Joaquín Arroyo (ADV) <joa@adhoc.inc>
1 parent b1072c0 commit 4b856ea

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

export_bg/models/export_bg_mixin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44

55
from markupsafe import Markup
6-
from odoo import _, models
6+
from odoo import _, api, models
77
from odoo.addons.web.controllers.export import CSVExport
88
from odoo.tools.misc import xlsxwriter
99

@@ -12,6 +12,11 @@ class IrModel(models.Model):
1212
_name = "ir.model"
1313
_inherit = ["ir.model", "base.bg"]
1414

15+
@api.model
16+
def get_export_threshold(self):
17+
"""Get the threshold for background export without requiring admin permissions."""
18+
return int(self.env["ir.config_parameter"].sudo().get_param("export_bg.record_threshold", "500"))
19+
1520
def _prepare_export_data(self, data):
1621
params = json.loads(data)
1722
Model = self.env[params["model"]].with_context(**params.get("context", {}))

export_bg/static/src/views/list_controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/** @odoo-module **/
22

3-
import { ListController } from "@web/views/list/list_controller";
43
import { patch } from "@web/core/utils/patch";
4+
import { ListController } from "@web/views/list/list_controller";
55

66
patch(ListController.prototype, {
77
async downloadExport(fields, import_compat, format) {
88
const resIds = this.isDomainSelected ? false : await this.getSelectedResIds();
99
const recordCount = resIds ? resIds.length : (this.model.root.count || 0);
1010

1111
const threshold = await this.model.orm.call(
12-
"ir.config_parameter",
13-
"get_param",
14-
["export_bg.record_threshold", "500"]
12+
"ir.model",
13+
"get_export_threshold",
14+
[]
1515
);
1616

17-
if (recordCount > parseInt(threshold)) {
17+
if (recordCount > threshold) {
1818
const data = {
1919
model: this.props.resModel,
2020
fields: fields,

0 commit comments

Comments
 (0)