-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace code by odoo.tools.pdf
- Loading branch information
Showing
4 changed files
with
33 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Copyright 2022 Camptocamp SA | ||
# @author: Simone Orsi <[email protected]> | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
import logging | ||
|
||
from PyPDF2.utils import PdfReadError | ||
import logging | ||
|
||
from odoo import models | ||
from odoo import api, models | ||
|
||
from ..utils import PDFParser | ||
|
||
|
@@ -18,16 +18,16 @@ class PDFHelper(models.AbstractModel): | |
|
||
_PDF_PARSER_KLASS = PDFParser | ||
|
||
@api.model | ||
def pdf_get_xml_files(self, pdf_file): | ||
"""Extract XML attachments from pdf | ||
:param pdf_file: binary PDF file content | ||
:returns: a dict like {$filename: $parsed_xml_file_obj}. | ||
""" | ||
parser = self._PDF_PARSER_KLASS(pdf_file) | ||
try: | ||
return parser.get_xml_files() | ||
except self._pdf_get_xml_files_swallable_exceptions() as err: | ||
# TODO: can't we catch specific exceptions? | ||
# This try/except block was added to reflect what done | ||
# in base_business_document_import till now. | ||
except parser.get_xml_files_swallable_exceptions() as err: | ||
_logger.error("PDF file parsing failed: %s", str(err)) | ||
return {} | ||
|
||
def _pdf_get_xml_files_swallable_exceptions(self): | ||
return (KeyError, PdfReadError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* Simone Orsi <[email protected]> | ||
* Alexis de Lattre <[email protected]> | ||
* Jacques-Etienne Baudoux (BCIM) <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters