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

[17.0][MIG] pdf_helper: Migration to 17.0 #911

Merged
merged 21 commits into from
Feb 2, 2024
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
108 changes: 108 additions & 0 deletions pdf_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
==========
PDF Helper
==========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d2b2944492ea6b07b30e0f22c55bc8b95ab88c35292fbb556969fb2809289dca
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/17.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-17-0/edi-17-0-pdf_helper
: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/edi&target_branch=17.0
:alt: Try me on Runboat

|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)

new_pdf_filecontent = env["pdf.helper"].pdf_embed_xml(pdf_filecontent, filename, xml)

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20pdf_helper%0Aversion:%2017.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]>
- Jacques-Etienne Baudoux (BCIM) <[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/17.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": "17.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",
],
}
22 changes: 22 additions & 0 deletions pdf_helper/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pdf_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-08-07 11:09+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: pdf_helper
#: model:ir.model,name:pdf_helper.model_pdf_helper
msgid "PDF Helper"
msgstr "Ayudante de PDF"
23 changes: 23 additions & 0 deletions pdf_helper/i18n/hr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pdf_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-06-02 12:09+0000\n"
"Last-Translator: Bole <[email protected]>\n"
"Language-Team: none\n"
"Language: hr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 4.17\n"

#. module: pdf_helper
#: model:ir.model,name:pdf_helper.model_pdf_helper
msgid "PDF Helper"
msgstr "PDF Pomoćnik"
19 changes: 19 additions & 0 deletions pdf_helper/i18n/pdf_helper.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pdf_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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,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
50 changes: 50 additions & 0 deletions pdf_helper/models/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 io
import logging

from odoo import api, models
from odoo.tools.pdf import NameObject, OdooPdfFileReader, OdooPdfFileWriter

from ..utils import PDFParser

_logger = logging.getLogger(__name__)


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

_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 parser.get_xml_files_swallable_exceptions() as err:
_logger.error("PDF file parsing failed: %s", str(err))
return {}

@api.model
def pdf_embed_xml(self, pdf_content, xml_filename, xml_string):
"""Add an XML attachment in a pdf"""
with io.BytesIO(pdf_content) as reader_buffer, io.BytesIO() as new_pdf_stream:
reader = OdooPdfFileReader(reader_buffer, strict=False)
writer = OdooPdfFileWriter()
writer.cloneReaderDocumentRoot(reader)
writer.addAttachment(xml_filename, xml_string, subtype="text/xml")
# show attachments when opening PDF
writer._root_object.update(
{NameObject("/PageMode"): NameObject("/UseAttachments")}
)
writer.write(new_pdf_stream)
return new_pdf_stream.getvalue()
3 changes: 3 additions & 0 deletions pdf_helper/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions pdf_helper/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Simone Orsi \<<[email protected]>\>
- Alexis de Lattre \<<[email protected]>\>
- Jacques-Etienne Baudoux (BCIM) \<<[email protected]>\>
1 change: 1 addition & 0 deletions pdf_helper/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Technical module to share PDF utils.
11 changes: 11 additions & 0 deletions pdf_helper/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Inside Odoo env:

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

new_pdf_filecontent = env["pdf.helper"].pdf_embed_xml(pdf_filecontent, filename, xml)

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
Loading