Pular para o conteúdo
Odoo Menu
  • Entrar
  • Experimente grátis
  • Aplicativos
    Finanças
    • Financeiro
    • Faturamento
    • Despesas
    • Planilhas (BI)
    • Documentos
    • Assinar Documentos
    Vendas
    • CRM
    • Vendas
    • PDV Loja
    • PDV Restaurantes
    • Assinaturas
    • Locação
    Websites
    • Criador de Sites
    • e-Commerce
    • Blog
    • Fórum
    • Chat ao Vivo
    • e-Learning
    Cadeia de mantimentos
    • Inventário
    • Fabricação
    • PLM - Ciclo de Vida do Produto
    • Compras
    • Manutenção
    • Qualidade
    Recursos Humanos
    • Funcionários
    • Recrutamento
    • Folgas
    • Avaliações
    • Indicações
    • Frota
    Marketing
    • Redes Sociais
    • Marketing por E-mail
    • Marketing por SMS
    • Eventos
    • Automação de Marketing
    • Pesquisas
    Serviços
    • Projeto
    • Planilhas de Horas
    • Serviço de Campo
    • Central de Ajuda
    • Planejamento
    • Compromissos
    Produtividade
    • Mensagens
    • Aprovações
    • Internet das Coisas
    • VoIP
    • Conhecimento
    • WhatsApp
    Aplicativos de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Varejo
    • Loja de livros
    • Loja de roupas
    • Loja de móveis
    • Mercearia
    • Loja de ferramentas
    • Loja de brinquedos
    Comida e hospitalidade
    • Bar e Pub
    • Restaurante
    • Fast Food
    • Hospedagem
    • Distribuidor de bebidas
    • Hotel
    Imóveis
    • Imobiliária
    • Escritório de arquitetura
    • Construção
    • Administração de propriedades
    • Jardinagem
    • Associação de proprietários de imóveis
    Consultoria
    • Escritório de Contabilidade
    • Parceiro Odoo
    • Agência de marketing
    • Escritório de advocacia
    • Aquisição de talentos
    • Auditoria e Certificação
    Fabricação
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Presentes corporativos
    Saúde e Boa forma
    • Clube esportivo
    • Loja de óculos
    • Academia
    • Profissionais de bem-estar
    • Farmácia
    • Salão de cabeleireiro
    Comércio
    • Handyman
    • Hardware e Suporte de TI
    • Sistemas de energia solar
    • Sapataria
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência Ambiental
    • Aluguel de outdoors
    • Fotografia
    • Aluguel de bicicletas
    • Revendedor de software
    Navegar por todos os setores
  • Comunidade
    Aprenda
    • Tutoriais
    • Documentação
    • Certificações
    • Treinamento
    • Blog
    • Podcast
    Empodere a Educação
    • Programa de educação
    • Scale Up! Jogo de Negócios
    • Visite a Odoo
    Obtenha o Software
    • Baixar
    • Comparar edições
    • Releases
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Cadastre seu escritório contábil
    Obtenha os serviços
    • Encontre um parceiro
    • Encontre um Contador
    • Conheça um consultor
    • Serviços de Implementação
    • Referências de Clientes
    • Suporte
    • Upgrades
    Github YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Faça uma demonstração
  • Preços
  • Ajuda

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

  • CRM
  • e-Commerce
  • Financeiro
  • Inventário
  • PoS
  • Projeto
  • MRP
All apps
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
Ajuda

Time & Date Issue

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
timezonedatetime
6 Respostas
12459 Visualizações
Avatar
Asad Asif

Hello All,

I am having some issues with Date and Time when generating reports.

I fully understand that by default Odoo stores all information in its Database in UTC format where as when I see the form view it shows the correct time & date as per timezone of the user.
​

The timezone of my server is set PKT (GMT+5), and the same time is set in postgresql.conf.

Lets suppose its 12.01 AM 25 July and I make any purchase order at that moment; and if I generate any report to see all the purchase orders made on 25 July it will NOT show this record as in Odoo Database this transaction was stored in UTC which is 7.01 PM 24 July. So this transaction will appear in the report for 24 July but as per me it was made on 25 July.

This is one just example, this is something happening on almost everything.

Can any one be kind enough to help me fix this issue in my modules.

I am using a few custom modules on as well on Odoo CE V11 and I am really looking forward to your expert advise.

Please help me.

Thanks

1
Avatar
Cancelar
Avatar
Asad Asif
Autor Melhor resposta

Hello Hilar,

Thanks for your answer, I dont know somehow I cant reply to you so now I am editing my answer so you can see this.

Can you please guide where to add this or if you dont mind can I paste the code for report view and py files here so you can guide accordingly.

Thanks

1
Avatar
Cancelar
Hilar Andikkadavath

Replace your the value in my answer with the DateTime field.

Hilar Andikkadavath

Check My updated answer.

Avatar
Hilar Andikkadavath
Melhor resposta


Actually, the database stores the Datetime field according to the system timezone. In Odoo, views which will be automatically converted according to the user's timezone if it is set.

Your TZ is. GMT+5),. So your custom operations on Datetime field need the proper conversion of Timezone according to the user.

Odoo views and ORM methods are treated the TZ with moment.js and the pytz conversions. This is actually a good feature to manage different timezones in Odoo.

You can use astimezone on Datetime objects:


def astimezone(self, tz): # known case of datetime.datetime.astimezone
    """ tz -> convert to local time in new timezone tz """
    return datetime(1, 1, 1)

or 

fields.Datetime.context_timestamp(self, datetime.strptime(value, DEFAULT_SERVER_DATETIME_FORMAT))
Examples:
1. date = date.replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone)
2.
import time
from datetime import datetime
from pytz import timezone
import pytz

tz = partner_id.tz or self.env._context.get('tz') # Find Timezone from user or partner or employee
att_tz = timezone(tz or 'utc') # If no tz then return in UTC
attendance_dt = datetime.strptime(date, DEFAULT_SERVER_DATETIME_FORMAT) #Input date
att_tz_dt = pytz.utc.localize(attendance_dt)
att_tz_dt = att_tz_dt.astimezone(att_tz) # converted value to tz







1
Avatar
Cancelar
Asad Asif
Autor

Hello,

Thanks

In terms of coding I am very novice.

If you dont mind, I am pasting the code lines from my module.

Can you please make the changes in that and guide me.

My timezone in GMT+5 so based on that please guide me.

Really appreciate your guidance.

Thanks in advance.

-------------------------------------

from odoo import models, fields, api

import itertools

from operator import itemgetter

import operator

class report_goods_receive_report(models.AbstractModel):

_name = 'report.dev_inter_transfer.goods_receive_report_template'

@api.multi

def get_product_ids(self,obj):

domain = []

if obj.category_id:

domain.append(('categ_id','=',obj.category_id.id))

if obj.product_ids:

domain.append(('id','in',obj.product_ids.ids))

product_ids = self.env['product.product'].search(domain)

if product_ids:

return product_ids.ids

return False

@api.multi

def get_picking_type_ids(self,obj):

if obj.warehouse_id:

picking_ids = self.env['stock.picking.type'].search([('warehouse_id','in',obj.warehouse_id.ids),('code','=','incoming')])

return picking_ids

return False

@api.multi

def get_lines(self,obj):

inter_transfer_pool = self.env['dev.inter.transfer']

product_ids = self.get_product_ids(obj)

if obj.from_date and obj.to_date:

transfer_ids = inter_transfer_pool.search([('dest_warehouse_id','in',obj.warehouse_id.ids),

('date','>=',obj.from_date),

('date','<=',obj.to_date),

('state','=','validate')])

lst =[]

for tra in transfer_ids:

for transfer in tra.line_ids:

if transfer.product_id.id in product_ids:

qty = transfer.uom_id._compute_quantity(transfer.receive_qty, transfer.product_id.uom_id)

lst.append({

'product':transfer.product_id.name or '',

'qty':qty,

'price':transfer.product_id.standard_price or 0.0,

'uom_id':transfer.product_id and transfer.product_id.uom_id and transfer.product_id.uom_id.name or '',

})

from_date = obj.from_date +' 00:00:00'

to_date = obj.to_date+' 23:59:59'

picking_type_ids = self.get_picking_type_ids(obj)

if picking_type_ids and product_ids:

line_ids = self.env['purchase.order.line'].search([('order_id.date_order','>=',from_date),

('order_id.date_order','<=',to_date),

('order_id.picking_type_id','in',picking_type_ids.ids),

('product_id','in',product_ids),

('state','in',['purchase','done'])])

for line in line_ids:

pro_qty = line.product_qty

if line.qty_received:

pro_qty = line.qty_received

qty = line.product_uom._compute_quantity(pro_qty, line.product_id.uom_po_id)

lst.append({

'product':line.product_id.name or '',

'qty':qty,

'price':line.product_id.standard_price or 0.0,

'uom_id':line.product_uom and line.product_uom.name or '',

})

if lst:

n_lines=sorted(lst,key=itemgetter('product'))

groups = itertools.groupby(n_lines, key=operator.itemgetter('product'))

lst = [{'product':k,'values':[x for x in v]} for k, v in groups]

return lst

@api.multi

def set_total(self,total1, total2):

return float(total1) + float(total2)

@api.multi

def get_report_values(self, docids, data=None):

docs = self.env['goods.receive.report'].browse(docids)

return {

'doc_ids': docs.ids,

'doc_model': 'goods.receive.report',

'docs': docs,

'get_lines':self.get_lines,

'set_total':self.set_total,

}

Avatar
Paresh Wagh
Melhor resposta

Hi Asad:

Odoo displays the timezone information based on a user's preferences. However, if all your users are located in the same timezone you can try this:

  • Activate developer mode

  • Go to Settings > Users & Companies

  • Set the filter to "Inactive Users"

  • One of the inactive users will be something called "odoobot". Update the "Timezone" in the "Preferences" tab of this user to your local timezone.

0
Avatar
Cancelar
Está gostando da discussão? Não fique apenas lendo, participe!

Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!

Inscreva-se
Publicações relacionadas Respostas Visualizações Atividade
Take Users Timezone Resolvido
timezone datetime
Avatar
Avatar
Avatar
Avatar
3
jul. 25
5223
How to add time difference on datetime object in Email Template ?
timezone datetime
Avatar
Avatar
Avatar
2
mar. 16
8652
How can I ignore timezone for a datetime field ?
timezone datetime
Avatar
0
mar. 15
9090
Datetime and Time Zones - OpenERP 7 Resolvido
timezone datetime
Avatar
Avatar
1
jan. 24
13374
How do I print the current time (in the user's timezone) in a message I generate from an Automated Action
timezone user datetime
Avatar
Avatar
Avatar
Avatar
Avatar
4
mar. 23
16123
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Open Source
  • Baixar
  • Github
  • Runbot
  • Traduções
Serviços
  • Odoo.sh Hosting
  • Suporte
  • Upgrade
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um Contador
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • Nossa empresa
  • Ativos da marca
  • Contato
  • Empregos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة 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 é um conjunto de aplicativos de negócios em código aberto que cobre todas as necessidades de sua empresa: CRM, comércio eletrônico, contabilidade, estoque, ponto de venda, gerenciamento de projetos, etc.

A proposta de valor exclusiva Odoo é ser, ao mesmo tempo, muito fácil de usar e totalmente integrado.

Site feito com

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