diff --git a/attachment_indexation_ocr_job/README.rst b/attachment_indexation_ocr_job/README.rst new file mode 100644 index 00000000..15c293f7 --- /dev/null +++ b/attachment_indexation_ocr_job/README.rst @@ -0,0 +1,91 @@ +======== +OCR Jobs +======== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:105d2f68229c93f2eb40bbf73f786ecc2093c280ce523eabdfe6a35b3f94995e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-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%2Fknowledge-lightgray.png?logo=github + :target: https://github.com/OCA/knowledge/tree/16.0/attachment_indexation_ocr_job + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-attachment_indexation_ocr_job + :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/knowledge&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module deactivates the OCR cron and replaces it by individual OCR jobs. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on `queue_job` additionally to `attachment_indexation_ocr`. + +Configuration +============= + +Standard queue job configuration can be applied to the `ocr` channel. + +Usage +===== + +Installing the module is enough unless finer configuration of jobs is required. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* len-foss/Financial Way + +Contributors +~~~~~~~~~~~~ + +* Nans Lefebvre + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/knowledge `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/attachment_indexation_ocr_job/__init__.py b/attachment_indexation_ocr_job/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/attachment_indexation_ocr_job/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/attachment_indexation_ocr_job/__manifest__.py b/attachment_indexation_ocr_job/__manifest__.py new file mode 100644 index 00000000..c4d4c9e3 --- /dev/null +++ b/attachment_indexation_ocr_job/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2023 len-foss/Financial Way +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "OCR Jobs", + "version": "16.0.1.0.0", + "author": "len-foss/Financial Way,Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/knowledge", + "category": "Knowledge Management", + "summary": "Run OCR through jobs", + "depends": ["attachment_indexation_ocr", "queue_job"], + "data": ["data/ir_cron.xml", "data/queue_job_channel.xml"], +} diff --git a/attachment_indexation_ocr_job/data/ir_cron.xml b/attachment_indexation_ocr_job/data/ir_cron.xml new file mode 100644 index 00000000..753ee3bb --- /dev/null +++ b/attachment_indexation_ocr_job/data/ir_cron.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/attachment_indexation_ocr_job/data/queue_job_channel.xml b/attachment_indexation_ocr_job/data/queue_job_channel.xml new file mode 100644 index 00000000..c1dbd161 --- /dev/null +++ b/attachment_indexation_ocr_job/data/queue_job_channel.xml @@ -0,0 +1,9 @@ + + + + + ocr + + + diff --git a/attachment_indexation_ocr_job/models/__init__.py b/attachment_indexation_ocr_job/models/__init__.py new file mode 100644 index 00000000..aaf38a16 --- /dev/null +++ b/attachment_indexation_ocr_job/models/__init__.py @@ -0,0 +1 @@ +from . import ir_attachment diff --git a/attachment_indexation_ocr_job/models/ir_attachment.py b/attachment_indexation_ocr_job/models/ir_attachment.py new file mode 100644 index 00000000..9624118b --- /dev/null +++ b/attachment_indexation_ocr_job/models/ir_attachment.py @@ -0,0 +1,19 @@ +# Copyright 2023 len-foss/Financial Way +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models + +from odoo.addons.attachment_indexation_ocr.models.ir_attachment import _MARKER_PHRASE + + +class IrAttachment(models.Model): + _inherit = "ir.attachment" + + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for record in records: + if record.index_content == _MARKER_PHRASE: + desc = _("Perform OCR on attachment %s") % record.name + record.with_delay(description=desc, channel="ocr").perform_ocr() + return records diff --git a/attachment_indexation_ocr_job/readme/CONFIGURE.rst b/attachment_indexation_ocr_job/readme/CONFIGURE.rst new file mode 100644 index 00000000..fc3806d7 --- /dev/null +++ b/attachment_indexation_ocr_job/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Standard queue job configuration can be applied to the `ocr` channel. diff --git a/attachment_indexation_ocr_job/readme/CONTRIBUTORS.rst b/attachment_indexation_ocr_job/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..940a23ce --- /dev/null +++ b/attachment_indexation_ocr_job/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Nans Lefebvre diff --git a/attachment_indexation_ocr_job/readme/DESCRIPTION.rst b/attachment_indexation_ocr_job/readme/DESCRIPTION.rst new file mode 100644 index 00000000..4921d890 --- /dev/null +++ b/attachment_indexation_ocr_job/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module deactivates the OCR cron and replaces it by individual OCR jobs. diff --git a/attachment_indexation_ocr_job/readme/INSTALL.rst b/attachment_indexation_ocr_job/readme/INSTALL.rst new file mode 100644 index 00000000..64a2343e --- /dev/null +++ b/attachment_indexation_ocr_job/readme/INSTALL.rst @@ -0,0 +1 @@ +This module depends on `queue_job` additionally to `attachment_indexation_ocr`. diff --git a/attachment_indexation_ocr_job/readme/USAGE.rst b/attachment_indexation_ocr_job/readme/USAGE.rst new file mode 100644 index 00000000..f7edba36 --- /dev/null +++ b/attachment_indexation_ocr_job/readme/USAGE.rst @@ -0,0 +1 @@ +Installing the module is enough unless finer configuration of jobs is required. diff --git a/attachment_indexation_ocr_job/static/description/index.html b/attachment_indexation_ocr_job/static/description/index.html new file mode 100644 index 00000000..fd84dcba --- /dev/null +++ b/attachment_indexation_ocr_job/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +OCR Jobs + + + +
+

OCR Jobs

+ + +

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runboat

+

This module deactivates the OCR cron and replaces it by individual OCR jobs.

+

Table of contents

+ +
+

Installation

+

This module depends on queue_job additionally to attachment_indexation_ocr.

+
+
+

Configuration

+

Standard queue job configuration can be applied to the ocr channel.

+
+
+

Usage

+

Installing the module is enough unless finer configuration of jobs is required.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • len-foss/Financial Way
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/knowledge project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/attachment_indexation_ocr_job/tests/__init__.py b/attachment_indexation_ocr_job/tests/__init__.py new file mode 100644 index 00000000..059af577 --- /dev/null +++ b/attachment_indexation_ocr_job/tests/__init__.py @@ -0,0 +1,3 @@ +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_document_ocr diff --git a/attachment_indexation_ocr_job/tests/test_document_ocr.py b/attachment_indexation_ocr_job/tests/test_document_ocr.py new file mode 100644 index 00000000..cb3edb0a --- /dev/null +++ b/attachment_indexation_ocr_job/tests/test_document_ocr.py @@ -0,0 +1,24 @@ +# Copyright 2023 len-foss/Financial Way +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import base64 + +from odoo.addons.attachment_indexation_ocr.tests.common import TestOcrCase +from odoo.addons.queue_job.tests.common import trap_jobs + + +class TestOcrJob(TestOcrCase): + def test_document_ocr_png(self): + vals = {"name": "testattachment", "datas": base64.b64encode(self.data_png)} + with trap_jobs() as trap: + attachment = self.env["ir.attachment"].create(vals) + trap.assert_jobs_count(1) + expected_job_desc = "Perform OCR on attachment testattachment" + trap.assert_enqueued_job( + self.env["ir.attachment"].perform_ocr, + args=(), + kwargs={}, + properties={"channel": "ocr", "description": expected_job_desc}, + ) + # the ocr has not been performed yet + self.assertEqual(attachment.index_content.strip(), self.marker) diff --git a/setup/attachment_indexation_ocr_job/odoo/addons/attachment_indexation_ocr_job b/setup/attachment_indexation_ocr_job/odoo/addons/attachment_indexation_ocr_job new file mode 120000 index 00000000..eebcc402 --- /dev/null +++ b/setup/attachment_indexation_ocr_job/odoo/addons/attachment_indexation_ocr_job @@ -0,0 +1 @@ +../../../../attachment_indexation_ocr_job \ No newline at end of file diff --git a/setup/attachment_indexation_ocr_job/setup.py b/setup/attachment_indexation_ocr_job/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/attachment_indexation_ocr_job/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)