Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Time Zone Discrepancy in Odoo Database Records

Odebírat

Get notified when there's activity on this post

This question has been flagged
timezonepostgresqltimestampodoo16features
1 Odpovědět
3798 Zobrazení
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
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

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
Zrušit
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!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Postgres Issue
postgresql odoo16features
Avatar
Avatar
1
čvn 23
2793
Does Odoo works with Postgres 15?
postgresql odoo16features
Avatar
Avatar
1
kvě 23
6969
CRONs aren't executed after a certain time
cron postgresql odoo16features
Avatar
Avatar
Avatar
3
dub 24
4551
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 Vyřešeno
python postgresql odoo16features
Avatar
Avatar
1
bře 23
3116
Export Time diifernet with live data
export timezone timestamp odoo10.0
Avatar
Avatar
3
srp 19
5688
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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