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

[MIG] Migrate report_fillpdf to 16.0 #799

Closed
wants to merge 11 commits into from
116 changes: 116 additions & 0 deletions report_fillpdf/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

====================
Base report fill PDF
====================

This module provides a basic report class that fills pdfs.

Installation
============

Make sure you have ``fdfgen`` Python module installed::

$ pip install fdfgen

For testing it is also necessary ``pdftk`` app installed:

Ubuntu ::

apt-get install pdftk

OSX ::

* Install pdftk (https://www.pdflabs.com/tools/pdftk-server/).

Windows ::

* Install pdftk (https://www.pdflabs.com/tools/pdftk-server/).

Usage
=====

An example of Fill PDF report for partners on a module called `module_name`:

A python class ::

from odoo import models

class PartnerFillPDF(models.AbstractModel):
_name = 'report.module_name.report_name'
_inherit = 'report.report_fillpdf.abstract'

@api.model
def get_original_document_path(self, data, objs):
return get_resource_path(
'report_fillpdf', 'static/src/pdf', 'partner_pdf.pdf')

@api.model
def get_document_values(self, data, objs):
objs.ensure_one()
return {'name': objs.name}

A computed form can be executed modifying the computing function ::

from odoo import models

class PartnerFillPDF(models.AbstractModel):
_name = 'report.module_name.report_name'
_inherit = 'report.report_fillpdf.abstract'

@api.model
def get_form(self, data, objs):
return self.env['ir.attachment'].search([], limit=1)

@api.model
def get_document_values(self, data, objs):
objs.ensure_one()
return {'name': objs.name}


A report XML record ::

<report
id="partner_fillpdf"
model="res.partner"
string="Fill PDF"
report_type="fillpdf"
name="report_fillpdf.partner_fillpdf"
file="res_partner"
attachment_use="False"
/>

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/143/11.0

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 smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Enric Tobella <[email protected]>

Maintainer
----------

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
5 changes: 5 additions & 0 deletions report_fillpdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import controllers
from . import models
from . import report
34 changes: 34 additions & 0 deletions report_fillpdf/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2017 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Base report PDF Filler",
"summary": """
Base module that fills PDFs""",
"author": "Creu Blanca," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"category": "Reporting",
"version": "16.0.1.0.1",
"license": "AGPL-3",
"external_dependencies": {
"python": [
"fdfgen",
],
"deb": [
"pdftk",
],
},
"depends": [
"base",
"web",
],
"data": [],
"demo": [
"demo/report.xml",
],
"installable": True,
"assets": {
"web.assets_backend": [
"report_fillpdf/static/src/js/report/action_manager_report.esm.js",
],
},
}
1 change: 1 addition & 0 deletions report_fillpdf/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
99 changes: 99 additions & 0 deletions report_fillpdf/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright (C) 2017 Creu Blanca
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).

import json
import logging

from werkzeug.urls import url_decode

from odoo.http import (
content_disposition,
request,
route,
serialize_exception as _serialize_exception,
)
from odoo.tools import html_escape
from odoo.tools.safe_eval import safe_eval, time

from odoo.addons.web.controllers.report import ReportController

_logger = logging.getLogger(__name__)


class ReportController(ReportController):
@route()
def report_routes(self, reportname, docids=None, converter=None, **data):
if converter == "fillpdf":
report = request.env["ir.actions.report"]._get_report_from_name(reportname)
context = dict(request.env.context)
if docids:
docids = [int(i) for i in docids.split(",")]
if data.get("options"):
data.update(json.loads(data.pop("options")))
if data.get("context"):
data["context"] = json.loads(data["context"])
context.update(data["context"])
pdf = report.with_context(**context).render_fillpdf(
reportname, docids, data=data
)[0]
pdfhttpheaders = [
("Content-Type", "application/pdf"),
("Content-Length", len(pdf)),
]
return request.make_response(pdf, headers=pdfhttpheaders)
return super().report_routes(reportname, docids, converter, **data)

@route()
def report_download(self, data, context=None, token=None):
requestcontent = json.loads(data)
url, report_type = requestcontent[0], requestcontent[1]
if report_type == "fillpdf":
try:
reportname = url.split("/report/fillpdf/")[1].split("?")[0]
docids = None
if "/" in reportname:
reportname, docids = reportname.split("/")
if docids:
# Generic report:
response = self.report_routes(
reportname, docids=docids, converter="fillpdf", context=context
)
else:
# Particular report:
data = dict(
url_decode(url.split("?")[1]).items()
) # decoding the args represented in JSON
if "context" in data:
context, data_context = json.loads(context or "{}"), json.loads(
data.pop("context")
)
context = json.dumps({**context, **data_context})
response = self.report_routes(
reportname, converter="fillpdf", context=context, **data
)

report = request.env["ir.actions.report"]._get_report_from_name(
reportname
)
filename = "%s.%s" % (report.name, "pdf")

if docids:
ids = [int(x) for x in docids.split(",")]
obj = request.env[report.model].browse(ids)
if report.print_report_name and not len(obj) > 1:
report_name = safe_eval(
report.print_report_name, {"object": obj, "time": time}
)
filename = "%s.%s" % (report_name, "pdf")
if not response.headers.get("Content-Disposition"):
response.headers.add(
"Content-Disposition", content_disposition(filename)
)
return response
except Exception as e:
_logger.exception("Error while generating report %s", reportname)
se = _serialize_exception(e)
error = {"code": 200, "message": "Odoo Server Error", "data": se}
return request.make_response(html_escape(json.dumps(error)))
else:
return super().report_download(data, context=context, token=token)
14 changes: 14 additions & 0 deletions report_fillpdf/demo/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--
© 2017 Creu Blanca
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
-->
<record model="ir.actions.report" id="partner_fillpdf">
<field name="name">report_fillpdf.partner_fillpdf</field>
<field name="model">res.partner</field>
<field name="report_type">fillpdf</field>
<field name="report_name">res_partner</field>
<field name="report_file">res_partner</field>
</record>
</odoo>
63 changes: 63 additions & 0 deletions report_fillpdf/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * report_fillpdf
#
# Translators:
# Ricardo Gross <[email protected]>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-23 03:49+0000\n"
"PO-Revision-Date: 2017-12-23 03:49+0000\n"
"Last-Translator: Ricardo Gross <[email protected]>, 2017\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"Language: de\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"

#. module: report_fillpdf
#: code:addons/report_fillpdf/models/ir_report.py:18
#, python-format
msgid "%s model was not found"
msgstr "%s Modell wurde nicht gefunden"

#. module: report_fillpdf
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_abstract_display_name
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_partner_fillpdf_display_name
msgid "Display Name"
msgstr "Name anzeigen"

#. module: report_fillpdf
#: model:ir.actions.report,name:report_fillpdf.partner_fillpdf
msgid "Fill PDF"
msgstr "PDF ausfüllen"

#. module: report_fillpdf
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_abstract_id
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_partner_fillpdf_id
msgid "ID"
msgstr "ID"

#. module: report_fillpdf
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_abstract___last_update
#: model:ir.model.fields,field_description:report_fillpdf.field_report_report_fillpdf_partner_fillpdf___last_update
msgid "Last Modified on"
msgstr "Zuletzt geändert am"

#. module: report_fillpdf
#: model:ir.model,name:report_fillpdf.model_ir_actions_report
msgid "ir.actions.report"
msgstr ""

#. module: report_fillpdf
#: model:ir.model,name:report_fillpdf.model_report_report_fillpdf_abstract
msgid "report.report_fillpdf.abstract"
msgstr ""

#. module: report_fillpdf
#: model:ir.model,name:report_fillpdf.model_report_report_fillpdf_partner_fillpdf
msgid "report.report_fillpdf.partner_fillpdf"
msgstr ""
Loading
Loading