Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
tooltip
3 Răspunsuri
14434 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Emanuel Cino

I'm also interested in doing this!

Imagine profil
thompsonn
Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Dissapearing developer tooltip
tooltip
Imagine profil
0
apr. 22
65
Change Tooltip Help Text Rezolvat
tooltip
Imagine profil
Imagine profil
1
aug. 15
7343
How to disable the tooltip (indicating drops) of odoo 10 ? Rezolvat
tooltip odoo10
Imagine profil
Imagine profil
1
mai 24
20976
Tooltips not showing when defined in xml and developer mode off Rezolvat
tooltip odoo16features
Imagine profil
Imagine profil
1
iul. 23
2947
Tooltip for Kanban View? Rezolvat
kanban tooltip
Imagine profil
Imagine profil
1
dec. 20
6478
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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