Skip to content

Commit

Permalink
[15.0][FIX][IMP]base_import_async
Browse files Browse the repository at this point in the history
  • Loading branch information
Rad0van committed May 25, 2022
1 parent f02dd13 commit 9376b49
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_export_async/|
^base_import_async/|
^queue_job_subscribe/|
^test_base_import_async/|
# END NOT INSTALLABLE ADDONS
Expand Down
11 changes: 7 additions & 4 deletions base_import_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
{
"name": "Asynchronous Import",
"summary": "Import CSV files in the background",
"version": "14.0.1.0.1",
"version": "15.0.1.0.1",
"author": "Akretion, ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/queue",
"category": "Generic Modules",
"depends": ["base_import", "queue_job"],
"data": ["data/queue_job_function_data.xml", "views/base_import_async.xml"],
"qweb": ["static/src/xml/import.xml"],
"installable": False,
"data": ["data/queue_job_function_data.xml"],
"assets": {
"web.assets_qweb": ["/base_import_async/static/src/xml/import.xml"],
"web.assets_backend": ["/base_import_async/static/src/js/import.js"],
},
"installable": True,
"development_status": "Production/Stable",
}
20 changes: 14 additions & 6 deletions base_import_async/models/base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
class BaseImportImport(models.TransientModel):
_inherit = "base_import.import"

def do(self, fields, columns, options, dryrun=False):
def execute_import(self, fields, columns, options, dryrun=False):
if dryrun or not options.get(OPT_USE_QUEUE):
# normal import
return super().do(fields, columns, options, dryrun=dryrun)
return super().execute_import(fields, columns, options, dryrun=dryrun)

# asynchronous import
try:
Expand All @@ -56,15 +56,18 @@ def do(self, fields, columns, options, dryrun=False):
translated_model_name,
self.file_name,
)
file_name = self.file_name
if not file_name.endswith(".csv"):
file_name += ".csv"
attachment = self._create_csv_attachment(
import_fields, data, options, self.file_name
import_fields, data, options, file_name
)
delayed_job = self.with_delay(description=description)._split_file(
model_name=self.res_model,
translated_model_name=translated_model_name,
attachment=attachment,
options=options,
file_name=self.file_name,
file_name=file_name,
)
self._link_attachment_to_job(delayed_job, attachment)
return []
Expand All @@ -91,7 +94,12 @@ def _create_csv_attachment(self, fields, data, options, file_name):
# create attachment
datas = base64.encodebytes(f.getvalue().encode(encoding))
attachment = self.env["ir.attachment"].create(
{"name": file_name, "datas": datas}
{
"name": file_name,
"datas": datas,
"type": "binary",
"mimetype": "text/csv",
}
)
return attachment

Expand Down Expand Up @@ -130,7 +138,7 @@ def _split_file(
options,
file_name="file.csv",
):
""" Split a CSV attachment in smaller import jobs """
"""Split a CSV attachment in smaller import jobs"""
model_obj = self.env[model_name]
fields, data = self._read_csv_attachment(attachment, options)
padding = len(str(len(data)))
Expand Down
2 changes: 1 addition & 1 deletion base_import_async/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class QueueJob(models.Model):
""" Job status and result """
"""Job status and result"""

_inherit = "queue.job"

Expand Down
2 changes: 1 addition & 1 deletion base_import_async/static/src/xml/import.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<t t-extend="ImportView">
<t t-extend="ImportView.side_panel">
<t t-jquery="#oe_import_has_header" t-operation="before">
<div
title="When checked, the import will be executed as a background job,
Expand Down
15 changes: 0 additions & 15 deletions base_import_async/views/base_import_async.xml

This file was deleted.

1 change: 1 addition & 0 deletions setup/base_import_async/odoo/addons/base_import_async
6 changes: 6 additions & 0 deletions setup/base_import_async/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 9376b49

Please sign in to comment.