Odoo's jet lag pit [updated]

Source: Internet
Author: User

a lot of people fell into Odoo The time pit

Odoo contract data about dates, when stored in a database, to utc0 time zone is also without time zone Store, when the application reads the date display date, convert to a user's time zone display. The user's time zone is passed through the context .

Odoo itself can handle this very well , For example , each model has its own create_date/write_date

Code

When it handles these, it uses the utc-0 time zone to store the database.

These date information can be displayed on the Web client and other interfaces , depending on the user's time zone, c10> such as Shanghai time zone "East 8 District"

If the user's time zone is switched to another, for example Fiji [utc-12 Zone] is 4 hours from Shanghai time.

The time of the show is local time, plus 4 hours on the basis of Shanghai time, so it is 5/13 01:46

And the time of the order storage database is utc-0

Some applications, however, are not well handled when they are going to the data inventory at these times.

For example, Stock Picking of the Field Date_done is a when the sorting is complete date, read when sorting is complete system time, this should be converted to utc-0 and write to the database as a Date_done . of Data

but Odoo SA 's programmers did not convert to utc-0 when they wrote this logic.

Code

Self.write (CR, UID, [picking.id], {' Date_done ': Time.strftime (Default_server_datetime_format)}, context= Context

time.strftime () Read Odoo current time of the server "with time zone", if the server is running on utc-8 , the date the database is stored is also With utc-8 , also shown in the front 2 Trade [id = +]

this way, When the user reads the change data from the application, based on this data + Time difference, turned into a.

causing Time Difference 8 hours

The reason is that Odoo the relevant code inside Date processing is not correct, No Follow remove the data before saving time zone information.

To solve this problem, 2 ways

1, abide by the Convention, the use of utc-0 when saving the database

For example Stock problematic part of the Code Modifications, has been submitted PR [https://github.com/odoo/odoo/pull/12063]

@@ -506,7 +506,7 @@ -506,7 _quant_create (self, CR, UID, qty, move, Lot_id=false, Owner_id=false, SRC_PA

' Qty ': Float_round (Qty, precision_rounding=rounding),

' Cost ': Price_unit,

' History_ids ': [(4, move.id)],

-' in_date ': DateTime.Now (). Strftime (Default_server_datetime_format),

+ ' in_date ': Datetime.utcnow (). Strftime (Default_server_datetime_format),

' company_id ': move.company_id.id,

' lot_id ': lot_id,

' owner_id ': owner_id,

2, using Workaround resolve this issue, That's will be Odoo The server's time zone is set to utc-0

Use dpkg-reconfigure Tzdata Set Time Zone

set to utc-0 after the Test

server is set to utc-0 later, Datetime.datetime.now () and the Datetime.datetime.utcnow () as well Time the time taken 's All without time zone information, this will be able to Avoid jet lag problem.

 

Odoo's jet lag pit [updated]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.