Skip to content

Commit

Permalink
[MIG] document_quick_access_folder_auto_classification: Migration to …
Browse files Browse the repository at this point in the history
…16.0
  • Loading branch information
luisDIXMIT committed Jul 1, 2024
1 parent 7b44abf commit bdddaa3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 69 deletions.
12 changes: 6 additions & 6 deletions document_quick_access_folder_auto_classification/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Document Quick Access Folder Auto Classification
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33a6eebca1ef882eaefa59d584099932fc04c410b7de401e6dbf5f708bdb98e6
!! source digest: sha256:14edc6aa1a5f02796dcc54b02bbaae83f3915aeb6d90a1d30ee32988de5f7170
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Document Quick Access Folder Auto Classification
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/15.0/document_quick_access_folder_auto_classification
:target: https://github.com/OCA/server-ux/tree/16.0/document_quick_access_folder_auto_classification
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-15-0/server-ux-15-0-document_quick_access_folder_auto_classification
:target: https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-document_quick_access_folder_auto_classification
: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/server-ux&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -62,7 +62,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/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/server-ux/issues/new?body=module:%20document_quick_access_folder_auto_classification%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20document_quick_access_folder_auto_classification%0Aversion:%2016.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 @@ -101,6 +101,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-etobella|

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/15.0/document_quick_access_folder_auto_classification>`_ project on GitHub.
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/16.0/document_quick_access_folder_auto_classification>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"name": "Document Quick Access Folder Auto Classification",
"summary": """
Auto classification of Documents after reading a QR""",
"version": "15.0.1.1.0",
"version": "16.0.1.0.0",
"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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@
<field name="direction">input</field>
<field name="exchange_filename_pattern" />
</record>
<record id="storage_backend" model="storage.backend">
<field name="name">Document Quick Access Storage Folder</field>
<field name="backend_type">filesystem</field>
<field name="directory_path">opt/qr_data</field>
</record>
<record id="edi_backend" model="edi.backend">
<field name="name">Document quick access auto classification</field>
<field name="backend_type_id" ref="backend_type" />
<field name="storage_id" ref="storage_backend" />
</record>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Document Quick Access Folder Auto Classification</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33a6eebca1ef882eaefa59d584099932fc04c410b7de401e6dbf5f708bdb98e6
!! source digest: sha256:14edc6aa1a5f02796dcc54b02bbaae83f3915aeb6d90a1d30ee32988de5f7170
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/server-ux/tree/15.0/document_quick_access_folder_auto_classification"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-15-0/server-ux-15-0-document_quick_access_folder_auto_classification"><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/server-ux&amp;target_branch=15.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="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/server-ux/tree/16.0/document_quick_access_folder_auto_classification"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-document_quick_access_folder_auto_classification"><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/server-ux&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module creates a job that scans all files from a storage and attaches them
to its record. The record is found using the document quick access rules.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -407,7 +407,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-ux/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/server-ux/issues/new?body=module:%20document_quick_access_folder_auto_classification%0Aversion:%2015.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/server-ux/issues/new?body=module:%20document_quick_access_folder_auto_classification%0Aversion:%2016.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">
Expand All @@ -434,7 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/etobella"><img alt="etobella" src="https://github.com/etobella.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-ux/tree/15.0/document_quick_access_folder_auto_classification">OCA/server-ux</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-ux/tree/16.0/document_quick_access_folder_auto_classification">OCA/server-ux</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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"})
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -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(
[
Expand All @@ -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),
"edi_exchange_state": "input_received",
},
)
self.backend._cron_check_input_exchange_sync()
self.assertTrue(
self.exchange_model.search(
Expand Down

0 comments on commit bdddaa3

Please sign in to comment.