Skip to content
Closed
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
661 changes: 661 additions & 0 deletions report_pylatex/LICENSE

Large diffs are not rendered by default.

274 changes: 274 additions & 0 deletions report_pylatex/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
==================
PyLatex Report Engine
==================

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

.. |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-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_pylatex
: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-16-0/reporting-engine-16-0-report_pylatex
: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=16.0
:alt: Try me on Runboat

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

The PyLatex reporting engine is a reporting engine for Odoo based on `PyLatex Libraty <https://pypi.org/project/PyLaTeX/>`_:

* the report is created in pdf format,


The key advantages of a PyLatex based reporting engine are:

* The possibility to use the Latex language to produce PDF document


**Table of contents**

.. contents::
:local:

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

Install the required python libs:

.. code::

pip install PyLatex [Already in __manifest__]
sudo apt-get install latexmk for better rendering
sudo apt-get install texlive-full for a complete latex support

Configuration
=============

For example, to replace the native invoice report by a custom pylatex report, add the following XML file in your custom module:

.. code-block:: XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account.account_invoices" model="ir.actions.report">
<field name="report_type">pylatex</field>
<field name="module">my_custom_module_base</field>
<field name="report_code">
def generate_unique(self, record_id, data):
import pylatex
doc = pylatex.Document()
return doc
</field>
</record>
</odoo>

.. code-block:: PYTHON

def generate_unique(self, record_id, data):
import pylatex
geometry_options = {"head": "40pt", "margin": "0.5in", "bottom": "0.6in", "includeheadfoot": True}
doc = pylatex.Document(geometry_options=geometry_options)
#
# Configure heder
#
first_page = pylatex.PageStyle("firstpage")
#
# Header image
#
with first_page.create(pylatex.Head("L")) as header_left:
with header_left.create(pylatex.MiniPage(width=pylatex.utils.NoEscape(r"0.49\textwidth"),
pos='c')) as title_wrapper:
title_wrapper.append(pylatex.SmallText(pylatex.utils.bold(f"{record_id.company_id.name} • {record_id.company_id.street} • {record_id.company_id.zip} {record_id.company_id.city}")))


# Add document title
with first_page.create(pylatex.Head("R")) as right_header:
with right_header.create(pylatex.MiniPage(width=NoEscape(r"0.49\textwidth"),
pos='c', align='r')) as title_wrapper:
logo_file = self.getImagePathFromContent(record_id.company_id.logo)
title_wrapper.append(pylatex.StandAloneGraphic(image_options="width=120px",
filename=logo_file))
title_wrapper.append("\n")
title_wrapper.append(pylatex.LargeText(pylatex.utils.bold(record_id.partner_id.display_name)))
title_wrapper.append(pylatex.LineBreak())
title_wrapper.append(pylatex.MediumText(pylatex.utils.bold(record_id.date_order)))

doc.preamble.append(first_page)
#
#Add customer information
with doc.create(pylatex.Tabu("X[l] X[r]")) as first_page_table:
customer = pylatex.MiniPage(width=NoEscape(r"0.49\textwidth"), pos='h')
customer.append("Verna Volcano")
customer.append("\n")
customer.append("For some Person")
customer.append("\n")
customer.append("Address1")
customer.append("\n")
customer.append("Address2")
customer.append("\n")
customer.append("Address3")

# Add branch information
branch = pylatex.MiniPage(width=NoEscape(r"0.49\textwidth"), pos='t!',
align='r')
branch.append("Branch no.")
branch.append(pylatex.LineBreak())
branch.append(pylatex.utils.bold("1181..."))
branch.append(pylatex.LineBreak())
branch.append(pylatex.utils.bold("TIB Cheque"))

first_page_table.add_row([customer, branch])
first_page_table.add_empty_row()

# Add footer
with first_page.create(pylatex.Foot("C")) as footer:
message = "Important message please read"
with footer.create(pylatex.Tabularx(
"X X X X",
width_argument=pylatex.utils.NoEscape(r"\textwidth"))) as footer_table:

footer_table.add_row(
[pylatex.MultiColumn(4, align='l', data=pylatex.TextColor("blue", message))])
footer_table.add_hline(color="blue")
footer_table.add_empty_row()

branch_address = pylatex.MiniPage(
width=NoEscape(r"0.25\textwidth"),
pos='t')
branch_address.append("960 - 22nd street east")
branch_address.append("\n")
branch_address.append("Saskatoon, SK")

document_details = pylatex.MiniPage(width=pylatex.utils.NoEscape(r"0.25\textwidth"),
pos='t', align='r')
document_details.append("1000")
document_details.append(pylatex.LineBreak())
document_details.append(pylatex.simple_page_number())

footer_table.add_row([branch_address, branch_address,
branch_address, document_details])
doc.change_document_style("firstpage")

#
# Add statement table
#
with doc.create(pylatex.LongTabu("X[l] X[2l] X[r] X[r] X[r] X[r]",
row_height=1.5)) as data_table:
data_table.add_row(["Position",
"Name",
"Description",
"Qty",
"UnitPrice",
"RawPrice"],
mapper=pylatex.utils.bold,
color="lightgray")
data_table.add_empty_row()
data_table.add_hline()
for i, sale_order_line in enumerate(record_id.order_line):
row = [sale_order_line.sequence,
sale_order_line.product_id.display_name,
sale_order_line.name,
sale_order_line.product_uom_qty,
sale_order_line.price_unit,
sale_order_line.price_subtotal
]
if (i % 2) == 0:
data_table.add_row(row, color="lightgray")
else:
data_table.add_row(row)
#
return doc
where *my_custom_module_base* is the name of the custom Odoo module.


Usage
=====

The templating language is `extensively documented <https://jeltef.github.io/PyLaTeX/current/>`,
Setting pepersize and margin https://www.overleaf.com/learn/latex/Page_size_and_margins

Available functions and objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code::
# manage Image from the filed binary content
tmp_img_path = getImagePathFromContent(field_content)

#get the path of a generic binary content
tmp_img_path = getPathFromContent(content, exte)

#get PyLatexStandAloneGraphic object
def StandAloneGraphic(self,
field_content,
**args)
es:
img = self.StandAloneGraphic(record_id.company_id.logo,
image_options="width=200px")
#
# if the field is false return empty string
getEmptyIfNot(self, record_brw, field_name)

# get a minpage from the res_partner object
def get_partner_address_minipage(self, partner_id, fields=[])


Known issues / Roadmap
======================


* Manage multi report now it works only for one record at the time


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:%20report_pylatex%0Aversion:%2016.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
~~~~~~~

* OmniaSolutions


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

* Matteo Boscolo <matteo.boscolo@omniasolutions.eu>

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.

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_pylatex>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
24 changes: 24 additions & 0 deletions report_pylatex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import models
from . import controllers
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
51 changes: 51 additions & 0 deletions report_pylatex/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Pylatex Reporting connection',
'description': """
Technical : Improve odoo reporting to also use pylatex for report generation
https://jeltef.github.io/PyLaTeX/latest/faq.html
============================================================================
""",
'version': '16.0.2',
'sequence':1,
'author': 'OmniaSolutions',
"license": "AGPL-3",
"summary": "pylatex Reporting",
'website': 'http://www.omniasolutions.website',
"category": "Reporting",
'depends': ["base","mail"],
'external_dependencies': {'python': ['pylatex','cssutils','more_itertools','lxml','cssutils']},
'data': [# security
# views
'views/ir_report.xml',
# wizard
# report
# data
],
"assets": {
"web.assets_backend": [
"report_pylatex/static/src/js/report/action_manager_report.js"
],
},
'installable': True,
}
1 change: 1 addition & 0 deletions report_pylatex/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
Loading