[FIX] web: company details
In Odoo editor when a html field is empty, we add en empty <br> inside the <p>. 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 <br> 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) <jol@odoo.com> Signed-off-by: Maximilien La Barre (malb) <malb@odoo.com>
This commit is contained in:
@@ -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 <p> balise remains with a <br> 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 '')
|
||||
|
||||
@@ -304,8 +304,9 @@
|
||||
</div>
|
||||
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" class="float-start" alt="Logo"/>
|
||||
<div class="float-start company_address">
|
||||
<ul class="list-unstyled" t-if="company.company_details or forced_vat">
|
||||
<li t-if="company.company_details"> <t t-esc="company.company_details"/></li>
|
||||
<ul class="list-unstyled">
|
||||
<li t-if="company.is_company_details_empty"><t t-esc="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/></li>
|
||||
<li t-else=""><t t-esc="company.company_details"/></li>
|
||||
<li t-if="forced_vat">
|
||||
<t t-esc="company.country_id.vat_label or 'Tax ID'"/>:
|
||||
<span t-esc="forced_vat"/>
|
||||
@@ -346,8 +347,9 @@
|
||||
<div class="col-6 text-end mb4">
|
||||
<div class="mt0 h4" t-field="company.report_header"/>
|
||||
<div name="company_address" class="float-end mb4">
|
||||
<ul class="list-unstyled" t-if="company.company_details or forced_vat">
|
||||
<li t-if="company.company_details"> <t t-esc="company.company_details"/></li>
|
||||
<ul class="list-unstyled">
|
||||
<li t-if="company.is_company_details_empty"><t t-esc="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/></li>
|
||||
<li t-else=""><t t-esc="company.company_details"/></li>
|
||||
<li t-if="forced_vat">
|
||||
<t t-esc="company.country_id.vat_label or 'Tax ID'"/>:
|
||||
<span t-esc="forced_vat"/>
|
||||
@@ -385,8 +387,9 @@
|
||||
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" alt="Logo"/>
|
||||
</div>
|
||||
<div class="col-5 offset-1" name="company_address">
|
||||
<ul class="list-unstyled" t-if="company.company_details or forced_vat">
|
||||
<li t-if="company.company_details"> <t t-esc="company.company_details"/></li>
|
||||
<ul class="list-unstyled">
|
||||
<li t-if="company.is_company_details_empty"><t t-esc="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/></li>
|
||||
<li t-else=""><t t-esc="company.company_details"/></li>
|
||||
<li t-if="forced_vat">
|
||||
<t t-esc="company.country_id.vat_label or 'Tax ID'"/>:
|
||||
<span t-esc="forced_vat"/>
|
||||
@@ -408,7 +411,8 @@
|
||||
<span t-field="company.report_footer"/>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<span t-if="company.company_details" t-field="company.company_details"/>
|
||||
<span t-if="company.is_company_details_empty" t-field="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/>
|
||||
<span t-else="" t-field="company.company_details"/>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<div class="mt0 mb0 h5" t-field="company.report_header"/>
|
||||
@@ -438,8 +442,8 @@
|
||||
<div class="row">
|
||||
<div class="col-6" name="company_address">
|
||||
<ul class="list-unstyled">
|
||||
<li t-if="company.company_details"> <t t-esc="company.company_details"/></li>
|
||||
<li t-else=""> <t t-esc="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/></li>
|
||||
<li t-if="company.is_company_details_empty"><t t-esc="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'/></li>
|
||||
<li t-else=""><t t-esc="company.company_details"/></li>
|
||||
<li t-if="forced_vat">
|
||||
<t t-esc="company.country_id.vat_label or 'Tax ID'"/>:
|
||||
<span t-esc="forced_vat"/>
|
||||
|
||||
@@ -10,6 +10,7 @@ import warnings
|
||||
from odoo import api, fields, models, tools, _, Command
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.modules.module import get_resource_path
|
||||
from odoo.tools import html2plaintext
|
||||
from odoo.tools import file_open
|
||||
from random import randrange
|
||||
from PIL import Image
|
||||
@@ -41,6 +42,7 @@ class Company(models.Model):
|
||||
report_header = fields.Html(string='Company Tagline', translate=True, help="Appears by default on the top right corner of your printed documents (report header).")
|
||||
report_footer = fields.Html(string='Report Footer', translate=True, help="Footer text displayed at the bottom of all reports.")
|
||||
company_details = fields.Html(string='Company Details', translate=True, help="Header text displayed at the top of all reports.")
|
||||
is_company_details_empty = fields.Boolean(compute='_compute_empty_company_details')
|
||||
logo = fields.Binary(related='partner_id.image_1920', default=_get_logo, string="Company Logo", readonly=False)
|
||||
# logo_web: do not store in attachments, since the image is retrieved in SQL for
|
||||
# performance reasons (see addons/web/controllers/main.py, Binary.company_logo)
|
||||
@@ -174,6 +176,13 @@ class Company(models.Model):
|
||||
_logger.warning("The method '_company_default_get' on res.company is deprecated and shouldn't be used anymore")
|
||||
return self.env.company
|
||||
|
||||
@api.depends('company_details')
|
||||
def _compute_empty_company_details(self):
|
||||
# In recent change when an html field is empty a <p> balise remains with a <br> 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 '')
|
||||
|
||||
def cache_restart(self):
|
||||
warnings.warn("Since 17.0, deprecated method, use `clear_caches` instead", DeprecationWarning, 2)
|
||||
self.clear_caches()
|
||||
|
||||
Reference in New Issue
Block a user