Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I have an onchange class written :
self.beschreibung = str(now) + '\n' + str(self.beschreibung)
self.beschreibung = ' '
and a global variable: now = datetime.datetime.now()
I have 2 problems:
1: it is showing about 2 hours behind my current time, how do I fix that? and
2: how do I get rid of the milliseconds at the end - 10:07:15.471708?
1. I guess you're in UTC+2 time zone? Take in account that server time is in UTC, but that's corrected according timezone of user (timezone of users is configured in settings), so in user interface every user see time correctly in it's timezone (that's nice solution for a case if several user are logged into the same server from different timezone) consider to use datetime and date fields (also try widget="datetime" widget="date"), finally users will see correct time.
UPDATE for 1.
if you want add or subtract that 2 hours directly at server side (in python), then you can use (but take in account that it may show wrong time to users in browser, because of what I posted above...):
from datetime import timedelta
now = datetime.datetime.now() + timedelta(hours=2)
UPDATE: one more option to get time in user timezone at serverside:
in your case, you may find useful to use server_to_local_timestamp function from openerp.tools.misc
from openerp import tools
src_tstamp_str = tools.datetime.now().strftime(tools.misc.DEFAULT_SERVER_DATETIME_FORMAT)
src_format = tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
dst_format = "%c" #format you want to get time in.
dst_tz_name = self.env.user.tz # timezone you want get time in (here used v8 api, otherwise you'll have to browse for user and access tz field using "user_browserecord.tz")
_now = tools.misc.server_to_local_timestamp(src_tstamp_str, src_format, dst_format, dst_tz_name)
note: user should have configured a timezone in settings. if that's not a case, then odoo displays warning (!) at upper right corner in UI in browser.
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/29/15, 6:10 AM|
|Seen: 8335 times|
|Last updated: 7/18/17, 2:50 AM|