From c819fc69ee0b8de9d0fe237d09b5e2f95206461d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 17 Dec 2018 13:28:17 +0000 Subject: [PATCH] [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 --- odoo/addons/test_impex/tests/test_export.py | 8 +++++--- odoo/fields.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/odoo/addons/test_impex/tests/test_export.py b/odoo/addons/test_impex/tests/test_export.py index 1239436839c..95edb7cd805 100644 --- a/odoo/addons/test_impex/tests/test_export.py +++ b/odoo/addons/test_impex/tests/test_export.py @@ -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): diff --git a/odoo/fields.py b/odoo/fields.py index a678dec06d5..8ecbd81fda0 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -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):