Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_export_async/|
^base_import_async/|
^queue_job_subscribe/|
^test_base_import_async/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
Expand Down
4 changes: 2 additions & 2 deletions base_import_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{
"name": "Asynchronous Import",
"summary": "Import CSV files in the background",
"version": "13.0.2.0.0",
"version": "14.0.1.0.0",
"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,
"installable": True,
"development_status": "Production/Stable",
}
3 changes: 1 addition & 2 deletions base_import_async/models/base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def _read_csv_attachment(self, attachment, options):

@staticmethod
def _extract_chunks(model_obj, fields, data, chunk_size):
""" Split the data on record boundaries,
in chunks of minimum chunk_size """
"""Split the data on record boundaries, in chunks of minimum chunk_size"""
fields = list(map(fix_import_export_id_paths, fields))
row_from = 0
for rows in model_obj._extract_records(fields, data):
Expand Down
17 changes: 10 additions & 7 deletions base_import_async/static/src/js/import.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
odoo.define("base_import_async.import", function(require) {
odoo.define("base_import_async.import", function (require) {
"use strict";

var core = require("web.core");
var _t = core._t;
var DataImport = require("base_import.import").DataImport;

DataImport.include({
import_options: function() {
import_options: function () {
var options = this._super.apply(this, arguments);
options.use_queue = this.$("input.oe_import_queue").prop("checked");
return options;
},

onimported: function() {
onimported: function () {
if (this.$("input.oe_import_queue").prop("checked")) {
this.do_notify(
_t("Your request is being processed"),
_t("You can check the status of this job in menu 'Queue / Jobs'.")
);
this.displayNotification({
type: "warning",
title: _t("Your request is being processed"),
message: _t(
"You can check the status of this job in menu 'Queue / Jobs'."
),
});
this.exit();
} else {
this._super.apply(this, arguments);
Expand Down
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,
)
6 changes: 6 additions & 0 deletions setup/test_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,
)
4 changes: 2 additions & 2 deletions test_base_import_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Test suite for base_import_async",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/queue",
Expand All @@ -15,6 +15,6 @@
""",
"depends": ["base_import_async", "account"],
"data": [],
"installable": False,
"installable": True,
"development_status": "Production/Stable",
}
47 changes: 24 additions & 23 deletions test_base_import_async/tests/test_base_import_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from odoo.addons.queue_job.job import Job


class TestBaseImportAsync(common.TransactionCase):
class TestBaseImportAsync(common.SavepointCase):

FIELDS = [
"date",
Expand All @@ -36,38 +36,40 @@ class TestBaseImportAsync(common.TransactionCase):
"date_format": "%Y-%m-%d",
}

def setUp(self):
super().setUp()
@classmethod
def setUpClass(cls):
super().setUpClass()
# add xmlids that will be used in the test CSV file
self.env["ir.model.data"]._update_xmlids(
cls.env["ir.model.data"]._update_xmlids(
[
{
"xml_id": "test_base_import_async.testjournal_xmlid",
"record": self.env["account.journal"].search(
"record": cls.env["account.journal"].search(
[("code", "=", "CABA")]
),
},
{
"xml_id": "test_base_import_async.a_recv_xmlid",
"record": self.env["account.account"].search(
"record": cls.env["account.account"].search(
[("code", "=", "121000")]
),
},
{
"xml_id": "test_base_import_async.a_sale_xmlid",
"record": self.env["account.account"].search(
"record": cls.env["account.account"].search(
[("code", "=", "400000")]
),
},
]
)
self.import_obj = self.env["base_import.import"]
self.move_obj = self.env["account.move"]
self.job_obj = self.env["queue.job"]
cls.import_obj = cls.env["base_import.import"]
cls.move_obj = cls.env["account.move"]
cls.job_obj = cls.env["queue.job"]

def _read_test_file(self, file_name):
file_name = os.path.join(os.path.dirname(__file__), file_name)
return open(file_name).read()
with open(file_name) as opened:
return opened.read()

def _do_import(self, file_name, use_queue, chunk_size=None):
data = self._read_test_file(file_name)
Expand Down Expand Up @@ -105,7 +107,7 @@ def test_async_import(self):
self.assertEqual(len(split_job), 1)
# job names are important
self.assertEqual(
split_job.name, "Import Journal Entries from file account.move.csv"
split_job.name, "Import Journal Entry from file account.move.csv"
)
# perform job
Job.load(self.env, split_job.uuid).perform()
Expand All @@ -114,7 +116,7 @@ def test_async_import(self):
self.assertEqual(len(load_job), 1)
self.assertEqual(
load_job.name,
"Import Journal Entries from file account.move.csv - " "#0 - lines 2 to 10",
"Import Journal Entry from file account.move.csv - " "#0 - lines 2 to 10",
)
# perform job
Job.load(self.env, load_job.uuid).perform()
Expand All @@ -134,11 +136,11 @@ def test_async_import_small_misaligned_chunks(self):
self.assertEqual(len(load_jobs), 2)
self.assertEqual(
load_jobs[0].name,
"Import Journal Entries from file account.move.csv - " "#0 - lines 2 to 7",
"Import Journal Entry from file account.move.csv - " "#0 - lines 2 to 7",
)
self.assertEqual(
load_jobs[1].name,
"Import Journal Entries from file account.move.csv - " "#1 - lines 8 to 10",
"Import Journal Entry from file account.move.csv - " "#1 - lines 8 to 10",
)
# perform job
Job.load(self.env, load_jobs[0].uuid).perform()
Expand All @@ -159,15 +161,15 @@ def test_async_import_smaller_misaligned_chunks(self):
self.assertEqual(len(load_jobs), 3)
self.assertEqual(
load_jobs[0].name,
"Import Journal Entries from file account.move.csv - " "#0 - lines 2 to 4",
"Import Journal Entry from file account.move.csv - " "#0 - lines 2 to 4",
)
self.assertEqual(
load_jobs[1].name,
"Import Journal Entries from file account.move.csv - " "#1 - lines 5 to 7",
"Import Journal Entry from file account.move.csv - " "#1 - lines 5 to 7",
)
self.assertEqual(
load_jobs[2].name,
"Import Journal Entries from file account.move.csv - " "#2 - lines 8 to 10",
"Import Journal Entry from file account.move.csv - " "#2 - lines 8 to 10",
)
# perform job
Job.load(self.env, load_jobs[0].uuid).perform()
Expand All @@ -176,8 +178,7 @@ def test_async_import_smaller_misaligned_chunks(self):
self._check_import_result()

def test_async_import_smaller_aligned_chunks(self):
""" Chunks aligned on record boundaries.
Last chunk ends exactly at file end. """
"""Chunks aligned on record boundaries. Last chunk ends exactly at file end."""
res = self._do_import("account.move.csv", use_queue=True, chunk_size=3)
self.assertFalse(res, repr(res))
# but we must have one job to split the file
Expand All @@ -190,15 +191,15 @@ def test_async_import_smaller_aligned_chunks(self):
self.assertEqual(len(load_jobs), 3)
self.assertEqual(
load_jobs[0].name,
"Import Journal Entries from file account.move.csv - " "#0 - lines 2 to 4",
"Import Journal Entry from file account.move.csv - " "#0 - lines 2 to 4",
)
self.assertEqual(
load_jobs[1].name,
"Import Journal Entries from file account.move.csv - " "#1 - lines 5 to 7",
"Import Journal Entry from file account.move.csv - " "#1 - lines 5 to 7",
)
self.assertEqual(
load_jobs[2].name,
"Import Journal Entries from file account.move.csv - " "#2 - lines 8 to 10",
"Import Journal Entry from file account.move.csv - " "#2 - lines 8 to 10",
)
# perform job
Job.load(self.env, load_jobs[0].uuid).perform()
Expand Down