Skip to content

Commit c35a3ec

Browse files
author
Reanova Migration
committed
[MIG] base_import_async: Migration to 19.0
- bump version 18.0.1.0.0 -> 19.0.1.0.0 - installable False -> True - remove @api.returns("ir.attachment") decorator on _create_csv_attachment (decorator no longer supported in V19; the method already returns an ir.attachment recordset, so the decorator was redundant) - replace _() with self.env._() (W8161 prefer-env-translation) - use kwarg form of self.env._() instead of % formatting (W8301 translation-not-lazy); rename %(from)s/%(to)s to %(row_from)s/%(row_to)s to use as kwargs (from is a Python reserved word) - remove unused imports (_, api) - mark BaseImportImport with # pylint: disable=no-wizard-in-models (TransientModel extends core base_import.import which is itself in models/, following the upstream convention) - remove module from .pre-commit-config.yaml NOT INSTALLABLE list - add odoo-addon-base_import_async==19.0.* to setup/_metapackage dependencies Tested on a V19 install with a 35k-row partner CSV: import is correctly queued as a queue.job and processed in background. The ir.attachment returned by _create_csv_attachment is properly linked to the queue job (res_model="queue.job"). Note: queue_job_cron was dropped from this PR because its test_queue_job_cron_callback test fails on V19 due to an internal cr.commit() in ir.cron._callback (V19 forbids commit/rollback inside TransactionCase tests). That migration needs a separate PR with a test refactor (savepoint-based or testing-bus-mock based).
1 parent ebb87ea commit c35a3ec

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4-
^base_import_async/|
54
^queue_job_batch/|
65
^queue_job_cron/|
76
^queue_job_cron_jobrunner/|

base_import_async/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Asynchronous Import",
77
"summary": "Import CSV files in the background",
8-
"version": "18.0.1.0.0",
8+
"version": "19.0.1.0.0",
99
"author": "Akretion, ACSONE SA/NV, Odoo Community Association (OCA)",
1010
"license": "AGPL-3",
1111
"website": "https://github.com/OCA/queue",
@@ -20,6 +20,6 @@
2020
"base_import_async/static/src/xml/import_data_sidepanel.xml",
2121
],
2222
},
23-
"installable": False,
23+
"installable": True,
2424
"development_status": "Production/Stable",
2525
}

base_import_async/models/base_import_import.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from io import BytesIO, StringIO, TextIOWrapper
1010
from os.path import splitext
1111

12-
from odoo import _, api, models
12+
from odoo import models
1313
from odoo.models import fix_import_export_id_paths
1414

1515
from odoo.addons.base_import.models.base_import import ImportValidationError
@@ -30,6 +30,7 @@
3030
DEFAULT_CHUNK_SIZE = 100
3131

3232

33+
# pylint: disable=no-wizard-in-models
3334
class BaseImportImport(models.TransientModel):
3435
_inherit = "base_import.import"
3536

@@ -55,10 +56,11 @@ def execute_import(self, fields, columns, options, dryrun=False):
5556
translated_model_name = search_result[0][1]
5657
else:
5758
translated_model_name = self._description
58-
description = _("Import %(model)s from file %(from_file)s") % {
59-
"model": translated_model_name,
60-
"from_file": self.file_name,
61-
}
59+
description = self.env._(
60+
"Import %(model)s from file %(from_file)s",
61+
model=translated_model_name,
62+
from_file=self.file_name,
63+
)
6264
attachment = self._create_csv_attachment(
6365
import_fields, data, options, self.file_name
6466
)
@@ -78,7 +80,6 @@ def _link_attachment_to_job(self, delayed_job, attachment):
7880
)
7981
attachment.write({"res_model": "queue.job", "res_id": queue_job.id})
8082

81-
@api.returns("ir.attachment")
8283
def _create_csv_attachment(self, fields, data, options, file_name):
8384
# write csv
8485
f = StringIO()
@@ -155,16 +156,15 @@ def _split_file(
155156
model_obj, fields, data, chunk_size
156157
):
157158
chunk = str(priority - INIT_PRIORITY).zfill(padding)
158-
description = _(
159+
description = self.env._(
159160
"Import %(model)s from file %(file_name)s - "
160-
"#%(chunk)s - lines %(from)s to %(to)s"
161-
) % {
162-
"model": translated_model_name,
163-
"file_name": file_name,
164-
"chunk": chunk,
165-
"from": row_from + 1 + header_offset,
166-
"to": row_to + 1 + header_offset,
167-
}
161+
"#%(chunk)s - lines %(row_from)s to %(row_to)s",
162+
model=translated_model_name,
163+
file_name=file_name,
164+
chunk=chunk,
165+
row_from=row_from + 1 + header_offset,
166+
row_to=row_to + 1 + header_offset,
167+
)
168168
# create a CSV attachment and enqueue the job
169169
root, ext = splitext(file_name)
170170
attachment = self._create_csv_attachment(

base_import_async/models/queue_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017 ACSONE SA/NV
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, models
4+
from odoo import models
55

66

77
class QueueJob(models.Model):
@@ -11,7 +11,7 @@ class QueueJob(models.Model):
1111

1212
def _related_action_attachment(self):
1313
return {
14-
"name": _("Attachment"),
14+
"name": self.env._("Attachment"),
1515
"type": "ir.actions.act_window",
1616
"res_model": "ir.attachment",
1717
"view_mode": "form",

setup/_metapackage/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "odoo-addons-oca-queue"
33
version = "19.0.20260104.0"
44
dependencies = [
5+
"odoo-addon-base_import_async==19.0.*",
56
"odoo-addon-queue_job==19.0.*",
67
"odoo-addon-test_queue_job==19.0.*",
78
]

0 commit comments

Comments
 (0)