Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Time Zone Discrepancy in Odoo Database Records

Subscriure's

Get notified when there's activity on this post

This question has been flagged
timezonepostgresqltimestampodoo16features
1 Respondre
3774 Vistes
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
Best Answer

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 '

Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
Postgres Issue
postgresql odoo16features
Avatar
Avatar
1
de juny 23
2780
Does Odoo works with Postgres 15?
postgresql odoo16features
Avatar
Avatar
1
de maig 23
6947
CRONs aren't executed after a certain time
cron postgresql odoo16features
Avatar
Avatar
Avatar
3
d’abr. 24
4544
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 Solved
python postgresql odoo16features
Avatar
Avatar
1
de març 23
3110
Export Time diifernet with live data
export timezone timestamp odoo10.0
Avatar
Avatar
3
d’ag. 19
5682
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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