Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

check if html.field is empty on Qweb report

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
qweb
7 Respuestas
27174 Vistas
Avatar
jean44

Hello,

I have an html field and I want to display the field on Qweb report if it is not empty.

python code:

note= fields.Html(string="Note")

Qweb:

            <p t-if="doc.note">

                <strong>Note: </strong>

                <span t-raw="doc.note"/>

            </p>


if the the field is empty I got always the result:

Note:

Which is not as should be expected, I don't know if t-if tag is working on html.fields, please help !

Best regards

1
Avatar
Descartar
Ray Carnes

Hello,

Thank you for yourreply, I tried your code but it does not work


Avatar
Stephan Becker
Mejor respuesta

You need to escape the < > in XML.

For me the following works:

                    <div t-if="html-field != '&lt;p&gt;&lt;br&gt;&lt;/p&gt;'">

                    </div>

Wich is essentialle probing for a content of <p><br/></p>.
The HTML field is filled with that string by odoo automatically if you leave the HTML form widget edit area empty.
5
Avatar
Descartar
Raphael Hue de Froberville

There is a better way nowadays :

<p t-if="not is_html_empty(doc.payment_term_id.note)">
<strong>Note :</strong>
<span t-field="doc.payment_term_id.note"/>
</p>

Avatar
Jainesh Shah(Aktiv Software)
Mejor respuesta

Try

<div t-if="doc.note != '<p><br/></p>'">

    <strong>Note: </strong>

    <span t-raw="doc.note"/>

</div>

2
Avatar
Descartar
Dipak Shah

Have you tried this ?

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Mejor respuesta

Hi,


Since Odoo V14 there is a new helper called "is_html_empty". This built-in helper in the Odoo core now allows you to check if a field is empty or not. You can use this "is_html_empty" function in QWeb statements. You can then simply wrap this in a t-if statement as such: "t-if="is_html_empty(doc.note)" and do a t-else statement for example.

P.S: Sorry I wanted to paste a whole code block sample but sadly the official forum editor is completely broken again. You can see a sample in the core from Odoo here

 



1
Avatar
Descartar
Rodrigo Robles

Does this work for mail.template?

Trying to make a template that fills note field from a module if not empty. Still haven't found a way to make it work if it matches '&lt;p&gt;&lt;br&gt;&lt;/p&gt;' aswell.

Rodrigo Robles

I mean for UI web template editor*

Avatar
jean44
Autor Mejor respuesta

Hello,


I still have this problem, Any help please !


BR

0
Avatar
Descartar
Avatar
Muniswaran
Mejor respuesta

HI Jean

You just try <span> or <div> tag instead of <p> tag

I mean,

             <span t-if="doc.note">

                <strong>Note: </strong>

                <span t-raw="doc.note"/>

            </span>


or


            <div t-if="doc.note">

                <strong>Note: </strong>

                <span t-raw="doc.note"/>

            </div>

0
Avatar
Descartar
Avatar
empress
Mejor respuesta

salam jean44;

in order to check if the html.field is empty you need to add this code:

<t t-foreach="docs" t-as="doc">
                <t t-if="doc.html.field == '&lt;br&gt;'">
                    <t t-set="style" t-value=" 'display: none;' "/>
                </t>

<span  t-att-style="style" t-raw="html.field"/> 

</t>

where &lt;br&gt; is <br> decoded

0
Avatar
Descartar
Avatar
Ray Carnes
Mejor respuesta

This how Odoo does it, did you try their method?

https://github.com/odoo/odoo/blob/11.0/addons/website_quote/views/website_quote_templates.xml#L649

<div t-field="option_line.website_description" class="oe_no_empty"/>
0
Avatar
Descartar
jean44
Autor

Hello,

in my code Qweb there is also the string "Note", I don't want to display it the field note is emty, how I can do that please ?

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Odoo 18: Display image from char field containing url in qweb form
qweb
Avatar
Avatar
1
jul 25
2980
PDF Export Option for QWeb Reports in odoo 17.0
qweb
Avatar
Avatar
1
may 25
3766
QWeb: use t-if to check birthday date Resuelto
qweb
Avatar
Avatar
1
abr 25
3260
Odoo 17 - QWeb Reports with External Datasource Resuelto
qweb
Avatar
Avatar
1
feb 25
2616
Tree line field shrinked/cut
qweb
Avatar
0
oct 24
2166
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now