summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorRémy Voet (ryv) <ryv@odoo.com>2025-01-14 08:27:01 +0100
committerRémy Voet (ryv) <ryv@odoo.com>2025-01-14 09:28:10 +0000
commitefbee4f591704d7ff0ed34805d09070a5d78134d (patch)
tree09542374af23e49ef173a7fe031aff97451b3967 /odoo
parent72f7117de5bff2907925e5074797bb4c959d5cc6 (diff)
[FIX] base: website is not shown in the contact qweb widget
Steps to reproduce: - Render the Contact qweb widget with fields ["phone", "website"] ```py Contact = self.env["ir.qweb.field.contact"] partner = self.env["res.partner"].create( { "name": "Test Partner", "phone": "1234567890", "website": "https://www.example.com", } ) result = Contact.value_to_html(partner, {"fields": ["phone", "website"]}) ``` Result: - The website is not shown This is a regression introduced in 9e53aea, in combination with some buggy behavior in the qweb compilation. Somehow the `t-elif` condition is applying on the next element instead on itself, hiding the website element. I did not investigate further to find the root cause, though. Switching to a `t-if` condition works around the issue. closes odoo/odoo#193461 X-original-commit: 8263316 Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/addons/base/tests/test_qweb_field.py25
-rw-r--r--odoo/addons/base/views/ir_qweb_widget_templates.xml2
2 files changed, 26 insertions, 1 deletions
diff --git a/odoo/addons/base/tests/test_qweb_field.py b/odoo/addons/base/tests/test_qweb_field.py
index 1e86312896e..8964d8d55aa 100644
--- a/odoo/addons/base/tests/test_qweb_field.py
+++ b/odoo/addons/base/tests/test_qweb_field.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.tests import common
@@ -56,3 +57,27 @@ class TestQwebFieldInteger(common.TransactionCase):
self.value_to_html(125125, {'format_decimalized_number': True, 'precision_digits': 3}),
"125.125k"
)
+
+class TestQwebFieldContact(common.TransactionCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
+ cls.partner = cls.env.ref("base.res_partner_1")
+
+ def test_value_to_html_with_website_and_phone(self):
+ Contact = self.env["ir.qweb.field.contact"]
+ result = Contact.value_to_html(self.partner, {"fields": ["phone", "website"]})
+ self.assertIn('itemprop="website"', result)
+ self.assertIn(self.partner.website, result)
+ self.assertIn('itemprop="telephone"', result)
+ self.assertIn(self.partner.phone, result)
+ self.assertNotIn('itemprop="email"', result)
+
+ def test_value_to_html_without_phone(self):
+ Contact = self.env["ir.qweb.field.contact"]
+ result = Contact.value_to_html(self.partner, {"fields": ["name", "website"]})
+ self.assertIn('itemprop="website"', result)
+ self.assertIn(self.partner.website, result)
+ self.assertNotIn(self.partner.phone, result)
+ self.assertIn('itemprop="telephone"', result, "Empty telephone itemprop should be added to prevent issue with iOS Safari")
diff --git a/odoo/addons/base/views/ir_qweb_widget_templates.xml b/odoo/addons/base/views/ir_qweb_widget_templates.xml
index 2ce8b1aea82..5f3a059b6e7 100644
--- a/odoo/addons/base/views/ir_qweb_widget_templates.xml
+++ b/odoo/addons/base/views/ir_qweb_widget_templates.xml
@@ -44,7 +44,7 @@
<i t-if="not options.get('no_marker') or options.get('phone_icons')" class='fa fa-mobile fa-fw' role="img" aria-label="Mobile" title="Mobile"/> <span class="o_force_ltr" itemprop="telephone" t-esc="mobile"/>
</div>
<!-- Prevent issue with iOS Safari parsing of schema data without telephone itemprops -->
- <div t-elif="not (phone and 'phone' in fields)" itemprop="telephone"/>
+ <div t-if="not (phone and 'phone' in fields) and not (mobile and 'mobile' in fields)" itemprop="telephone"/>
<div class="d-flex align-items-baseline gap-1" t-if="website and 'website' in fields">
<i t-if="not options.get('no_marker')" class='fa fa-globe fa-fw' role="img" aria-label="Website" title="Website"/>
<a class="text-break w-100" t-att-href="website and '%s%s' % ('http://' if '://' not in website else '',website)"><span itemprop="website" t-esc="website"/></a>