Skip to content
Open
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
2 changes: 1 addition & 1 deletion base_import_async/models/base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 26 additions & 0 deletions base_import_async/tests/test_base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Loading