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
    • e-learning
    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
    • Conocimientos
    • 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 pub
    • 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
    • Cervecería
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y soporte técnico
    • 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
    Explorar todos los sectores
  • 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
    • Servicios para 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

Is it possible to change the time format (AM-PM) to a 24h format in time-off requests?

Suscribirse

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

Se marcó esta pregunta
formattimeoff
2 Respuestas
3645 Vistas
Avatar
Josep Anton Belchi Riera

In the entire application the time format used is 24h. In contrast, in Time Off app the type used is AM-PM. Is it possible to change this to use a 24h format everywhere?

0
Avatar
Descartar
Avatar
Tim Altendorf
Mejor respuesta

I made an account just for this and the one person that will have the same problem. 

The problem is that in the frontend odoo only uses the locale language code and not the time format options. 

If you know how to develop modules you can add the following code to the static code and add the file to your web.assets_backend then odoo will also respect the time format in chatter, forms and discuss. 

If anyoe else needs this and can't develop their own addons I could wrap it in an odoo 18 addon and make it public. Just respond to this. :)

/** @odoo-module */


import { user } from "@web/core/user";

import { _t } from "@web/core/l10n/translation";

import { rpc } from "@web/core/network/rpc";

import { session } from "@web/session";


// Cache for language formats to avoid repeated server calls

const langFormatCache = {};


/**

* Gets the user's preferred time format from res_lang model

* @returns {Promise<string>} The time format string (e.g. '%H:%M')

*/

async function getUserTimeFormat() {

// Check if we already have the format in cache

let userLang = user.lang || session.user_context.lang || 'en_US';


userLang = userLang.replace('-', '_');

if (langFormatCache[userLang]) {

return langFormatCache[userLang];

}


try {

// Query the server for language settings

const langData = await rpc('/web/dataset/call_kw', {

model: 'res.lang',

method: 'search_read',

args: [[['code', '=', userLang]], ['code', 'time_format', 'date_format', 'short_time_format']],

kwargs: {},

});

if (langData && langData.length) {

const timeFormat = langData[0].time_format || '%H:%M';

const shortTimeFormat = langData[0].short_time_format || '%H:%M';

// Cache the result

langFormatCache[userLang] = {

timeFormat,

shortTimeFormat

};

return langFormatCache[userLang];

}

return {

timeFormat: '%H:%M:%S', // Default format if not found

shortTimeFormat: '%H:%M'

};

} catch (error) {

return {

timeFormat: '%H:%M:%S', // Default format in case of errors

shortTimeFormat: '%H:%M'

}; // Return default formats in case of errors

}

}


// Translation function to convert from DateTime object to user-defined format

function formatTimeAccordingToUserPreferences(dateTime, hasSeconds, timeFormat = {

shortTimeFormat: '%H:%M',

timeFormat: '%H:%M:%S'

}) {

if (!dateTime) return '';


const localTimeFormat = hasSeconds ? timeFormat.timeFormat : timeFormat.shortTimeFormat;


// Extract hour and minute values from DateTime object

const hour = dateTime.hour;

const minute = dateTime.minute;

const second = dateTime.second;

// Handle different format placeholders

let formattedTime = localTimeFormat;

// Handle 24-hour format

formattedTime = formattedTime.replace(/%H/g, hour.toString().padStart(2, '0')); // 24h with leading zero

formattedTime = formattedTime.replace(/%k/g, hour.toString()); // 24h without leading zero

// Handle 12-hour format

const hour12 = hour % 12 || 12;

formattedTime = formattedTime.replace(/%I/g, hour12.toString().padStart(2, '0')); // 12h with leading zero

formattedTime = formattedTime.replace(/%l/g, hour12.toString()); // 12h without leading zero

// Handle minutes and seconds

formattedTime = formattedTime.replace(/%M/g, minute.toString().padStart(2, '0')); // Minutes with leading zero

formattedTime = formattedTime.replace(/%S/g, second.toString().padStart(2, '0')); // Seconds with leading zero

// Handle AM/PM indicator

const ampm = hour >= 12 ? 'PM' : 'AM';

formattedTime = formattedTime.replace(/%p/g, ampm); // AM/PM uppercase

formattedTime = formattedTime.replace(/%P/g, ampm.toLowerCase()); // am/pm lowercase

return formattedTime;

}


// Global Luxon patch

const patchLuxon = async function() {

if (!window.luxon || !window.luxon.DateTime) {

setTimeout(patchLuxon, 500);

return;

}


const userTimeFormat = await getUserTimeFormat();

const { DateTime } = window.luxon;

// Store the original toLocaleString method

const originalToLocaleString = DateTime.prototype.toLocaleString;

// Replace it with our own implementation

DateTime.prototype.toLocaleString = function(formatOpts, opts = {}) {

// Check if formatOpts is an object with time components

if (formatOpts && typeof formatOpts === 'object') {

const hasTimeComponents = formatOpts.hour !== undefined ||

formatOpts.minute !== undefined ||

formatOpts.second !== undefined;

if (hasTimeComponents) {

// Create a copy of format options without time components

const dateOnlyFormatOpts = { ...formatOpts };

delete dateOnlyFormatOpts.hour;

delete dateOnlyFormatOpts.minute;

const userHasSeconds = dateOnlyFormatOpts.second !== undefined;

delete dateOnlyFormatOpts.second;

let result = '';

// Only format the date part if there are date components left

const hasDateComponents = Object.keys(dateOnlyFormatOpts).length > 0;

if (hasDateComponents) {

// Get date portion using original formatter with date-only options

const datePart = originalToLocaleString.call(this, dateOnlyFormatOpts, opts);

result = datePart;

}

// Format time using our custom formatter

const timePart = formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

// Combine date and time parts

if (hasDateComponents) {

// Only add separator if we have both date and time

result += ', ' + timePart;

} else {

result = timePart;

}

return result;

}

}

// Handle predefined formats like DateTime.TIME_SIMPLE

else if (formatOpts === DateTime.TIME_SIMPLE ||

formatOpts === DateTime.TIME_WITH_SECONDS) {

// These are time-only formats, use our custom formatter

return formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

}

else if (formatOpts === DateTime.DATETIME_SHORT ||

formatOpts === DateTime.DATETIME_MED) {

// These are combined date+time formats

// Split into date and time parts for separate formatting

// First get original result

const originalResult = originalToLocaleString.call(this, formatOpts, opts);

// Then try to extract date part

const parts = originalResult.split(/,\s*|\s+at\s+|\s+/);

if (parts.length > 1) {

const datePart = parts[0];

const timePart = formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

return `${datePart} ${timePart}`;

}

}

// For non-time formats or predefined formats we don't handle,

// use the original implementation;

return originalToLocaleString.call(this, formatOpts, opts);

};


};


// Execute patch when DOM is ready

document.addEventListener('DOMContentLoaded', () => {

// Patch Luxon globally

patchLuxon();

});

0
Avatar
Descartar
Avatar
Vlads
Mejor respuesta

I guess you are using English(US) and custom time format. In that case it won`t affect the date+time format in Time-Off. 

Changing language to English (UK) solves problem.

0
Avatar
Descartar
Josep Anton Belchi Riera
Autor

We are using Catalan and Spanish languages. The time format is the expected on the whole aplication.
However, on the Time Off app the time format is AM-PM.
It is the latter that we would like to change so that the time format is the same throughout Odoo.

Vlads

This is just a workaround that works for us.
Good luck waiting help from odoo

¿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
How to Allow Employees to View Their Coworkers' Vacations Types
timeoff
Avatar
0
feb 25
1372
time off
timeoff
Avatar
0
jul 24
1643
Odoo 17 enterprise time off 3 steps approval workflow
timeoff
Avatar
Avatar
1
may 24
3825
Time off 0 days
timeoff
Avatar
Avatar
1
nov 23
1848
How to setup a recurrent time off
timeoff
Avatar
0
dic 21
4690
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 empresariales de código abierto que cubre 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