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)