Skip to content

Commit 2d9260a

Browse files
committed
[15.0][FIX][IMP]base_import_async
1 parent f02dd13 commit 2d9260a

File tree

8 files changed

+51
-40
lines changed

8 files changed

+51
-40
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
44
^base_export_async/|
5-
^base_import_async/|
65
^queue_job_subscribe/|
76
^test_base_import_async/|
87
# END NOT INSTALLABLE ADDONS

base_import_async/__manifest__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
{
66
"name": "Asynchronous Import",
77
"summary": "Import CSV files in the background",
8-
"version": "14.0.1.0.1",
8+
"version": "15.0.1.0.1",
99
"author": "Akretion, ACSONE SA/NV, Odoo Community Association (OCA)",
1010
"license": "AGPL-3",
1111
"website": "https://github.com/OCA/queue",
1212
"category": "Generic Modules",
1313
"depends": ["base_import", "queue_job"],
14-
"data": ["data/queue_job_function_data.xml", "views/base_import_async.xml"],
15-
"qweb": ["static/src/xml/import.xml"],
16-
"installable": False,
14+
"data": ["data/queue_job_function_data.xml"],
15+
"assets": {
16+
"web.assets_qweb": ["/base_import_async/static/src/xml/import.xml"],
17+
"web.assets_backend": ["/base_import_async/static/src/js/import.js"],
18+
},
19+
"installable": True,
1720
"development_status": "Production/Stable",
1821
}

base_import_async/models/base_import_import.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
class BaseImportImport(models.TransientModel):
3333
_inherit = "base_import.import"
3434

35-
def do(self, fields, columns, options, dryrun=False):
35+
def execute_import(self, fields, columns, options, dryrun=False):
3636
if dryrun or not options.get(OPT_USE_QUEUE):
3737
# normal import
38-
return super().do(fields, columns, options, dryrun=dryrun)
38+
return super().execute_import(fields, columns, options, dryrun=dryrun)
3939

4040
# asynchronous import
4141
try:
@@ -52,19 +52,23 @@ def do(self, fields, columns, options, dryrun=False):
5252
translated_model_name = search_result[0][1]
5353
else:
5454
translated_model_name = self._description
55-
description = _("Import %s from file %s") % (
56-
translated_model_name,
57-
self.file_name,
55+
description = _(
56+
"Import %(translated_model_name)s from file %(file_name)s",
57+
translated_model_name=translated_model_name,
58+
file_name=self.file_name,
5859
)
60+
file_name = self.file_name
61+
if not file_name.endswith(".csv"):
62+
file_name += ".csv"
5963
attachment = self._create_csv_attachment(
60-
import_fields, data, options, self.file_name
64+
import_fields, data, options, file_name
6165
)
6266
delayed_job = self.with_delay(description=description)._split_file(
6367
model_name=self.res_model,
6468
translated_model_name=translated_model_name,
6569
attachment=attachment,
6670
options=options,
67-
file_name=self.file_name,
71+
file_name=file_name,
6872
)
6973
self._link_attachment_to_job(delayed_job, attachment)
7074
return []
@@ -91,7 +95,12 @@ def _create_csv_attachment(self, fields, data, options, file_name):
9195
# create attachment
9296
datas = base64.encodebytes(f.getvalue().encode(encoding))
9397
attachment = self.env["ir.attachment"].create(
94-
{"name": file_name, "datas": datas}
98+
{
99+
"name": file_name,
100+
"datas": datas,
101+
"type": "binary",
102+
"mimetype": "text/csv",
103+
}
95104
)
96105
return attachment
97106

@@ -130,7 +139,7 @@ def _split_file(
130139
options,
131140
file_name="file.csv",
132141
):
133-
""" Split a CSV attachment in smaller import jobs """
142+
"""Split a CSV attachment in smaller import jobs"""
134143
model_obj = self.env[model_name]
135144
fields, data = self._read_csv_attachment(attachment, options)
136145
padding = len(str(len(data)))
@@ -144,13 +153,14 @@ def _split_file(
144153
model_obj, fields, data, chunk_size
145154
):
146155
chunk = str(priority - INIT_PRIORITY).zfill(padding)
147-
description = _("Import %s from file %s - #%s - lines %s to %s")
148-
description = description % (
149-
translated_model_name,
150-
file_name,
151-
chunk,
152-
row_from + 1 + header_offset,
153-
row_to + 1 + header_offset,
156+
description = _(
157+
"Import %(translated_model_name)s from file %(file_name)s"
158+
" - #%(chunk)s - lines %(row_from)s to %(row_to)s",
159+
translated_model_name=translated_model_name,
160+
file_name=file_name,
161+
chunk=chunk,
162+
row_from=row_from + 1 + header_offset,
163+
row_to=row_to + 1 + header_offset,
154164
)
155165
# create a CSV attachment and enqueue the job
156166
root, ext = splitext(file_name)

base_import_async/models/queue_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class QueueJob(models.Model):
8-
""" Job status and result """
8+
"""Job status and result"""
99

1010
_inherit = "queue.job"
1111

base_import_async/static/src/xml/import.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<templates>
3-
<t t-extend="ImportView">
3+
<t t-extend="ImportView.side_panel">
44
<t t-jquery="#oe_import_has_header" t-operation="before">
55
<div
66
title="When checked, the import will be executed as a background job,
77
after splitting your file in small chunks that will be processed independently.
88
Use this to import very large files."
99
>
10-
<input type="checkbox" class="oe_import_queue" id="oe_import_queue" />
11-
<label for="oe_import_queue">Import in the background</label>
10+
<input
11+
type="checkbox"
12+
class="oe_import_queue custom-control-input"
13+
id="oe_import_queue"
14+
/>
15+
<label
16+
for="oe_import_queue"
17+
class="custom-control-label"
18+
>Import in the background</label>
1219
</div>
1320
</t>
1421
</t>

base_import_async/views/base_import_async.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../base_import_async

setup/base_import_async/setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)