-
-
Notifications
You must be signed in to change notification settings - Fork 832
[16.0][MIG] report fillpdf #1013
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
Open
cvinh
wants to merge
11
commits into
OCA:16.0
Choose a base branch
from
invitu:16.0-mig-report_fillpdf
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
754eb74
[ADD] Report Fill PDF
etobella 9572ebb
[FIX] Fix error when having report_fill_pdf without installing pdftk
36b696d
OCA Transbot updated translations from Transifex
oca-transbot 2d34998
OCA Transbot updated translations from Transifex
oca-transbot 234ee5c
[IMP] report_fillpdf, report_xlsx, report_xml: Use content_dispositio…
naglis 734d2b9
[UPD] Update report_fillpdf.pot
oca-travis 2076e67
[IMP] report_fillpdf: black, isort, prettier
cvinh e97fc0f
[MIG] : Migration to 14.0
cvinh 3d1f751
[IMP] Add attachment support to report_fillpdf
cvinh eca6a64
[IMP] report_fillpdf: pre-commit stuff
cvinh e6c5cdf
[MIG] report_fillpdf: Migration to 16.0
cvinh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -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. |
This file contains hidden or 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 |
---|---|---|
@@ -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 |
This file contains hidden or 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 |
---|---|---|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to 16.0.1.0.0 |
||
"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", | ||
], | ||
}, | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains hidden or 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 |
---|---|---|
@@ -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) | ||
This file contains hidden or 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 |
---|---|---|
@@ -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">report_fillpdf.partner_fillpdf</field> | ||
<field name="report_file">res_partner</field> | ||
</record> | ||
</odoo> |
This file contains hidden or 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 |
---|---|---|
@@ -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 "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Creu Blanca, Odoo Community Association (OCA)"