分组日期格式自定义
| 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) | 
您好,看了您关于odoo的文章受益匪浅。 近期一直在从事odoo开发,希望能对odoo源码,以及权限,模块管理,升级等内部机制有更深入的了解。 不知能否透露一下联系方式,在您有时间的时候请教探讨一些问题。多谢。
i@renjie.me
您好!
请问这个function怎么用呢?
是加在什么地方?
我的代码是:
Production History Pivot
customerpartner.schedule
100
请问这个read_group应该写在什么地方呢?
谢谢!
根据实际情况写在你自定义的模型或全局基础模型里都可以
代码太长了没有全部显示
Production History Pivot
customerpartner.schedule
100