分组日期格式自定义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
@api.model def _read_group_process_groupby(self, gb, query): #自定义格式 display_formats = { # Careful with week/year formats: # - yyyy (lower) must always be used, *except* for week+year formats # - YYYY (upper) must always be used for week+year format # e.g. 2006-01-01 is W52 2005 in some locales (de_DE), # and W1 2006 for others # # Mixing both formats, e.g. 'MMM YYYY' would yield wrong results, # such as 2006-01-01 being formatted as "January 2005" in some locales. # Cfr: http://babel.pocoo.org/docs/dates/#date-fields 'day': 'yyyy-MM-dd', # yyyy = normal year 'week': "yyyy-w", # w YYYY = ISO week-year 'month': 'yyyy-MM', 'quarter': 'yyyy-QQ', 'year': 'yyyy', } annotate = super(Model, self)._read_group_process_groupby(gb=gb, query=query) if annotate.get('display_format'): gb = annotate.get('groupby','') split = gb.split(':') #默认月 gb_function = split[1] if len(split) == 2 else 'month' #覆盖超类默认格式 annotate["display_format"] = display_formats.get(gb_function,"") return annotate |
排序日期默认倒序
1 2 3 4 5 6 7 8 9 |
@api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True): if not orderby and groupby and len(groupby) == 1: first_group_field = groupby[0] #日期分组 if len(first_group_field.split(":")) == 2: #默认倒序 orderby = "%s desc" % first_group_field return super(Model, self).read_group(domain=domain, fields=fields, groupby=groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy) |