Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ addon | version | maintainers | summary
--- | --- | --- | ---
[base_comment_template](base_comment_template/) | 19.0.0.0.0 | | Add conditional mako template to any reporton models that inherits comment.template.
[bi_sql_editor](bi_sql_editor/) | 19.0.1.0.1 | <a href='https://github.com/legalsylvain'><img src='https://github.com/legalsylvain.png' width='32' height='32' style='border-radius:50%;' alt='legalsylvain'/></a> | BI Views builder, based on Materialized or Normal SQL Views
[pdf_xml_attachment](pdf_xml_attachment/) | 19.0.1.0.0 | <a href='https://github.com/simahawk'><img src='https://github.com/simahawk.png' width='32' height='32' style='border-radius:50%;' alt='simahawk'/></a> <a href='https://github.com/alexis-via'><img src='https://github.com/alexis-via.png' width='32' height='32' style='border-radius:50%;' alt='alexis-via'/></a> | Provides helpers to work w/ PDFs and XML attachments
[report_context](report_context/) | 19.0.1.0.0 | | Adding context to reports
[report_csv](report_csv/) | 19.0.1.0.0 | | Base module to create csv report
[report_partner_address](report_partner_address/) | 19.0.1.0.0 | <a href='https://github.com/yostashiro'><img src='https://github.com/yostashiro.png' width='32' height='32' style='border-radius:50%;' alt='yostashiro'/></a> <a href='https://github.com/aungkokolin1997'><img src='https://github.com/aungkokolin1997.png' width='32' height='32' style='border-radius:50%;' alt='aungkokolin1997'/></a> | Translatable partner address details for reports and portal
Expand Down
112 changes: 112 additions & 0 deletions pdf_xml_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==================
PDF XML attachment
==================

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

.. |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/license-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%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/19.0/pdf_xml_attachment
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-19-0/reporting-engine-19-0-pdf_xml_attachment
: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/reporting-engine&target_branch=19.0
:alt: Try me on Runboat

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

Technical module to share easily deal with XML attachments in PDF files.

**Table of contents**

.. contents::
:local:

Usage
=====

Inside Odoo env:

::

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

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

Outside Odoo env:

::

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

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/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/reporting-engine/issues/new?body=module:%20pdf_xml_attachment%0Aversion:%2019.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 <simone.orsi@camptocamp.com>
- Alexis de Lattre <alexis.delattre@akretion.com>
- Jacques-Etienne Baudoux (BCIM) <je@bcim.be>

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/reporting-engine <https://github.com/OCA/reporting-engine/tree/19.0/pdf_xml_attachment>`_ 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_xml_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions pdf_xml_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simahawk@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "PDF XML attachment",
"version": "19.0.1.0.0",
"category": "Tools",
"license": "LGPL-3",
"summary": "Provides helpers to work w/ PDFs and XML attachments",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk", "alexis-via"],
"website": "https://github.com/OCA/reporting-engine",
"depends": [
"base",
],
}
22 changes: 22 additions & 0 deletions pdf_xml_attachment/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_xml_attachment
#
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 <informatica@totmaterial.es>\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_xml_attachment
#: model:ir.model,name:pdf_xml_attachment.model_pdf_xml_tool
msgid "PDF XML attachment"
msgstr "Ayudante de PDF"
23 changes: 23 additions & 0 deletions pdf_xml_attachment/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_xml_attachment
#
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 <bole@dajmi5.com>\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_xml_attachment
#: model:ir.model,name:pdf_xml_attachment.model_pdf_xml_tool
msgid "PDF XML attachment"
msgstr "PDF Pomoćnik"
22 changes: 22 additions & 0 deletions pdf_xml_attachment/i18n/it.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_xml_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-02-04 23:45+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\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_xml_attachment
#: model:ir.model,name:pdf_xml_attachment.model_pdf_xml_tool
msgid "PDF XML attachment"
msgstr "Aiuto PDF"
29 changes: 29 additions & 0 deletions pdf_xml_attachment/i18n/pdf_xml_attachment.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pdf_xml_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 19.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_xml_attachment
#: model:ir.model.fields,field_description:pdf_xml_attachment.field_pdf_xml_tool__display_name
msgid "Display Name"
msgstr ""

#. module: pdf_xml_attachment
#: model:ir.model.fields,field_description:pdf_xml_attachment.field_pdf_xml_tool__id
msgid "ID"
msgstr ""

#. module: pdf_xml_attachment
#: model:ir.model,name:pdf_xml_attachment.model_pdf_xml_tool
msgid "PDF XML attachment"
msgstr ""
1 change: 1 addition & 0 deletions pdf_xml_attachment/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_xml_attachment/models/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simahawk@gmail.com>
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# 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.xml.tool"
_description = "PDF XML attachment"

_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_xml_attachment/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_xml_attachment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Simone Orsi \<<simone.orsi@camptocamp.com>\>
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
- Jacques-Etienne Baudoux (BCIM) \<<je@bcim.be>\>
1 change: 1 addition & 0 deletions pdf_xml_attachment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Technical module to share easily deal with XML attachments in PDF files.
11 changes: 11 additions & 0 deletions pdf_xml_attachment/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Inside Odoo env:

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

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

Outside Odoo env:

from odoo.addons.pdf_xml_attachment.utils import PDFParser
[...]
res = PDFParser(pdf_filecontent).get_xml_files()
Binary file added pdf_xml_attachment/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