summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
Diffstat (limited to 'addons')
-rw-r--r--addons/attachment_indexation/__manifest__.py4
-rw-r--r--addons/attachment_indexation/models/ir_attachment.py16
-rw-r--r--addons/attachment_indexation/tests/test_indexation.py7
3 files changed, 23 insertions, 4 deletions
diff --git a/addons/attachment_indexation/__manifest__.py b/addons/attachment_indexation/__manifest__.py
index 325590158e7..ff75a99a083 100644
--- a/addons/attachment_indexation/__manifest__.py
+++ b/addons/attachment_indexation/__manifest__.py
@@ -8,7 +8,9 @@
Attachments list and document indexation
========================================
* Show attachment on the top of the forms
-* Document Indexation: odt
+* Document Indexation: odt, pdf, xlsx, docx
+
+The `pdfminer.six` Python library has to be installed in order to index PDF files
""",
'depends': ['web'],
'installable': True,
diff --git a/addons/attachment_indexation/models/ir_attachment.py b/addons/attachment_indexation/models/ir_attachment.py
index 11152b6c2ea..05394e12698 100644
--- a/addons/attachment_indexation/models/ir_attachment.py
+++ b/addons/attachment_indexation/models/ir_attachment.py
@@ -4,15 +4,23 @@ import io
import logging
import xml.dom.minidom
import zipfile
-from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
-from pdfminer.converter import TextConverter
-from pdfminer.pdfpage import PDFPage
from odoo import api, models
_logger = logging.getLogger(__name__)
+
+try:
+ from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
+ from pdfminer.converter import TextConverter
+ from pdfminer.pdfpage import PDFPage
+except ImportError:
+ PDFResourceManager = PDFPageInterpreter = TextConverter = PDFPage = None
+ _logger.warning("Attachment indexation of PDF documents is unavailable because the 'pdfminer' Python library cannot be found on the system. "
+ "You may install it from https://pypi.org/project/pdfminer.six/ (e.g. `pip3 install pdfminer.six`)")
+
FTYPES = ['docx', 'pptx', 'xlsx', 'opendoc', 'pdf']
+
def textToString(element):
buff = u""
for node in element.childNodes:
@@ -93,6 +101,8 @@ class IrAttachment(models.Model):
def _index_pdf(self, bin_data):
'''Index PDF documents'''
+ if PDFResourceManager is None:
+ return
buf = u""
if bin_data.startswith(b'%PDF-'):
f = io.BytesIO(bin_data)
diff --git a/addons/attachment_indexation/tests/test_indexation.py b/addons/attachment_indexation/tests/test_indexation.py
index 9f5fa0eca15..36c558cdcc1 100644
--- a/addons/attachment_indexation/tests/test_indexation.py
+++ b/addons/attachment_indexation/tests/test_indexation.py
@@ -1,14 +1,21 @@
# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase, tagged
+from unittest import skipIf
import os
directory = os.path.dirname(__file__)
+try:
+ from pdfminer.pdfinterp import PDFResourceManager
+except ImportError:
+ PDFResourceManager = None
+
@tagged('post_install', '-at_install')
class TestCaseIndexation(TransactionCase):
+ @skipIf(PDFResourceManager is None, "pdfminer not installed")
def test_attachment_pdf_indexation(self):
with open(os.path.join(directory, 'files', 'test_content.pdf'), 'rb') as file:
pdf = file.read()