odoo 8 11 导出excel,时间类型字段 时区问题解决
-
https://github.com/gilbert-yuan/odoo_config
from openerp.fields import Datetime, Field ISODATEFORMAT = '%Y-%m-%d' Newdatetime = Datetime.convert_to_export def convert_to_export(self, value, env): timezone = pytz.timezone(env.context.get('tz')) return_val = Newdatetime(self, value, env) if isinstance(return_val, datetime.datetime) and return_val: return self.to_string(return_val.replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone)) elif return_val: return self.to_string(self.from_string(return_val).replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone)) return return_val Datetime.convert_to_export = convert_to_export import datetime, pytz from odoo.fields import Datetime Newdatetime = Datetime.convert_to_export def convert_to_export(self, value, record): timezone = pytz.timezone(record._context.get('tz')) return_val = Newdatetime(self, value, record) if isinstance(return_val, datetime.datetime) and return_val: return self.to_string(return_val.replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone)) elif return_val: return self.to_string(self.from_string(return_val).replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone)) return return_val Datetime.convert_to_export = convert_to_export