diff --git a/base_import_async/__manifest__.py b/base_import_async/__manifest__.py index b94a74e65a..4d3a9e7561 100644 --- a/base_import_async/__manifest__.py +++ b/base_import_async/__manifest__.py @@ -7,7 +7,7 @@ { 'name': 'Asynchronous Import', 'summary': 'Import CSV files in the background', - 'version': '11.0.1.0.0', + 'version': '11.0.2.0.0', 'author': 'Akretion, ACSONE SA/NV, Odoo Community Association (OCA)', 'license': 'AGPL-3', 'website': 'https://github.com/OCA/queue', @@ -15,6 +15,7 @@ 'depends': [ 'base_import', 'queue_job', + 'queue_job_batch', ], 'data': [ 'views/base_import_async.xml', diff --git a/base_import_async/models/base_import_import.py b/base_import_async/models/base_import_import.py index 850ea6fba4..9eb2712e46 100644 --- a/base_import_async/models/base_import_import.py +++ b/base_import_async/models/base_import_import.py @@ -6,6 +6,7 @@ import csv import base64 +from datetime import datetime from os.path import splitext from io import StringIO, TextIOWrapper, BytesIO @@ -147,6 +148,8 @@ def _split_file(self, model_name, translated_model_name, else: header_offset = 0 chunk_size = options.get(OPT_CHUNK_SIZE) or DEFAULT_CHUNK_SIZE + batch_name = '%s (%s)' % (file_name, datetime.today()) + batch = self.env['queue.job.batch'].get_new_batch(batch_name) for row_from, row_to in self._extract_chunks( model_obj, fields, data, chunk_size): chunk = str(priority - INIT_PRIORITY).zfill(padding) @@ -161,13 +164,15 @@ def _split_file(self, model_name, translated_model_name, attachment = self._create_csv_attachment( fields, data[row_from:row_to + 1], options, file_name=root + '-' + chunk + ext) - delayed_job = self.with_delay( + delayed_job = self.with_context( + job_batch=batch).with_delay( description=description, priority=priority)._import_one_chunk( model_name=model_name, attachment=attachment, options=options) self._link_attachment_to_job(delayed_job, attachment) priority += 1 + batch.enqueue() @api.model @job diff --git a/base_import_async/readme/HISTORY.rst b/base_import_async/readme/HISTORY.rst index 630d9ebaa5..8090b30b6c 100644 --- a/base_import_async/readme/HISTORY.rst +++ b/base_import_async/readme/HISTORY.rst @@ -1,3 +1,9 @@ +11.0.2.0.0 (2019-07-08) +~~~~~~~~~~~~~~~~~~~~~~~ + +* Add dependency with module 'queue_job_batch', allowing the user to display + the progress of the import from the top bar. + 11.0.1.0.0 (2018-06-26) ~~~~~~~~~~~~~~~~~~~~~~~