From ac5d85ee9ff1d3a437f7b9618a80a9a90bcf26fe Mon Sep 17 00:00:00 2001 From: ivan deng Date: Tue, 24 Aug 2021 17:34:56 +0800 Subject: [PATCH] update --- app_common/__manifest__.py | 3 +- app_common/models/base.py | 58 ++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/app_common/__manifest__.py b/app_common/__manifest__.py index e49b6511..6022592f 100644 --- a/app_common/__manifest__.py +++ b/app_common/__manifest__.py @@ -33,7 +33,7 @@ { 'name': "Sunpop Odooapp Common Func", - 'version': '13.21.08.19', + 'version': '13.21.08.21', 'author': 'Sunpop.cn', 'category': 'Base', 'website': 'https://www.sunpop.cn', @@ -70,7 +70,6 @@ # 'data/.xml', # 'views/ir_module_module_views.xml', # 'report/.xml', - 'views/ir_cron_views.xml', ], 'qweb': [ 'static/src/xml/*.xml', diff --git a/app_common/models/base.py b/app_common/models/base.py index a621ed65..26d72f9a 100644 --- a/app_common/models/base.py +++ b/app_common/models/base.py @@ -9,9 +9,56 @@ from io import BytesIO from datetime import date, datetime, time import pytz +import logging + +_logger = logging.getLogger(__name__) + +# 常规的排除的fields +EXCLU_FIELDS = [ + '__last_update', + 'access_token', + 'access_url', + 'access_warning', + 'activity_date_deadline', + 'activity_exception_decoration', + 'activity_exception_icon', + 'activity_ids', + 'activity_state', + 'activity_summary', + 'activity_type_id', + 'activity_user_id', + 'display_name', + 'message_attachment_count', + 'message_channel_ids', + 'message_follower_ids', + 'message_has_error', + 'message_has_error_counter', + 'message_has_sms_error', + 'message_ids', + 'message_is_follower', + 'message_main_attachment_id', + 'message_needaction', + 'message_needaction_counter', + 'message_partner_ids', + 'message_unread', + 'message_unread_counter', + 'website_message_ids', + 'write_date', + 'write_uid', +] + + class Base(models.AbstractModel): _inherit = 'base' + @api.model + def _get_normal_fields(self): + f_list = [] + for k, v in self._fields.items(): + if k not in EXCLU_FIELDS: + f_list.append(k) + return f_list + @api.model def _app_get_m2o_default(self, fieldname, domain=[]): if hasattr(self, fieldname) and self._fields[fieldname].type == 'many2one': @@ -24,16 +71,17 @@ class Base(models.AbstractModel): def _app_dt2local(self, value, return_format=DEFAULT_SERVER_DATETIME_FORMAT): """ - 将value中时间,按格式转为用户本地时间 + 将value中时间,按格式转为用户本地时间.注意只处理in str为字符串类型,如果是时间类型直接用 datetime.now(tz) """ if not value: return value if isinstance(value, datetime): value = value.strftime(return_format) dt = datetime.strptime(value, return_format) - pytz_timezone = pytz.timezone(self.env.user.tz or 'Etc/GMT-8') + user_tz = pytz.timezone(self.env.user.tz or 'Etc/GMT-8') + _logger.warning('============= user2 tz: %s' % user_tz) dt = dt.replace(tzinfo=pytz.timezone('UTC')) - return dt.astimezone(pytz_timezone).strftime(return_format) + return dt.astimezone(user_tz).strftime(return_format) def _app_dt2utc(self, value, return_format=DEFAULT_SERVER_DATETIME_FORMAT): """ @@ -44,9 +92,9 @@ class Base(models.AbstractModel): if isinstance(value, datetime): value = value.strftime(return_format) dt = datetime.strptime(value, return_format) - user_tz = pytz.timezone(self.env.user.tz or 'Etc/GMT+8') + pytz_timezone = pytz.timezone('Etc/GMT+8') dt = dt.replace(tzinfo=pytz.timezone('UTC')) - return dt.astimezone(user_tz).strftime(return_format) + return dt.astimezone(pytz_timezone).strftime(return_format) @api.model def get_image_from_url(self, url):