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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_import_async/|
^queue_job_batch/|
^queue_job_cron/|
^queue_job_cron_jobrunner/|
Expand Down
22 changes: 10 additions & 12 deletions base_import_async/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===================
Asynchronous Import
===================
Expand All @@ -13,17 +17,17 @@ Asynchronous Import
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
:target: https://github.com/OCA/queue/tree/18.0/base_import_async
:target: https://github.com/OCA/queue/tree/20.0/base_import_async
:alt: OCA/queue
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-base_import_async
:target: https://translation.odoo-community.org/projects/queue-20-0/queue-20-0-base_import_async
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=20.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -87,7 +91,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20base_import_async%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20base_import_async%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -130,12 +134,6 @@ Other contributors include:

- Daniel Duque (FactorLibre)

Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp

Maintainers
-----------

Expand All @@ -149,6 +147,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/base_import_async>`_ project on GitHub.
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/20.0/base_import_async>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions base_import_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Asynchronous Import",
"summary": "Import CSV files in the background",
"version": "18.0.1.0.0",
"version": "20.0.1.0.0",
"author": "Akretion, ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/queue",
Expand All @@ -20,6 +20,6 @@
"base_import_async/static/src/xml/import_data_sidepanel.xml",
],
},
"installable": False,
"installable": True,
"development_status": "Production/Stable",
}
1 change: 1 addition & 0 deletions base_import_async/data/queue_job_function_data.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="job_function_base_import_import_split_file" model="queue.job.function">
<field name="model_id" ref="base_import.model_base_import_import" />
Expand Down
62 changes: 31 additions & 31 deletions base_import_async/models/base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
import csv
from io import BytesIO, StringIO, TextIOWrapper
from io import StringIO, TextIOWrapper
from os.path import splitext

from odoo import _, api, models
from odoo import models
from odoo.models import fix_import_export_id_paths

from odoo.addons.base_import.models.base_import import ImportValidationError
Expand All @@ -30,7 +29,8 @@
DEFAULT_CHUNK_SIZE = 100


class BaseImportImport(models.TransientModel):
# Upstream base_import.import lives in models/; keep path for backwards compatibility.
class BaseImportImport(models.TransientModel): # pylint: disable=no-wizard-in-models
_inherit = "base_import.import"

def execute_import(self, fields, columns, options, dryrun=False):
Expand All @@ -55,10 +55,11 @@ def execute_import(self, fields, columns, options, dryrun=False):
translated_model_name = search_result[0][1]
else:
translated_model_name = self._description
description = _("Import %(model)s from file %(from_file)s") % {
"model": translated_model_name,
"from_file": self.file_name,
}
description = self.env._(
"Import %(model)s from file %(from_file)s",
model=translated_model_name,
from_file=self.file_name,
)
attachment = self._create_csv_attachment(
import_fields, data, options, self.file_name
)
Expand All @@ -67,7 +68,7 @@ def execute_import(self, fields, columns, options, dryrun=False):
translated_model_name=translated_model_name,
attachment=attachment,
options=options,
file_name=self.file_name,
file_name=self.file_name or "file.csv",
)
self._link_attachment_to_job(delayed_job, attachment)
return []
Expand All @@ -78,7 +79,6 @@ def _link_attachment_to_job(self, delayed_job, attachment):
)
attachment.write({"res_model": "queue.job", "res_id": queue_job.id})

@api.returns("ir.attachment")
def _create_csv_attachment(self, fields, data, options, file_name):
# write csv
f = StringIO()
Expand All @@ -94,30 +94,29 @@ def _create_csv_attachment(self, fields, data, options, file_name):
# create attachment. Remove default values from context
context = self.env.context
context_copy = {}
for key in context.keys():
for key in context:
if not key.startswith("default_"):
context_copy[key] = context[key]
datas = base64.encodebytes(f.getvalue().encode(encoding))
attachment = (
self.env["ir.attachment"]
.with_context(**context_copy)
.create({"name": file_name, "datas": datas})
.create({"name": file_name, "raw": f.getvalue().encode(encoding)})
)
return attachment

@staticmethod
def _read_csv_attachment(attachment, options):
decoded_datas = base64.decodebytes(attachment.datas)
encoding = options.get(OPT_ENCODING) or "utf-8"
f = TextIOWrapper(BytesIO(decoded_datas), encoding=encoding)
reader = csv.reader(
f,
delimiter=str(options.get(OPT_SEPARATOR)) or ",",
quotechar=str(options.get(OPT_QUOTING)),
)
with attachment.raw.open() as raw_file:
f = TextIOWrapper(raw_file, encoding=encoding)
reader = csv.reader(
f,
delimiter=str(options.get(OPT_SEPARATOR)) or ",",
quotechar=str(options.get(OPT_QUOTING)),
)

fields = next(reader)
data = [row for row in reader]
fields = next(reader)
data = [row for row in reader]
return fields, data

@staticmethod
Expand Down Expand Up @@ -155,16 +154,17 @@ def _split_file(
model_obj, fields, data, chunk_size
):
chunk = str(priority - INIT_PRIORITY).zfill(padding)
description = _(
description = self.env._(
"Import %(model)s from file %(file_name)s - "
"#%(chunk)s - lines %(from)s to %(to)s"
) % {
"model": translated_model_name,
"file_name": file_name,
"chunk": chunk,
"from": row_from + 1 + header_offset,
"to": row_to + 1 + header_offset,
}
"#%(chunk)s - lines %(from)s to %(to)s",
**{
"model": translated_model_name,
"file_name": file_name,
"chunk": chunk,
"from": row_from + 1 + header_offset,
"to": row_to + 1 + header_offset,
},
)
# create a CSV attachment and enqueue the job
root, ext = splitext(file_name)
attachment = self._create_csv_attachment(
Expand Down
4 changes: 2 additions & 2 deletions base_import_async/models/queue_job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo import models


class QueueJob(models.Model):
Expand All @@ -11,7 +11,7 @@ class QueueJob(models.Model):

def _related_action_attachment(self):
return {
"name": _("Attachment"),
"name": self.env._("Attachment"),
"type": "ir.actions.act_window",
"res_model": "ir.attachment",
"view_mode": "form",
Expand Down
2 changes: 0 additions & 2 deletions base_import_async/readme/CREDITS.md

This file was deleted.

42 changes: 21 additions & 21 deletions base_import_async/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,21 @@
</style>
</head>
<body>
<div class="document" id="asynchronous-import">
<h1 class="title">Asynchronous Import</h1>
<div class="document">


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="asynchronous-import">
<h1>Asynchronous Import</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:299c64b165f6348dfa062b8925a95235390daa6063964f21a5a1d0757cdf1614
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/18.0/base_import_async"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-base_import_async"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/queue&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/20.0/base_import_async"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/queue-20-0/queue-20-0-base_import_async"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/queue&amp;target_branch=20.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the standard CSV import functionality to import
files in the background using the OCA/queue framework.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -385,14 +390,13 @@ <h1 class="title">Asynchronous Import</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-6">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-7">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-8">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-9">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-9">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<p>The user is presented with a new checkbox in the import screen. When
selected, the import is delayed in a background job.</p>
<p>This job in turn splits the CSV file in chunks of minimum 100 lines (or
Expand All @@ -416,7 +420,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<ul class="simple">
<li>There is currently no user interface to control the chunk size, which
is currently 100 by default. Should this proves to be an issue, it is
Expand All @@ -425,33 +429,33 @@ <h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
</ul>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#toc-entry-3">Changelog</a></h1>
<h2><a class="toc-backref" href="#toc-entry-3">Changelog</a></h2>
<div class="section" id="section-1">
<h2><a class="toc-backref" href="#toc-entry-4">13.0.1.0.0 (2019-12-20)</a></h2>
<h3><a class="toc-backref" href="#toc-entry-4">13.0.1.0.0 (2019-12-20)</a></h3>
<ul class="simple">
<li>[MIGRATION] from 12.0 branched at rev. a7f8031</li>
</ul>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<h2><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/queue/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20base_import_async%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20base_import_async%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-6">Credits</a></h2>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-7">Authors</a></h3>
<ul class="simple">
<li>Akretion</li>
<li>ACSONE SA/NV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-8">Contributors</a></h3>
<p>Sébastien Beau (Akretion) authored the initial prototype.</p>
<p>Stéphane Bidoul (ACSONE) extended it to version 1.0 to support
multi-line records, store data to import as attachments and let the user
Expand All @@ -472,24 +476,20 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<li>Daniel Duque (FactorLibre)</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-9">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/18.0/base_import_async">OCA/queue</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/20.0/base_import_async">OCA/queue</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</div>
</body>
</html>
6 changes: 3 additions & 3 deletions base_import_async/static/src/xml/import_data_sidepanel.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t
t-name="base_import_async.ImportDataSidepanel"
Expand All @@ -13,9 +13,9 @@ after splitting your file in small chunks that will be processed independently.
Use this to import very large files."
>
<input
type="checkbox"
class="oe_import_queue form-check-input"
id="oe_import_queue"
class="oe_import_queue form-check-input"
type="checkbox"
/>
<label for="oe_import_queue">Import in the background</label>
</div>
Expand Down
Loading
Loading