From 995ca5e1fdc646b89bcb53b7998ba80ec9ef0cff Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Thu, 27 Jun 2024 23:15:38 +0200 Subject: [PATCH] [IMP] document_quick_access_folder_auto_classification: Remove edi_storage_oca unnecessary dependancy --- .../README.rst | 3 +- .../__manifest__.py | 2 +- .../data/edi_data.xml | 6 -- .../readme/CONFIGURE.rst | 3 +- .../static/description/index.html | 6 +- ...cument_quick_access_auto_classification.py | 92 +++++++++---------- 6 files changed, 50 insertions(+), 62 deletions(-) diff --git a/document_quick_access_folder_auto_classification/README.rst b/document_quick_access_folder_auto_classification/README.rst index 1653f5c512..2adeebed79 100644 --- a/document_quick_access_folder_auto_classification/README.rst +++ b/document_quick_access_folder_auto_classification/README.rst @@ -39,7 +39,8 @@ to its record. The record is found using the document quick access rules. Configuration ============= -# Create an storage on your system using the storage project from OCA +# Create an storage on your system using the storage project from OCA. + Another option is using the endpoint project. Usage ===== diff --git a/document_quick_access_folder_auto_classification/__manifest__.py b/document_quick_access_folder_auto_classification/__manifest__.py index 34610e1ae7..4059238755 100644 --- a/document_quick_access_folder_auto_classification/__manifest__.py +++ b/document_quick_access_folder_auto_classification/__manifest__.py @@ -9,7 +9,7 @@ "license": "AGPL-3", "author": "Creu Blanca,Odoo Community Association (OCA)", "website": "https://github.com/OCA/server-ux", - "depends": ["document_quick_access", "edi_storage_oca"], + "depends": ["document_quick_access", "edi_oca"], "external_dependencies": { "deb": ["libzbar0", "poppler-utils"], "python": ["pyzbar", "pdf2image"], diff --git a/document_quick_access_folder_auto_classification/data/edi_data.xml b/document_quick_access_folder_auto_classification/data/edi_data.xml index a7b85e8fda..c2d363ea23 100644 --- a/document_quick_access_folder_auto_classification/data/edi_data.xml +++ b/document_quick_access_folder_auto_classification/data/edi_data.xml @@ -11,14 +11,8 @@ input - - Document Quick Access Storage Folder - filesystem - opt/qr_data - Document quick access auto classification - diff --git a/document_quick_access_folder_auto_classification/readme/CONFIGURE.rst b/document_quick_access_folder_auto_classification/readme/CONFIGURE.rst index a361274237..cabff61d81 100644 --- a/document_quick_access_folder_auto_classification/readme/CONFIGURE.rst +++ b/document_quick_access_folder_auto_classification/readme/CONFIGURE.rst @@ -1 +1,2 @@ -# Create an storage on your system using the storage project from OCA +# Create an storage on your system using the storage project from OCA. + Another option is using the endpoint project. diff --git a/document_quick_access_folder_auto_classification/static/description/index.html b/document_quick_access_folder_auto_classification/static/description/index.html index 7961e188b3..03d9808fbd 100644 --- a/document_quick_access_folder_auto_classification/static/description/index.html +++ b/document_quick_access_folder_auto_classification/static/description/index.html @@ -1,4 +1,3 @@ - @@ -388,7 +387,10 @@

Document Quick Access Folder Auto Classification

Configuration

-

# Create an storage on your system using the storage project from OCA

+
+
# Create an storage on your system using the storage project from OCA.
+
Another option is using the endpoint project.
+

Usage

diff --git a/document_quick_access_folder_auto_classification/tests/test_document_quick_access_auto_classification.py b/document_quick_access_folder_auto_classification/tests/test_document_quick_access_auto_classification.py index 2d4fbfde58..add1d472a5 100644 --- a/document_quick_access_folder_auto_classification/tests/test_document_quick_access_auto_classification.py +++ b/document_quick_access_folder_auto_classification/tests/test_document_quick_access_auto_classification.py @@ -1,9 +1,7 @@ # Copyright 2019 Creu Blanca # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import os -import shutil -import uuid +import base64 from mock import patch @@ -36,45 +34,19 @@ def setUpClass(cls): self._setup_registry(self) self._load_module_components(self, "component_event") self._load_module_components(self, "edi") - self._load_module_components(self, "edi_storage") self._load_module_components( self, "document_quick_access_folder_auto_classification" ) - self.base_dir = os.path.join(self.env["ir.attachment"]._filestore(), "storage") - try: - os.mkdir(self.base_dir) - self.clean_base_dir = True - except FileExistsError: - # If the directory exists we respect it and do not clean it on teardown. - self.clean_base_dir = False - self.tmpdir = os.path.join(self.base_dir, str(uuid.uuid4())) - self.storage = self.env["storage.backend"].create( - { - "name": "Demo Storage", - "backend_type": "filesystem", - "directory_path": self.tmpdir, - } - ) self.backend = self.env["edi.backend"].create( { "name": "Demo Backend", "backend_type_id": self.env.ref( "document_quick_access_folder_auto_classification.backend_type" ).id, - "storage_id": self.storage.id, - "input_dir_pending": self.tmpdir, } ) - os.mkdir(self.tmpdir) self.model_id = self.env.ref("base.model_res_partner") - @classmethod - def tearDownClass(cls): - shutil.rmtree(cls.tmpdir) - if cls.clean_base_dir: - shutil.rmtree(cls.base_dir) - return super().tearDownClass() - def test_ok_pdf_multi(self): partners = self.env["res.partner"].create({"name": "Partner 1"}) partners |= self.env["res.partner"].create({"name": "Partner 2"}) @@ -100,8 +72,6 @@ def test_ok_pdf(self, partners=False): "barcode_format": "standard", } ) - with open(os.path.join(self.tmpdir, "test_file.pdf"), "wb") as f: - f.write(file) code = [ Encoded(partner.get_quick_access_code().encode("utf-8")) for partner in partners @@ -111,9 +81,14 @@ def test_ok_pdf(self, partners=False): "components.document_quick_access_process.decode" ) as ptch: ptch.return_value = code - self.assertFalse(self.exchange_model.search([])) - self.backend._storage_cron_check_pending_input() - self.assertEqual(self.exchange_model.search_count([]), 1) + self.backend.create_record( + "document_quick_access", + { + "exchange_filename": "test_file.pdf", + "exchange_file": base64.b64encode(file), + "edi_exchange_state": "input_received", + }, + ) self.backend._cron_check_input_exchange_sync() self.assertEqual(ptch.call_count, 1) self.assertTrue(partners) @@ -131,11 +106,14 @@ def test_no_ok_assign(self): "addons/document_quick_access_folder_auto_classification/tests/test_file.pdf", mode="rb", ).read() - with open(os.path.join(self.tmpdir, "test_file.pdf"), "wb") as f: - f.write(file) - self.assertFalse(self.exchange_model.search([])) - self.backend._storage_cron_check_pending_input() - self.assertEqual(self.exchange_model.search_count([]), 1) + self.backend.create_record( + "document_quick_access", + { + "exchange_filename": "test_file.pdf", + "exchange_file": base64.b64encode(file), + "edi_exchange_state": "input_received", + }, + ) self.backend._cron_check_input_exchange_sync() self.assertTrue( self.exchange_model.search( @@ -184,16 +162,20 @@ def test_failure(self): "addons/document_quick_access_folder_auto_classification/tests/test_file.pdf", mode="rb", ).read() - with open(os.path.join(self.tmpdir, "test_file.pdf"), "wb") as f: - f.write(file) with self.assertRaises(TypeError): with patch( "odoo.addons.document_quick_access_folder_auto_classification." "components.document_quick_access_process.decode" ) as ptch: ptch.return_value = 1 - self.backend._storage_cron_check_pending_input() - self.assertEqual(self.exchange_model.search_count([]), 1) + self.backend.create_record( + "document_quick_access", + { + "exchange_filename": "test_file.pdf", + "exchange_file": base64.b64encode(file), + "edi_exchange_state": "input_received", + }, + ) self.backend._cron_check_input_exchange_sync() @mute_logger("odoo.addons.queue_job.models.base") @@ -203,10 +185,14 @@ def test_no_ok_reject(self): "addons/document_quick_access_folder_auto_classification/tests/test_file.pdf", mode="rb", ).read() - with open(os.path.join(self.tmpdir, "test_file.pdf"), "wb") as f: - f.write(file) - self.backend._storage_cron_check_pending_input() - self.assertEqual(self.exchange_model.search_count([]), 1) + self.backend.create_record( + "document_quick_access", + { + "exchange_filename": "test_file.pdf", + "exchange_file": base64.b64encode(file), + "edi_exchange_state": "input_received", + }, + ) self.backend._cron_check_input_exchange_sync() missing = self.exchange_model.search( [ @@ -230,14 +216,18 @@ def test_corrupted(self): "document_quick_access_folder_auto_classification/tests/test_file.pdf", mode="rb", ).read() - with open(os.path.join(self.tmpdir, "test_file.pdf"), "wb") as f: - f.write(file[: int(len(file) / 2)]) with mute_logger( "odoo.addons.document_quick_access_folder_auto_classification." "components.document_quick_access_process", ): - self.backend._storage_cron_check_pending_input() - self.assertEqual(self.exchange_model.search_count([]), 1) + self.backend.create_record( + "document_quick_access", + { + "exchange_filename": "test_file.pdf", + "exchange_file": base64.b64encode(file[: int(len(file) / 2)]), + "edi_exchange_state": "input_received", + }, + ) self.backend._cron_check_input_exchange_sync() self.assertTrue( self.exchange_model.search(