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

How to change the color of a field inside a form depending on a value?

Suscribirse

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

Se marcó esta pregunta
formcolorsv9
6 Respuestas
37971 Vistas
Avatar
Anabela Damas

Hi, 

I want to in a form view have a field that depending on his value changes the color. 

If is diferent than zero I want this number to show in red color , if it is zero I want the field to be green. 

I've tried this way , but nothing happens.

 

<form string="Sales Order"> 
<sheet>
<notebook> 
<page name="SO_payment">
    <group class="oe_subtotal_footer oe_right" colspan="2" name="payment_total">                           <div class="oe_subtotal_footer_separator oe_inline o_td_label">
          <label for="to_pay" />                   
         </div> 
         <field name="to_pay" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}" colors="{'red':to_pay&gt;0}"/> 
</group>
</page></notebook></sheet></form>

 

I just want the number to have the color. 


Thanks



3
Avatar
Descartar
Vishal Gediya

you want only field name="to_pay" color or all fields color.

Anabela Damas
Autor

I've updated the question.

Sehrish

This Odoo app allows users to dynamically change the background and text color of any integer field based on a threshold value. The app introduces a customizable widget that automatically adjusts the visual representation of integer fields, allowing users to define their own colors for values below and above the threshold. Whether for financial figures, performance metrics, or other numeric values, users can easily tailor the display according to their preferences.
https://apps.odoo.com/apps/modules/17.0/mh_integer_field_color_widget

Avatar
Jose David Moreno Hernandez
Mejor respuesta

I've been for a long time looking for a solution for that, and I've ended creating my own. It's a little of a hack but works perfectly for colouring the field's backgrounds depending on other fields values.

First I add a new meaningful class name to my field, for example 'opt_required', and use in it the odoo's built-in colouring functionality, I'll chose 'decoration-warning'

<field name="custom_field" class="opt_required" decoration-warning="company_name == 'Elektrolux'"/>


After that, in my custom css file I add the next code. The decoration-warning will trigger the .text-warning class in the case the conditional is met, otherwise the input-field won't have that class. So the next piece of css code will only work if the input has either the .text-warning class and the opt_required class, and our field will have happily its background colour :)

input.opt_required.text-warning{
   background-color: #D2D2FF !important;
   color: rgb(31, 31, 31) !important; /*We don't want the text to actually have the warning color, so we keep it the usual*/
}

Take care of adding your css file to the assets as usual, for instance like this:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>   
    <template id="assets_backend" name="Technical Service Assets" inherit_id="web.assets_backend">
        <xpath expr="//link[last()]" position="after">            
            <link rel="stylesheet" href="technical_service/static/src/css/styles.css"/>       
        </xpath>   
    </template>
</odoo>

And after to the __manifest__.py

'data': [
        'views/my_custom_assets.xml',   
        ],
'css': ['static/src/css/styles.css'],

Then you just need to upgrade your module, and your fields will start working as you desired.

2
Avatar
Descartar
Avatar
Vishal Gediya
Mejor respuesta

If you want all fields color then give colors attribute in <tree>

<tree string="Configuration" colors="green:no == 0;red:no > 0">
    <field name="no" />
</tree>
1
Avatar
Descartar
Anabela Damas
Autor

For tree the answer is rigth. But I need in a form just the field.

Vishal Gediya

you need only for to_pay filed.

¿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
Can i create multiple forms for a single model using studio ? Resuelto
form
Avatar
Avatar
2
sept 25
1394
How to make Odoo form readonly when the record has an specific state?
form
Avatar
0
ene 21
3373
How to add Fields in Form Resuelto
form
Avatar
Avatar
Avatar
5
jul 19
5776
coloring a sale order line
colors
Avatar
Avatar
Avatar
6
ene 19
10338
Difference between Enterprise and Community Editions Resuelto
v9
Avatar
Avatar
Avatar
Avatar
Avatar
19
may 24
99681
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.

Sitio web hecho con

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