Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] pdf_helper #736

Merged
merged 9 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions pdf_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
==========
PDF Helper
==========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/14.0/pdf_helper
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-pdf_helper
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/226/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Technical module to share PDF utils.

**Table of contents**

.. contents::
:local:

Usage
=====

Inside Odoo env::

res = env["pdf.helper"].pdf_get_xml_files(pdf_filecontent)

Outside Odoo env::

from odoo.addons.pdf_helper.utils import PDFParser
[...]
res = PDFParser(pdf_filecontent).get_xml_files()

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20pdf_helper%0Aversion:%2014.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.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Simone Orsi <[email protected]>
* Alexis de Lattre <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk
.. |maintainer-alexis-via| image:: https://github.com/alexis-via.png?size=40px
:target: https://github.com/alexis-via
:alt: alexis-via

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk| |maintainer-alexis-via|

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/pdf_helper>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions pdf_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions pdf_helper/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

# TODO: move it to a simple python package under OCA umbrella?
{
"name": "PDF Helper",
"version": "15.0.1.0.0",
"category": "Tools",
"license": "LGPL-3",
"summary": "Provides helpers to work w/ PDFs",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk", "alexis-via"],
"website": "https://github.com/OCA/edi",
"depends": [
"base",
],
}
34 changes: 34 additions & 0 deletions pdf_helper/i18n/pdf_helper.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pdf_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: pdf_helper
#: model:ir.model.fields,field_description:pdf_helper.field_pdf_helper__display_name
msgid "Display Name"
msgstr ""

#. module: pdf_helper
#: model:ir.model.fields,field_description:pdf_helper.field_pdf_helper__id
msgid "ID"
msgstr ""

#. module: pdf_helper
#: model:ir.model.fields,field_description:pdf_helper.field_pdf_helper____last_update
msgid "Last Modified on"
msgstr ""

#. module: pdf_helper
#: model:ir.model,name:pdf_helper.model_pdf_helper
msgid "PDF Helper"
msgstr ""
1 change: 1 addition & 0 deletions pdf_helper/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import helper
33 changes: 33 additions & 0 deletions pdf_helper/models/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging

from PyPDF2.utils import PdfReadError

from odoo import models

from ..utils import PDFParser

_logger = logging.getLogger(__name__)


class PDFHelper(models.AbstractModel):
_name = "pdf.helper"
_description = "PDF Helper"

_PDF_PARSER_KLASS = PDFParser

def pdf_get_xml_files(self, pdf_file):
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.
_logger.error("PDF file parsing failed: %s", str(err))
return {}

def _pdf_get_xml_files_swallable_exceptions(self):
return (KeyError, PdfReadError)
2 changes: 2 additions & 0 deletions pdf_helper/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Simone Orsi <[email protected]>
* Alexis de Lattre <[email protected]>
1 change: 1 addition & 0 deletions pdf_helper/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Technical module to share PDF utils.
9 changes: 9 additions & 0 deletions pdf_helper/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Inside Odoo env::

res = env["pdf.helper"].pdf_get_xml_files(pdf_filecontent)

Outside Odoo env::

from odoo.addons.pdf_helper.utils import PDFParser
[...]
res = PDFParser(pdf_filecontent).get_xml_files()
Binary file added pdf_helper/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading