From b83fb948d454f0bb168a7faeeb6574939beca19c Mon Sep 17 00:00:00 2001 From: Denis Durepos Date: Tue, 11 Mar 2025 16:49:13 -0400 Subject: [PATCH] Initial commit for l10n_ca_pst_reports --- l10n_ca_pst_reports/__init__.py | 0 l10n_ca_pst_reports/__manifest__.py | 33 +++++ l10n_ca_pst_reports/tests/__init__.py | 1 + .../tests/test_report_tax_numbers.py | 65 +++++++++ l10n_ca_pst_reports/views/external_layout.xml | 136 ++++++++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 l10n_ca_pst_reports/__init__.py create mode 100644 l10n_ca_pst_reports/__manifest__.py create mode 100644 l10n_ca_pst_reports/tests/__init__.py create mode 100644 l10n_ca_pst_reports/tests/test_report_tax_numbers.py create mode 100644 l10n_ca_pst_reports/views/external_layout.xml diff --git a/l10n_ca_pst_reports/__init__.py b/l10n_ca_pst_reports/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/l10n_ca_pst_reports/__manifest__.py b/l10n_ca_pst_reports/__manifest__.py new file mode 100644 index 0000000..f77d228 --- /dev/null +++ b/l10n_ca_pst_reports/__manifest__.py @@ -0,0 +1,33 @@ +{ + 'name': 'Canadian PST Numbers on Reports', + 'author': 'Bemade Inc.', + 'version': '1.0', + 'category': 'Accounting/Localizations/Reports', + 'summary': 'Add PST numbers alongside GST/VAT numbers on reports', + 'description': ''' + This module adds Provincial Sales Tax (PST) numbers to reports where GST/VAT numbers + are already displayed. Supports: + - Invoice reports + - Company documents + - Customer/Vendor forms + ''', + 'depends': [ + 'base', + 'account', + 'l10n_ca', + 'web', # for external layouts + ], + 'data': [ + 'views/external_layout.xml', + ], + 'external_dependencies': { + 'python': [], + }, + 'test_external_dependencies': { + 'python': ['pdfminer.six'], + }, + 'installable': True, + 'application': False, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/l10n_ca_pst_reports/tests/__init__.py b/l10n_ca_pst_reports/tests/__init__.py new file mode 100644 index 0000000..99b7365 --- /dev/null +++ b/l10n_ca_pst_reports/tests/__init__.py @@ -0,0 +1 @@ +from . import test_report_tax_numbers diff --git a/l10n_ca_pst_reports/tests/test_report_tax_numbers.py b/l10n_ca_pst_reports/tests/test_report_tax_numbers.py new file mode 100644 index 0000000..d7977f3 --- /dev/null +++ b/l10n_ca_pst_reports/tests/test_report_tax_numbers.py @@ -0,0 +1,65 @@ +from odoo.tests import TransactionCase, tagged +from pdfminer.high_level import extract_text +import base64 +import tempfile +import os + +@tagged('post_install', '-at_install') +class TestReportTaxNumbers(TransactionCase): + + def setUp(self): + super().setUp() + # Create a Canadian company with GST and PST numbers + self.company = self.env['res.company'].create({ + 'name': 'Test Canadian Company', + 'country_id': self.env.ref('base.ca').id, + 'vat': '123456789', + 'l10n_ca_pst': 'PST12345', + }) + self.env['account.chart.template'].try_loading('ca_2023', company=self.company) + + # Create a partner + self.partner = self.env['res.partner'].create({ + 'name': 'Test Customer', + 'country_id': self.env.ref('base.ca').id, + }) + + # Create an invoice to test with + self.invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner.id, + 'company_id': self.company.id, + }) + + def _get_pdf_content(self, report_name, res_ids): + """Generate PDF report and extract its text content.""" + pdf_content, _ = self.env['ir.actions.report']._render_qweb_html(report_name, [res_ids]) + + return str(pdf_content) + + def test_invoice_tax_numbers(self): + """Test that GST and PST numbers appear on invoice report.""" + # Generate invoice PDF and extract text + text = self._get_pdf_content('account.report_invoice', self.invoice.id) + + # Check for GST and PST numbers + self.assertIn('GST: 123456789', text, "GST number not found in invoice") + self.assertIn('PST: PST12345', text, "PST number not found in invoice") + + def test_different_layouts(self): + """Test tax numbers appear with different report layouts.""" + layouts = ['standard', 'boxed', 'bold', 'striped', 'bubble', 'wave', 'folder'] + + for layout in layouts: + # Set company layout + layout_id = self.env.ref(f'web.external_layout_{layout}') + self.company.write({'external_report_layout_id': layout_id.id}) + + # Generate invoice PDF and extract text + text = self._get_pdf_content('account.report_invoice', self.invoice.id) + + # Check for GST and PST numbers + self.assertIn('GST: 123456789', text, + f"GST number not found in invoice with {layout} layout") + self.assertIn('PST: PST12345', text, + f"PST number not found in invoice with {layout} layout") \ No newline at end of file diff --git a/l10n_ca_pst_reports/views/external_layout.xml b/l10n_ca_pst_reports/views/external_layout.xml new file mode 100644 index 0000000..f17a91b --- /dev/null +++ b/l10n_ca_pst_reports/views/external_layout.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + +