AttributeError: 'datetime.date' object has no attribute 'hour' when creating an option - group by hour
AttributeError: 'datetime.date' object has no attribute 'hour' when creating an option - group by hour
我正在使用 odoo8 并想按小时创建一个选项组,
我知道我不应该弄乱核心 odoo 代码,但它只是添加到行(我希望如此),我检查了一个 "pivot by hour" 模块 V10 并添加了相同的两行。
在addons\point_of_sale\report\pos_order_report_view.xml我补充说:
<filter string="Order Hour" context="{'group_by':'date:hour'}" help="Hour of order date"/>
和 server\openerp\modules.py 在 _read_group_process_groupby() 方法中我添加了两行:
def _read_group_process_groupby(self, gb, query, context):
split = gb.split(':')
field_type = self._fields[split[0]].type
gb_function = split[1] if len(split) == 2 else None
temporal = field_type in ('date', 'datetime')
tz_convert = field_type == 'datetime' and context.get('tz') in pytz.all_timezones
qualified_field = self._inherits_join_calc(self._table, split[0], query)
if temporal:
display_formats = {
'hour': 'HH:mm dd MMM yyyy', ###### added by me
'day': 'dd MMM yyyy',
'week': "'W'w YYYY",
'month': 'MMMM yyyy',
'quarter': 'QQQ yyyy',
'year': 'yyyy',
}
time_intervals = {
'hour': dateutil.relativedelta.relativedelta(hours=1), ###### added by me
'day': dateutil.relativedelta.relativedelta(days=1),
'week': datetime.timedelta(days=7),
'month': dateutil.relativedelta.relativedelta(months=1),
'quarter': dateutil.relativedelta.relativedelta(months=3),
'year': dateutil.relativedelta.relativedelta(years=1)
}
if tz_convert:
qualified_field = "timezone('%s', timezone('UTC',%s))" % (context.get('tz', 'UTC'),
qualified_field)
qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
if field_type == 'boolean':
qualified_field = "coalesce(%s,false)" % qualified_field
return {
'field': split[0],
'groupby': gb,
'type': field_type,
'display_format': display_formats[gb_function or 'month'] if temporal else None,
'interval': time_intervals[gb_function or 'month'] if temporal else None,
'tz_convert': tz_convert,
'qualified_field': qualified_field
}
整个追溯如下:
确保传递给值的类型与索引的类型相同。
您传递的值是 'datetime.date' 和这个 Return date 对象具有相同的年份, 月份和日期。 Click Here
您可以将其更改为 datetime.time()
谢谢
在models.py中(路径:server/openerp)在_read_group_format_result方法中
.format_date(
需要改为
.format_datetime(
我正在使用 odoo8 并想按小时创建一个选项组, 我知道我不应该弄乱核心 odoo 代码,但它只是添加到行(我希望如此),我检查了一个 "pivot by hour" 模块 V10 并添加了相同的两行。
在addons\point_of_sale\report\pos_order_report_view.xml我补充说:
<filter string="Order Hour" context="{'group_by':'date:hour'}" help="Hour of order date"/>
和 server\openerp\modules.py 在 _read_group_process_groupby() 方法中我添加了两行:
def _read_group_process_groupby(self, gb, query, context):
split = gb.split(':')
field_type = self._fields[split[0]].type
gb_function = split[1] if len(split) == 2 else None
temporal = field_type in ('date', 'datetime')
tz_convert = field_type == 'datetime' and context.get('tz') in pytz.all_timezones
qualified_field = self._inherits_join_calc(self._table, split[0], query)
if temporal:
display_formats = {
'hour': 'HH:mm dd MMM yyyy', ###### added by me
'day': 'dd MMM yyyy',
'week': "'W'w YYYY",
'month': 'MMMM yyyy',
'quarter': 'QQQ yyyy',
'year': 'yyyy',
}
time_intervals = {
'hour': dateutil.relativedelta.relativedelta(hours=1), ###### added by me
'day': dateutil.relativedelta.relativedelta(days=1),
'week': datetime.timedelta(days=7),
'month': dateutil.relativedelta.relativedelta(months=1),
'quarter': dateutil.relativedelta.relativedelta(months=3),
'year': dateutil.relativedelta.relativedelta(years=1)
}
if tz_convert:
qualified_field = "timezone('%s', timezone('UTC',%s))" % (context.get('tz', 'UTC'),
qualified_field)
qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
if field_type == 'boolean':
qualified_field = "coalesce(%s,false)" % qualified_field
return {
'field': split[0],
'groupby': gb,
'type': field_type,
'display_format': display_formats[gb_function or 'month'] if temporal else None,
'interval': time_intervals[gb_function or 'month'] if temporal else None,
'tz_convert': tz_convert,
'qualified_field': qualified_field
}
整个追溯如下:
确保传递给值的类型与索引的类型相同。
您传递的值是 'datetime.date' 和这个 Return date 对象具有相同的年份, 月份和日期。 Click Here
您可以将其更改为 datetime.time()
谢谢
在models.py中(路径:server/openerp)在_read_group_format_result方法中
.format_date(
需要改为
.format_datetime(