From faf0415ac40c2157dc95826feddf876c377ffb9b Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Wed, 13 Dec 2023 18:06:27 +0100 Subject: [PATCH] [ADD] account_invoice_report_pagebreak --- account_invoice_report_pagebreak/__init__.py | 0 .../__manifest__.py | 20 +++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 + .../readme/ROADMAP.rst | 2 + .../reports/report_invoice.xml | 15 ++++ .../tests/__init__.py | 1 + .../tests/test_invoice_report_breakpage.py | 73 +++++++++++++++++++ .../addons/account_invoice_report_pagebreak | 1 + .../account_invoice_report_pagebreak/setup.py | 6 ++ test-requirements.txt | 1 + 11 files changed, 124 insertions(+) create mode 100644 account_invoice_report_pagebreak/__init__.py create mode 100644 account_invoice_report_pagebreak/__manifest__.py create mode 100644 account_invoice_report_pagebreak/readme/CONTRIBUTORS.rst create mode 100644 account_invoice_report_pagebreak/readme/DESCRIPTION.rst create mode 100644 account_invoice_report_pagebreak/readme/ROADMAP.rst create mode 100644 account_invoice_report_pagebreak/reports/report_invoice.xml create mode 100644 account_invoice_report_pagebreak/tests/__init__.py create mode 100644 account_invoice_report_pagebreak/tests/test_invoice_report_breakpage.py create mode 120000 setup/account_invoice_report_pagebreak/odoo/addons/account_invoice_report_pagebreak create mode 100644 setup/account_invoice_report_pagebreak/setup.py create mode 100644 test-requirements.txt diff --git a/account_invoice_report_pagebreak/__init__.py b/account_invoice_report_pagebreak/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/account_invoice_report_pagebreak/__manifest__.py b/account_invoice_report_pagebreak/__manifest__.py new file mode 100644 index 000000000..0adbf3b8a --- /dev/null +++ b/account_invoice_report_pagebreak/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 CGI37 (https://www.cgi37.com). +# @author Pierre Verkest +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Invoice report page break", + "summary": "Control Page Breaks in PDF invoice report", + "version": "14.0.1.0.0", + "author": "Pierre Verkest, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-invoice-reporting", + "license": "AGPL-3", + "category": "Accounting", + "depends": [ + "account", + "report_qweb_table_pagebreak", + ], + "data": [ + "reports/report_invoice.xml", + ], + "maintainers": ["petrus-v"], +} diff --git a/account_invoice_report_pagebreak/readme/CONTRIBUTORS.rst b/account_invoice_report_pagebreak/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..638be8663 --- /dev/null +++ b/account_invoice_report_pagebreak/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Pierre Verkest diff --git a/account_invoice_report_pagebreak/readme/DESCRIPTION.rst b/account_invoice_report_pagebreak/readme/DESCRIPTION.rst new file mode 100644 index 000000000..f490ab85f --- /dev/null +++ b/account_invoice_report_pagebreak/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Control Page Breaks in PDF invoice report. + +This split the main table by section and avoid +as much as possible breaking page inside a section. diff --git a/account_invoice_report_pagebreak/readme/ROADMAP.rst b/account_invoice_report_pagebreak/readme/ROADMAP.rst new file mode 100644 index 000000000..677bd990b --- /dev/null +++ b/account_invoice_report_pagebreak/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Gives more controls to end users to allows to force breaking + pages between any rows diff --git a/account_invoice_report_pagebreak/reports/report_invoice.xml b/account_invoice_report_pagebreak/reports/report_invoice.xml new file mode 100644 index 000000000..e6a97f535 --- /dev/null +++ b/account_invoice_report_pagebreak/reports/report_invoice.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/account_invoice_report_pagebreak/tests/__init__.py b/account_invoice_report_pagebreak/tests/__init__.py new file mode 100644 index 000000000..b46aeb690 --- /dev/null +++ b/account_invoice_report_pagebreak/tests/__init__.py @@ -0,0 +1 @@ +from . import test_invoice_report_breakpage diff --git a/account_invoice_report_pagebreak/tests/test_invoice_report_breakpage.py b/account_invoice_report_pagebreak/tests/test_invoice_report_breakpage.py new file mode 100644 index 000000000..bdbe1c899 --- /dev/null +++ b/account_invoice_report_pagebreak/tests/test_invoice_report_breakpage.py @@ -0,0 +1,73 @@ +from lxml import html + +from odoo.tests import tagged +from odoo.tools.image import image_data_uri + +from odoo.addons.account.tests.common import TestAccountReconciliationCommon + + +@tagged("post_install", "-at_install") +class TestInvoiceReportAvoidPageBreakInSection(TestAccountReconciliationCommon): + def setUp(self): + super().setUp() + self.invoice = self.create_invoice_partner() + self.invoice.line_ids.create( + [ + { + "move_id": self.invoice.id, + "name": "Note 1", + "display_type": "line_note", + "sequence": 20, + }, + { + "move_id": self.invoice.id, + "name": "Note 2", + "display_type": "line_note", + "sequence": 40, + }, + ] + ) + + def test_sale_report_with_section(self): + self.invoice.line_ids.create( + [ + { + "move_id": self.invoice.id, + "name": "Section", + "display_type": "line_section", + "sequence": 30, + }, + ] + ) + doc = html.document_fromstring( + self.env["ir.qweb"] + ._render( + "account.report_invoice_document", + values={ + "o": self.invoice, + "env": self.env, + "company": self.env.company, + "image_data_uri": image_data_uri, + }, + ) + .decode("utf-8") + ) + self.assertEqual( + len(doc.find('.//table[@style="page-break-inside: avoid"]')), 2 + ) + + def test_sale_report_without_section(self): + doc = html.document_fromstring( + self.env["ir.qweb"] + ._render( + "account.report_invoice_document", + values={ + "o": self.invoice, + "env": self.env, + "company": self.env.company, + "image_data_uri": image_data_uri, + }, + ) + .decode("utf-8") + ) + self.assertFalse(doc.find('.//table[@style="page-break-inside: avoid"]')) diff --git a/setup/account_invoice_report_pagebreak/odoo/addons/account_invoice_report_pagebreak b/setup/account_invoice_report_pagebreak/odoo/addons/account_invoice_report_pagebreak new file mode 120000 index 000000000..8e5bbae1c --- /dev/null +++ b/setup/account_invoice_report_pagebreak/odoo/addons/account_invoice_report_pagebreak @@ -0,0 +1 @@ +../../../../account_invoice_report_pagebreak \ No newline at end of file diff --git a/setup/account_invoice_report_pagebreak/setup.py b/setup/account_invoice_report_pagebreak/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_invoice_report_pagebreak/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..e77de05f8 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo14-addon-report-qweb-table-pagebreak @ git+https://github.com/OCA/reporting-engine.git@refs/pull/826/head#subdirectory=setup/report_qweb_table_pagebreak