Skip to content

Commit

Permalink
Merge PR #907 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Dec 8, 2024
2 parents 0eab298 + 995ca5e commit 0114a24
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 62 deletions.
3 changes: 2 additions & 1 deletion document_quick_access_folder_auto_classification/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
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
@@ -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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -388,7 +387,10 @@ <h1 class="title">Document Quick Access Folder Auto Classification</h1>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p># Create an storage on your system using the storage project from OCA</p>
<dl class="docutils">
<dt># Create an storage on your system using the storage project from OCA.</dt>
<dd>Another option is using the endpoint project.</dd>
</dl>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
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[: int(len(file) / 2)]),
"edi_exchange_state": "input_received",
},
)
self.backend._cron_check_input_exchange_sync()
self.assertTrue(
self.exchange_model.search(
Expand Down

0 comments on commit 0114a24

Please sign in to comment.