Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar 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
  • Proyecto
  • 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

How to create a function to set dynamic tooltip for field?

Suscribirse

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

Se marcó esta pregunta
tooltip
3 Respuestas
14345 Vistas
Avatar
JC

When I rollover my mouse to product field in order line, I want to pop up tooltip with infomations , like cost, qty on hand etc instead of going into the product screen? I understand tooltip is configure with the attribute help when creating the field, could I put a function to retrive the information instead? If yes please provide an example.thanks in advance.

5
Avatar
Descartar
Emanuel Cino

I'm also interested in doing this!

Avatar
thompsonn
Mejor respuesta

The aim of the attribute help=  is to display some general information on the field and not on the dynamically attached elements of that field. IMHO this should be achieved with JavaScript, asynchronous in this case as the field elements should be rendered afore. I do not insist that the way to do the trick I am going to describe is the only and the best one but it may give you the basic idea and inspire for a better solution.

 Let us create a module dynamic_tooltip with the following structure:
 

dynamic_tooltip/
|── assets.xml
|── __init__.py
|── __manifest__.py
|── static
│     └── src
│             └── js
│                     └── sale_order_line_tooltip.js
|── view.xml

We are putting there an empty __init__.py file in order to avoid ImportError on the server start. 

The file assets.xml incorporates our JS code into web.assets_backend and looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/dynamic_tooltip/static/src/js/sale_order_line_tooltip.js"
type="text/javascript" />
</xpath>
</template>
</odoo>

Our JS file should be placed under static/src/js/ as a generally good Odoo practice. I am not a JS master so those who have way with it -- no hard feelings please.

static/src/js/sale_order_line_tooltip.js

odoo.define('dynamic_tooltip', function(require) {

var core = require('web.core'), // get tree view widgets
Model = require('web.DataModel'); // make asynchronous calls to the DB

/* Make a special widget to include dynamic tooltips for the product name char field,
see addons/web/static/src/js/views/list_view.js for reference.
*/
var DynamicTooltip = core.list_widget_registry.get('field').extend({
_format: function (row_data, options) {
var value = row_data[this.id].value;
var product_tmpl_id = row_data[this.id].value[0],
product_name = row_data[this.id].value[1];

// Create a Query() object to make a request to the DB
var productTemplate = new Model('product.template')
productTemplate.query(['description_sale'])
.filter([['id', '=', product_tmpl_id]])
.first()
.then(function(res) {
if (res) {
// Attach the tooltip asynchronously after the corresponding element is rendered
$('#' + product_tmpl_id).prop('title', res.description_sale);
};
})
// Return a <p> tag with id of the product_temlate record
return '<p id="' + product_tmpl_id + '">' + product_name + '</p>';
}
});

// Make the created widget accessible by other models
core.list_widget_registry.add('field.dynamic_tooltip', DynamicTooltip);
})

It goes without saying that there are lots of ways to play with CSS and with Bootstrap Tooltips in particular, this is aimed at demonstrating the simplest principle possible.

The JS above is in fact pretty plain and simple so it should not be difficult to translate it into human language. More on Odoo JS calls to DB you can read here: https://www.odoo.com/documentation/10.0/reference/javascript.html#high-level-api-calling-into-odoo-models. More on Odoo widgets in general you can learn by examining the source code under addons/web/static/src/js/views, it is quite straightforward and easy to grasp.


So far we have created a widget that attaches tooltips with product descriptions to the elements containing product names but we only want this functionality in sale order lines tree and not anywhere else. For that purpose we tell Odoo where exactly to use the created widget i.e. in the corresponding sale order view only:

view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="sale_order_customer_note" model="ir.ui.view">
<field name="name">sale.order.line.dynamic.tooltip</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='product_id']" position="attributes">
<attribute name="widget">dynamic_tooltip</attribute>
</xpath>
</field>
</record>
</data>
</openerp>


Under Odoo general module layout we also need a __manifest__.py file that should look something like this:

{
'name': 'Sale Order Dynamic Tooltip',
'author': 'thompsonn',
'application': True,
'data': ['view.xml',
'assets.xml',
],
'depends': ['base', 'sale']
}


All-a-taut-o, now you can install the module and try it yourself.

Hope this would be of any help to those interested. Thanks.


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

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

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Dissapearing developer tooltip
tooltip
Avatar
0
abr 22
65
Change Tooltip Help Text Resuelto
tooltip
Avatar
Avatar
1
ago 15
7269
How to disable the tooltip (indicating drops) of odoo 10 ? Resuelto
tooltip odoo10
Avatar
Avatar
1
may 24
20816
Tooltips not showing when defined in xml and developer mode off Resuelto
tooltip odoo16features
Avatar
Avatar
1
jul 23
2854
Tooltip for Kanban View? Resuelto
kanban tooltip
Avatar
Avatar
1
dic 20
6416
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información 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 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