From 96f22bd8f069b4bb118d62c17dc461044155ccaa Mon Sep 17 00:00:00 2001 From: "Maximilien (malb)" Date: Tue, 6 Jun 2023 14:10:23 +0000 Subject: [PATCH] [FIX] web: company details In Odoo editor when a html field is empty, we add en empty
inside the

. This change broke all if statement checking that company details is empty. In this commit, we add a function is_empty_company_details that return True if the company details field contains only a
and False otherwise. With this method, we can check that company details is empty and displaying other thing that just an empty line break. closes odoo/odoo#124440 Task-id: 3168705 X-original-commit: 2aaca9afb6c54be3ef87ea38646af90a2599aa6b Signed-off-by: John Laterre (jol) Signed-off-by: Maximilien La Barre (malb) --- addons/web/models/base_document_layout.py | 9 +++++++++ addons/web/views/report_templates.xml | 22 +++++++++++++--------- odoo/addons/base/models/res_company.py | 9 +++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/addons/web/models/base_document_layout.py b/addons/web/models/base_document_layout.py index 47df92452da..47260ba25be 100644 --- a/addons/web/models/base_document_layout.py +++ b/addons/web/models/base_document_layout.py @@ -6,6 +6,7 @@ from odoo import api, fields, models, tools from odoo.addons.base.models.ir_qweb_fields import nl2br from odoo.modules import get_resource_path +from odoo.tools import html2plaintext try: import sass as libsass @@ -62,6 +63,7 @@ class BaseDocumentLayout(models.TransientModel): report_header = fields.Html(related='company_id.report_header', readonly=False) report_footer = fields.Html(related='company_id.report_footer', readonly=False, default=_default_report_footer) company_details = fields.Html(related='company_id.company_details', readonly=False, default=_default_company_details) + is_company_details_empty = fields.Boolean(compute='_compute_empty_company_details') # The paper format changes won't be reflected in the preview. paperformat_id = fields.Many2one(related='company_id.paperformat_id', readonly=False) @@ -304,3 +306,10 @@ class BaseDocumentLayout(models.TransientModel): ) except libsass.CompileError as e: raise libsass.CompileError(e.args[0]) + + @api.depends('company_details') + def _compute_empty_company_details(self): + # In recent change when an html field is empty a

balise remains with a
in it, + # but when company details is empty we want to put the info of the company + for record in self: + record.is_company_details_empty = not html2plaintext(record.company_details or '') diff --git a/addons/web/views/report_templates.xml b/addons/web/views/report_templates.xml index 18306b6cd9b..5545f7134e9 100644 --- a/addons/web/views/report_templates.xml +++ b/addons/web/views/report_templates.xml @@ -304,8 +304,9 @@ Logo

-