diff --git a/web_font_size_report_layout/README.rst b/web_font_size_report_layout/README.rst new file mode 100644 index 000000000000..c5a028ce7b7f --- /dev/null +++ b/web_font_size_report_layout/README.rst @@ -0,0 +1,116 @@ +=================================== +Report Font Size in Document Layout +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ee6f96a1077aace09df8bdf60b5d93ee172924b3bf73a462880b7c52adf87ab2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/17.0/web_font_size_report_layout + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_font_size_report_layout + :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/web&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This Odoo module adds the capability to customize font size in all PDF +reports throughout the system. Through a simple configuration, +administrators can select from a range of predefined font sizes +(measured in points) to optimize readability and appearance of invoices, +quotations, sales orders, and other printed documents. + +The module offers the following font size options (in points): + +============ ==== ========================= +Option Size Description +============ ==== ========================= +Extra Small 9pt For maximum compactness +Standard 10pt Odoo's default size +Small 11pt Just a little larger +Large 12pt Better readability +Extra Large 13pt Really Large +2Extra Large 14pt For high visibility needs +============ ==== ========================= + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +1. Copy the ``web_font_size_report_layout`` directory to your Odoo + addons folder +2. Update the module list from developer mode +3. Search for "Report Font Size in Document Layout" in the app store and + install it. + +Usage +===== + +Once installed: + +1. Go to **Settings → General Settings → Companies → Configure Document + Layout** +2. Locate the new **"Font Size"** field +3. Select your preferred size from the dropdown list +4. Look at Preview or Download PDF Preview +5. Save changes + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Binhex + +Contributors +------------ + +- `Binhex `__: +- Mario Montes +- Abraham J. Febres + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_font_size_report_layout/__init__.py b/web_font_size_report_layout/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_font_size_report_layout/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_font_size_report_layout/__manifest__.py b/web_font_size_report_layout/__manifest__.py new file mode 100644 index 000000000000..eee27b52729c --- /dev/null +++ b/web_font_size_report_layout/__manifest__.py @@ -0,0 +1,22 @@ +{ + "name": "Report Font Size in Document Layout", + "version": "17.0.1.1.0", + "summary": "Adds a font size selector (pt) to the Document Layout wizard", + "author": "Binhex," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "LGPL-3", + "depends": ["web"], + "data": [ + "views/base_document_layout_views.xml", + "views/report_templates_inherit.xml", + ], + "assets": { + "web.report_assets_common": [ + "web_font_size_report_layout/static/src/scss/report_font_size.scss" + ], + "web.report_assets_pdf": [ + "web_font_size_report_layout/static/src/scss/report_font_size.scss" + ], + }, + "installable": True, +} diff --git a/web_font_size_report_layout/models/__init__.py b/web_font_size_report_layout/models/__init__.py new file mode 100644 index 000000000000..290c7e13846b --- /dev/null +++ b/web_font_size_report_layout/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_company +from . import base_document_layout diff --git a/web_font_size_report_layout/models/base_document_layout.py b/web_font_size_report_layout/models/base_document_layout.py new file mode 100644 index 000000000000..53dea78187bc --- /dev/null +++ b/web_font_size_report_layout/models/base_document_layout.py @@ -0,0 +1,27 @@ +# web_font_size_report_layout/models/base_document_layout.py +import logging + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + + +class BaseDocumentLayout(models.TransientModel): + _inherit = "base.document.layout" + + report_font_size = fields.Selection( + related="company_id.report_font_size", + readonly=False, + string="Font size", + ) + + @api.onchange("report_font_size") + def _onchange_report_font_size(self): + func = getattr(self, "_compute_preview", None) + if not callable(func): + return + try: + func() + except Exception as exc: # pylint: disable=broad-except + _logger.debug("Failed computing document layout preview: %s", exc) + self.preview = False diff --git a/web_font_size_report_layout/models/res_company.py b/web_font_size_report_layout/models/res_company.py new file mode 100644 index 000000000000..eb0a6b47569d --- /dev/null +++ b/web_font_size_report_layout/models/res_company.py @@ -0,0 +1,47 @@ +from odoo import api, fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + report_font_size = fields.Selection( + selection=[ + ("9", "9 pt"), + ("10", "10 pt"), + ("11", "11 pt"), + ("12", "12 pt"), + ("13", "13 pt"), + ("14", "14 pt"), + ], + string="Report font size", + default="11", + help="Base font size for PDF content (in points), applied on the external " + "report layout.", + ) + + @api.model_create_multi + def create(self, vals_list): + companies = super().create(vals_list) + style_fields = { + "external_report_layout_id", + "font", + "report_font_size", + "primary_color", + "secondary_color", + } + if any(not style_fields.isdisjoint(values) for values in vals_list): + self._update_asset_style() + return companies + + def write(self, values): + res = super().write(values) + style_fields = { + "external_report_layout_id", + "font", + "report_font_size", + "primary_color", + "secondary_color", + } + if not style_fields.isdisjoint(values): + self._update_asset_style() + return res diff --git a/web_font_size_report_layout/pyproject.toml b/web_font_size_report_layout/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_font_size_report_layout/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_font_size_report_layout/readme/CONTRIBUTORS.md b/web_font_size_report_layout/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..f796d63ad965 --- /dev/null +++ b/web_font_size_report_layout/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Binhex](https://www.binhex.cloud): +- Mario Montes\<\> +- Abraham J. Febres \<\> diff --git a/web_font_size_report_layout/readme/DESCRIPTION.md b/web_font_size_report_layout/readme/DESCRIPTION.md new file mode 100644 index 000000000000..e06642cb2216 --- /dev/null +++ b/web_font_size_report_layout/readme/DESCRIPTION.md @@ -0,0 +1,12 @@ +This Odoo module adds the capability to customize font size in all PDF reports throughout the system. Through a simple configuration, administrators can select from a range of predefined font sizes (measured in points) to optimize readability and appearance of invoices, quotations, sales orders, and other printed documents. + +The module offers the following font size options (in points): + +| Option | Size | Description | +|--------|------|-------------| +| Extra Small | 9pt | For maximum compactness | +| Standard | 10pt | Odoo's default size | +| Small | 11pt | Just a little larger | +| Large | 12pt | Better readability | +| Extra Large | 13pt | Really Large | +| 2Extra Large | 14pt | For high visibility needs | diff --git a/web_font_size_report_layout/readme/INSTALL.md b/web_font_size_report_layout/readme/INSTALL.md new file mode 100644 index 000000000000..91069158fc0e --- /dev/null +++ b/web_font_size_report_layout/readme/INSTALL.md @@ -0,0 +1,3 @@ +1. Copy the `web_font_size_report_layout` directory to your Odoo addons folder +2. Update the module list from developer mode +3. Search for "Report Font Size in Document Layout" in the app store and install it. diff --git a/web_font_size_report_layout/readme/USAGE.md b/web_font_size_report_layout/readme/USAGE.md new file mode 100644 index 000000000000..cf1e758aaa01 --- /dev/null +++ b/web_font_size_report_layout/readme/USAGE.md @@ -0,0 +1,7 @@ +Once installed: + +1. Go to **Settings → General Settings → Companies → Configure Document Layout** +2. Locate the new **"Font Size"** field +3. Select your preferred size from the dropdown list +5. Look at Preview or Download PDF Preview +4. Save changes diff --git a/web_font_size_report_layout/static/description/index.html b/web_font_size_report_layout/static/description/index.html new file mode 100644 index 000000000000..3e44f97df63d --- /dev/null +++ b/web_font_size_report_layout/static/description/index.html @@ -0,0 +1,493 @@ + + + + + +Report Font Size in Document Layout + + + +
+

Report Font Size in Document Layout

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This Odoo module adds the capability to customize font size in all PDF +reports throughout the system. Through a simple configuration, +administrators can select from a range of predefined font sizes +(measured in points) to optimize readability and appearance of invoices, +quotations, sales orders, and other printed documents.

+

The module offers the following font size options (in points):

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionSizeDescription
Extra Small9ptFor maximum compactness
Standard10ptOdoo’s default size
Small11ptJust a little larger
Large12ptBetter readability
Extra Large13ptReally Large
2Extra Large14ptFor high visibility needs
+

Table of contents

+ +
+

Installation

+
    +
  1. Copy the web_font_size_report_layout directory to your Odoo +addons folder
  2. +
  3. Update the module list from developer mode
  4. +
  5. Search for “Report Font Size in Document Layout” in the app store and +install it.
  6. +
+
+
+

Usage

+

Once installed:

+
    +
  1. Go to Settings → General Settings → Companies → Configure Document +Layout
  2. +
  3. Locate the new “Font Size” field
  4. +
  5. Select your preferred size from the dropdown list
  6. +
  7. Look at Preview or Download PDF Preview
  8. +
  9. Save changes
  10. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Binhex
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_font_size_report_layout/static/src/scss/report_font_size.scss b/web_font_size_report_layout/static/src/scss/report_font_size.scss new file mode 100644 index 000000000000..3aa60f231e11 --- /dev/null +++ b/web_font_size_report_layout/static/src/scss/report_font_size.scss @@ -0,0 +1,15 @@ +/* Valor por defecto en pt */ +:root { + --report-font-size: 11pt; +} + +/* Aplica al wrapper típico y a .page (usado por algunos informes) */ +.o_report_layout, +.page { + font-size: var(--report-font-size) !important; +} + +.o_report_layout *, +.page * { + font-size: inherit !important; +} diff --git a/web_font_size_report_layout/tests/__init__.py b/web_font_size_report_layout/tests/__init__.py new file mode 100644 index 000000000000..18a2b6ed09f7 --- /dev/null +++ b/web_font_size_report_layout/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_company_font_size +from . import test_document_layout_onchange diff --git a/web_font_size_report_layout/tests/test_company_font_size.py b/web_font_size_report_layout/tests/test_company_font_size.py new file mode 100644 index 000000000000..4c7df5ca5c48 --- /dev/null +++ b/web_font_size_report_layout/tests/test_company_font_size.py @@ -0,0 +1,47 @@ +from odoo.tests.common import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestCompanyFontSize(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Company = cls.env["res.company"] + + def test_default_and_selection_values(self): + co = self.Company.create({"name": "Co A"}) + self.assertEqual(co.report_font_size, "11") + co.report_font_size = "9" + self.assertEqual(co.report_font_size, "9") + + def test_create_with_explicit_font_size_persists(self): + co = self.Company.create({"name": "Co B", "report_font_size": "12"}) + self.assertEqual(co.report_font_size, "12") + + def test_write_only_style_field_is_safe(self): + co = self.Company.create({"name": "Co C"}) + co.write({"report_font_size": "14"}) + self.assertEqual(co.report_font_size, "14") + + def test_write_unrelated_fields_dont_affect_font_size(self): + co = self.Company.create({"name": "Co D"}) + old = co.report_font_size + co.write({"email": "x@example.com"}) + self.assertEqual(co.report_font_size, old) + + def test_multi_company_independence(self): + co1 = self.Company.create({"name": "Co E"}) + co2 = self.Company.create({"name": "Co F"}) + co1.write({"report_font_size": "9"}) + co2.write({"report_font_size": "14"}) + self.assertEqual(co1.report_font_size, "9") + self.assertEqual(co2.report_font_size, "14") + + def test_multiple_changes_persist_in_sequence(self): + co = self.Company.create({"name": "Co G"}) + co.write({"report_font_size": "14"}) + self.assertEqual(co.report_font_size, "14") + co.write({"report_font_size": "10"}) + self.assertEqual(co.report_font_size, "10") + co.write({"report_font_size": "12"}) + self.assertEqual(co.report_font_size, "12") diff --git a/web_font_size_report_layout/tests/test_document_layout_onchange.py b/web_font_size_report_layout/tests/test_document_layout_onchange.py new file mode 100644 index 000000000000..6869dde61aca --- /dev/null +++ b/web_font_size_report_layout/tests/test_document_layout_onchange.py @@ -0,0 +1,47 @@ +from unittest.mock import patch + +from odoo.tests.common import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestDocumentLayoutOnchange(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Company = cls.env["res.company"] + cls.company = cls.Company.create({"name": "WZ Co", "report_font_size": "11"}) + cls.Wizard = cls.env["base.document.layout"] + + def test_onchange_when_compute_preview_absent_does_nothing(self): + wiz = self.Wizard.with_company(self.company.id).create( + {"company_id": self.company.id} + ) + prev = getattr(wiz, "preview", None) + wiz.report_font_size = "10" + + with patch.object(type(wiz), "_compute_preview", new=None, create=True): + wiz._onchange_report_font_size() + + self.assertEqual(getattr(wiz, "preview", None), prev) + + def test_onchange_handles_compute_exception_sets_preview_false(self): + wiz = self.Wizard.with_company(self.company.id).create( + {"company_id": self.company.id} + ) + self.assertIn("preview", wiz._fields) + wiz.report_font_size = "14" + + with patch.object( + type(wiz), "_compute_preview", side_effect=Exception("boom"), create=True + ): + wiz._onchange_report_font_size() + + self.assertFalse(bool(wiz.preview)) + + def test_onchange_updates_wizard_field_without_crash(self): + wiz = self.Wizard.with_company(self.company.id).create( + {"company_id": self.company.id} + ) + wiz.report_font_size = "14" + wiz._onchange_report_font_size() + self.assertEqual(wiz.report_font_size, "14") diff --git a/web_font_size_report_layout/views/base_document_layout_views.xml b/web_font_size_report_layout/views/base_document_layout_views.xml new file mode 100644 index 000000000000..9d1ebae03fb8 --- /dev/null +++ b/web_font_size_report_layout/views/base_document_layout_views.xml @@ -0,0 +1,14 @@ + + + + base.document.layout.font.size + base.document.layout + + 50 + + + + + + + diff --git a/web_font_size_report_layout/views/report_templates_inherit.xml b/web_font_size_report_layout/views/report_templates_inherit.xml new file mode 100644 index 000000000000..67e834f2008e --- /dev/null +++ b/web_font_size_report_layout/views/report_templates_inherit.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + +