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
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
Expand Down
28 changes: 28 additions & 0 deletions report_aeroo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,34 @@ The difference between this feature and a report attachment from `Advanced Setti
2. You do not need to redefine the name of the attachment in the email template.
The attachment name will be the one defined on the report.

Watermark Feature
=================
The module includes a TEST watermark feature for development and testing environments.

Configuration
-------------
To enable the TEST watermark on PDF reports, set the following configuration parameter:

.. code-block:: bash

# Enable TEST watermark
ir.config_parameter: AEROO_REPORTS_TESTS = True

# Disable TEST watermark (default)
ir.config_parameter: AEROO_REPORTS_TESTS = False

The watermark parameter can be set via the Odoo interface under Settings > Technical > Parameters > System Parameters.

.. image:: static/description/watermark_config_parameter.png

When enabled, all PDF reports generated through Aeroo will display a diagonal "TEST" watermark in red with transparency.

Example Result
--------------
When the watermark is enabled, PDF reports will show the TEST watermark overlaid on each page:

.. image:: static/description/watermark_example.png

Contributors
============
* Alistek
Expand Down
4 changes: 2 additions & 2 deletions report_aeroo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

{
"name": "Aeroo Reports",
"version": "16.0.1.0.1",
"version": "16.0.1.0.2",
"category": "Generic Modules/Aeroo Reports",
"summary": "Enterprise grade reporting solution",
"author": "Alistek",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"depends": ["mail", "spreadsheet_dashboard"],
"external_dependencies": {
"python": ["aeroolib", "babel", "genshi"],
"python": ["aeroolib", "babel", "genshi", "PyPDF2", "reportlab"],
},
"data": [
"security/security.xml",
Expand Down
6 changes: 6 additions & 0 deletions report_aeroo/data/report_aeroo_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@
<field name="code">csv</field>
<field name="compatible_types">ods</field>
</record>

<!-- Paramètre système pour les filigranes de test -->
<record model="ir.config_parameter" id="aeroo_reports_tests_param">
<field name="key">AEROO_REPORTS_TESTS</field>
<field name="value">False</field>
</record>
</data>
</odoo>
84 changes: 84 additions & 0 deletions report_aeroo/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@
from odoo.tools.safe_eval import safe_eval
from odoo.tools import file_open


from ..namespace import AerooNamespace
from ..extra_functions import aeroo_function_registry

_logger = logging.getLogger(__name__)


try:
from PyPDF2 import PdfFileWriter, PdfFileReader
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.colors import red

PYPDF_AVAILABLE = True
except ImportError:
PYPDF_AVAILABLE = False
_logger.warning(
"PyPDF2 and/or reportlab not available, watermark feature will not work!"
)


try:
# We use a jinja2 sandboxed environment to render mako templates.
# Note that the rendering does not cover all the mako syntax, in particular
Expand Down Expand Up @@ -399,6 +415,10 @@ def _render_aeroo_content(self, template, data, output_format):
if self.aeroo_in_format != output_format:
output = self._convert_aeroo_report(output, output_format)

# Add TEST watermark if parameter is enabled
if output_format == "pdf" and self._should_add_test_watermark():
output = self._add_test_watermark_to_pdf(output)

return output

def _get_aeroo_extra_functions(self):
Expand Down Expand Up @@ -606,6 +626,66 @@ def _merge_aeroo_pdf(self, input_files):

return output

def _should_add_test_watermark(self):
"""Check if TEST watermark should be added."""
param_value = (
self.env["ir.config_parameter"]
.sudo()
.get_param("AEROO_REPORTS_TESTS", "False")
)
return param_value.lower() == "true"

def _add_test_watermark_to_pdf(self, pdf_data):
"""Add TEST watermark to PDF."""
if not PYPDF_AVAILABLE:
_logger.warning("PyPDF2 and reportlab not available, cannot add watermark")
return pdf_data

try:
# Create watermark
watermark_buffer = BytesIO()
watermark_pdf = canvas.Canvas(watermark_buffer, pagesize=letter)

# Watermark configuration
watermark_pdf.setFillColor(red, alpha=0.3) # Red with transparency
watermark_pdf.setFont("Helvetica-Bold", 72) # Large size

# Center text on page
page_width, page_height = letter
text_width = watermark_pdf.stringWidth("TEST", "Helvetica-Bold", 72)
x = (page_width - text_width) / 2
y = page_height / 2

# Rotation for diagonal
watermark_pdf.saveState()
watermark_pdf.translate(x, y)
watermark_pdf.rotate(45)
watermark_pdf.drawString(-text_width / 2, 0, "TEST")
watermark_pdf.restoreState()

watermark_pdf.save()
watermark_buffer.seek(0)

original_pdf = PdfFileReader(BytesIO(pdf_data))
watermark_pdf_reader = PdfFileReader(watermark_buffer)
watermark_page = watermark_pdf_reader.pages[0]

output_pdf = PdfFileWriter()

for page in original_pdf.pages:
page.mergePage(watermark_page)
output_pdf.addPage(page)

output_buffer = BytesIO()
output_pdf.write(output_buffer)
output_buffer.seek(0)

return output_buffer.read()

except Exception as e:
_logger.error("Error adding watermark: %s", str(e))
return pdf_data


class IrActionsReportWithSudo(models.Model):

Expand Down Expand Up @@ -681,6 +761,10 @@ def _render_aeroo_from_list_of_records(
template, report_data, output_format
)

# Add TEST watermark if parameter is enabled
if output_format == "pdf" and self._should_add_test_watermark():
output = self._add_test_watermark_to_pdf(output)

return output, output_format

def _onchange_is_aeroo_list_report_set_multi(self):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.