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())