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

Time Zone Discrepancy in Odoo Database Records

Suscribirse

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

Se marcó esta pregunta
timezonepostgresqltimestampodoo16features
1 Responder
3786 Vistas
Avatar
gladiator

Hello,

My local time zone is 'Asia/Yangon,' but my Odoo database records datetime in UTC time. As a result, every time I generate a record directly from the database, it shows a 6.30-hour difference. Could you please guide me on how to convert the time zone of records generated directly from the database? Your assistance is greatly appreciated.

l.date_order -> This records which I want to change the Time Zone.


class PosReportGenerator(models.Model):
​_name = "pos.report"
​pos_report = fields.Char(string="PoS Report")
​date_from = fields.Datetime(string="Date From")
​date_to = fields.Datetime(string="Date to")
​report_type = fields.Selection([('report_by_order', 'Report By Order'),
​ ​ ​ ​ ​ ​ ​('report_by_order_detail', 'Report By Order Detail'),
​ ​ ​ ​ ​ ​ ​('report_by_product', 'Report By Product'),
​ ​ ​ ​ ​ ​ ​('report_by_categories', 'Report By Categories'),
​ ​ ​ ​ ​ ​ ​('report_by_salesman', 'Report By Salesman'),
​ ​ ​ ​ ​ ​ ​('report_by_payment', 'Report By Payment')],
​ ​ ​ ​ ​ ​ ​default='report_by_order')

def convert_time_zone(self,trans_date):
​tz = self.env.user.partner_id.tz and pytz.timezone(self.env.user.partner_id.tz) or pytz.utc
​localized_order_date = pytz.utc.localize(datetime.strptime(str(trans_date), "%Y-%m-%d %H:%M:%S")).astimezone(tz)
​return localized_order_date
def _get_report_sub_lines(self, data, report, date_from, date_to):
​report_sub_lines = []
​new_filter = None
​if data.get('report_type') == 'report_by_order':
​ ​query = '''select l.name,l.date_order,l.partner_id,l.amount_total,l.note,l.user_id,res_partner.name,l.name as shop,pos_session.name as session,
​ ​ ​ ​res_users.partner_id as user_partner,sum(pos_order_line.qty),l.id as id,
​ ​ ​ ​(SELECT res_partner.name as salesman FROM res_partner WHERE res_partner.id = res_users.partner_id)
​ ​ ​ ​from pos_order as l
​ ​ ​ ​left join pos_session on l.session_id = pos_session.id
​ ​ ​ ​left join res_partner on l.partner_id = res_partner.id
​ ​ ​ ​left join res_users on l.user_id = res_users.id
​ ​ ​ ​left join pos_order_line on l.id = pos_order_line.order_id'''
​ ​term = 'Where '
​ ​if data.get('date_from'):
​ ​ ​query += "Where l.date_order >= '%s' " % data.get('date_from')
​ ​ ​term = 'AND '
​ ​if data.get('date_to'):
​ ​ ​query += term + "l.date_order ​ ​query += "group by l.user_id,res_users.partner_id,res_partner.name,l.partner_id,l.date_order,pos_session.name,l.session_id,l.name,l.amount_total,l.note,l.id"
​ ​self._cr.execute(query)
​ ​report_by_order = self._cr.dictfetchall()
​ ​report_sub_lines.append(report_by_order)
0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi,

To get current date time, you can follow the code below,
current_time = datetime.now()
user_tz = pytz.timezone(
request.env.context.get('tz') or request.env.user.tz)
date_today = pytz.utc.localize(current_time).astimezone(user_tz)
formatted_time = datetime.strftime(date_today, '%H:%M:%S')


Hope it helps

0
Avatar
Descartar
gladiator
Autor

Thanks for sharing your information.
But I have retrieved the data directly from SQL. How can I convert l.date_order data time zone in that case.
Please guide me.

if data.get('date_from'):
query += "Where l.date_order >= '%s' " % data.get('date_from')
​ ​term = 'AND '

gladiator
Autor

Hi
I'm finally found the solution to change the Time Zone which is directly from the Database.

if data.get('date_from'):
query += "Where l.date_order AT TIME ZONE 'UTC' AT TIME ZONE 'Your Time Zone' >= '%s' " % data.get('date_from')
term = 'AND '

¿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
Postgres Issue
postgresql odoo16features
Avatar
Avatar
1
jun 23
2786
Does Odoo works with Postgres 15?
postgresql odoo16features
Avatar
Avatar
1
may 23
6957
CRONs aren't executed after a certain time
cron postgresql odoo16features
Avatar
Avatar
Avatar
3
abr 24
4548
i want write a script that when i select table name the related column name of the table is show in the drop down in odoo Resuelto
python postgresql odoo16features
Avatar
Avatar
1
mar 23
3111
Export Time diifernet with live data
export timezone timestamp odoo10.0
Avatar
Avatar
3
ago 19
5686
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