Skip to content

Commit 9376b49

Browse files
committed
[15.0][FIX][IMP]base_import_async
1 parent f02dd13 commit 9376b49

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
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: 14 additions & 6 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:
@@ -56,15 +56,18 @@ def do(self, fields, columns, options, dryrun=False):
5656
translated_model_name,
5757
self.file_name,
5858
)
59+
file_name = self.file_name
60+
if not file_name.endswith(".csv"):
61+
file_name += ".csv"
5962
attachment = self._create_csv_attachment(
60-
import_fields, data, options, self.file_name
63+
import_fields, data, options, file_name
6164
)
6265
delayed_job = self.with_delay(description=description)._split_file(
6366
model_name=self.res_model,
6467
translated_model_name=translated_model_name,
6568
attachment=attachment,
6669
options=options,
67-
file_name=self.file_name,
70+
file_name=file_name,
6871
)
6972
self._link_attachment_to_job(delayed_job, attachment)
7073
return []
@@ -91,7 +94,12 @@ def _create_csv_attachment(self, fields, data, options, file_name):
9194
# create attachment
9295
datas = base64.encodebytes(f.getvalue().encode(encoding))
9396
attachment = self.env["ir.attachment"].create(
94-
{"name": file_name, "datas": datas}
97+
{
98+
"name": file_name,
99+
"datas": datas,
100+
"type": "binary",
101+
"mimetype": "text/csv",
102+
}
95103
)
96104
return attachment
97105

@@ -130,7 +138,7 @@ def _split_file(
130138
options,
131139
file_name="file.csv",
132140
):
133-
""" Split a CSV attachment in smaller import jobs """
141+
"""Split a CSV attachment in smaller import jobs"""
134142
model_obj = self.env[model_name]
135143
fields, data = self._read_csv_attachment(attachment, options)
136144
padding = len(str(len(data)))

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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,

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)