[FIX] fields, test_impex: export Datetime
- Set a TZ on the user different from UTC - Export a record containing a datetime, e.g. the Order Date of a SO - Import the file The Order Date is changed on the record. The data export is always in UTC, but the data import takes into account the user TZ, which explains the difference. There is no good way of solving this in stable. We have 3 choices: 1. Do nothing: the flow export then import the same data is broken, as explained above. 2. Export in the user TZ: if the file is imported in a third-party software, we break the flow. 3. Import in UTC: if the file is generated from a third-party software, we break the flow. Whatever the choice is, we either break a flow or keep an inconsistent behavior. We choose option 2, assuming that in most cases the user wants to export the data in his TZ, therefore keeping the values displayed. We only do it in v12 in order to mitigate the impact on existing installations. A proper fix should be discussed for v13. opw-1915631 closes odoo/odoo#29576
This commit is contained in:
@@ -243,19 +243,21 @@ class test_datetime(CreatorCase):
|
||||
[['']])
|
||||
|
||||
def test_basic(self):
|
||||
""" Export value with no TZ set on the user
|
||||
"""
|
||||
self.env.user.write({'tz': False})
|
||||
self.assertEqual(
|
||||
self.export('2011-11-07 21:05:48'),
|
||||
[[u'2011-11-07 21:05:48']])
|
||||
|
||||
def test_tz(self):
|
||||
""" Export ignores the timezone and always exports to UTC
|
||||
""" Export converts the value in the user's TZ
|
||||
|
||||
.. note:: on the other hand, export uses user lang for name_get
|
||||
"""
|
||||
# NOTE: ignores user timezone, always exports to UTC
|
||||
self.assertEqual(
|
||||
self.export('2011-11-07 21:05:48', context={'tz': 'Pacific/Norfolk'}),
|
||||
[[u'2011-11-07 21:05:48']])
|
||||
[[u'2011-11-08 08:35:48']])
|
||||
|
||||
|
||||
class test_selection(CreatorCase):
|
||||
|
||||
@@ -1726,6 +1726,7 @@ class Datetime(Field):
|
||||
def convert_to_export(self, value, record):
|
||||
if not value:
|
||||
return ''
|
||||
value = self.convert_to_display_name(value, record)
|
||||
return self.from_string(value) if record._context.get('export_raw_data') else ustr(value)
|
||||
|
||||
def convert_to_display_name(self, value, record):
|
||||
|
||||
Reference in New Issue
Block a user