From 507bc0abc74b083c63906bff5f6ff5de0098d863 Mon Sep 17 00:00:00 2001 From: Manh Nguyen Date: Fri, 30 Oct 2026 14:12:29 +0700 Subject: [PATCH] [FIX] base_import_async: use the batch limit of the import dialog as chunk size The import dialog sends the batch size as options["limit"], but the module read options["chunk_size"], which nothing sends. Background imports were always split in chunks of 100 lines. Port of #878 (16.0). --- .../models/base_import_import.py | 2 +- .../tests/test_base_import_import.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/base_import_async/models/base_import_import.py b/base_import_async/models/base_import_import.py index f77a4bbc59..833b31e08b 100644 --- a/base_import_async/models/base_import_import.py +++ b/base_import_async/models/base_import_import.py @@ -20,9 +20,9 @@ OPT_SEPARATOR = "separator" OPT_QUOTING = "quoting" OPT_ENCODING = "encoding" +OPT_CHUNK_SIZE = "limit" # options defined in base_import_async/import.js OPT_USE_QUEUE = "use_queue" -OPT_CHUNK_SIZE = "chunk_size" # option not available in UI, but usable from scripts OPT_PRIORITY = "priority" diff --git a/base_import_async/tests/test_base_import_import.py b/base_import_async/tests/test_base_import_import.py index 4a815d6707..8025d62fd4 100644 --- a/base_import_async/tests/test_base_import_import.py +++ b/base_import_async/tests/test_base_import_import.py @@ -3,6 +3,8 @@ from odoo.tests.common import RecordCapturer, TransactionCase +from odoo.addons.queue_job.tests.common import trap_jobs + from ..models.base_import_import import OPT_USE_QUEUE @@ -97,3 +99,27 @@ def test_wrong_import_res_partners(self): opts, ) self.assertTrue(any(msg["type"] == "error" for msg in results["messages"])) + + def test_async_import_uses_batch_limit_as_chunk_size(self): + values = [["name"], ["partner 1"], ["partner 2"], ["partner 3"]] + import_wizard = self.import_wizard.create( + { + "res_model": self.res_partners._name, + "file": "\n".join([";".join(row) for row in values]), + "file_type": "text/csv", + "file_name": "partners.csv", + } + ) + # "limit" is the batch size set in the import dialog + opts = { + "quoting": '"', + "separator": ";", + "has_headers": True, + "limit": 1, + OPT_USE_QUEUE: True, + } + with trap_jobs() as trap: + import_wizard.execute_import(["name"], [], opts) + trap.assert_jobs_count(1, only=import_wizard._split_file) + trap.perform_enqueued_jobs() + trap.assert_jobs_count(3, only=import_wizard._import_one_chunk)