From 870f9c985c0ef55469934f57ea5b7f5e182e77e3 Mon Sep 17 00:00:00 2001 From: Samy Mostafa Shaawat Date: Sat, 17 Oct 2026 13:55:50 +0300 Subject: [PATCH] [FIX] brand_external_report_layout: avoid empty SCSS attachment when no brand exists The generated res.brand.scss attachment was empty when there was no res.brand record, so the assets compiler failed with 'Could not get content for ...asset_styles_brand_report.scss' and the document layout preview never loaded. Fall back to a placeholder comment. --- brand_external_report_layout/models/res_brand.py | 4 ++++ .../tests/test_brand_external_report_layout.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/brand_external_report_layout/models/res_brand.py b/brand_external_report_layout/models/res_brand.py index e559a5dfb..a609c08a6 100644 --- a/brand_external_report_layout/models/res_brand.py +++ b/brand_external_report_layout/models/res_brand.py @@ -103,6 +103,10 @@ def _get_asset_style_b64(self): {"brand_ids": self.sudo().search([])}, raise_if_not_found=False, ) + # An empty attachment cannot be read by the assets compiler, + # which breaks the report assets when there is no brand yet. + if not brand_styles.strip(): + brand_styles = "/* No brand-specific styles configured */" return base64.b64encode(brand_styles.encode()) def _update_asset_style(self): diff --git a/brand_external_report_layout/tests/test_brand_external_report_layout.py b/brand_external_report_layout/tests/test_brand_external_report_layout.py index 74b2edae2..61919d452 100644 --- a/brand_external_report_layout/tests/test_brand_external_report_layout.py +++ b/brand_external_report_layout/tests/test_brand_external_report_layout.py @@ -187,3 +187,8 @@ def test_brand_document_layout_get_asset_style(self): ) result = wizard._get_asset_style() self.assertIsInstance(result, markupsafe.Markup) + + def test_asset_style_not_empty_without_brand(self): + self.env["res.brand"].search([]).unlink() + content = base64.b64decode(self.env["res.brand"]._get_asset_style_b64()) + self.assertTrue(content.strip())