odoo14 搜索和分组查询函数

Odoo搜索和分组查询函数:search、name_search、search_count、search_read、read_group

  • search(): 搜索视图中调用
  • search_count(): 视图中计算记录数时调用
  • name_search(): 模型记录在被关联、被搜索时调用
  • search_read(): many2one点开搜索更多时调用
  • read_group(): 搜索视图分组时调用

这里主要讲read_group()函数

read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True)

  • domain:domain用于过滤记录。这将作为read_group方法的搜索条件。
  • fields:这是一个使用分组获取的字段列表。注意这里传入的字段应在groupby参数中,除非你使用了一些聚合函数。且可以使用数据库标准函数组件:(如:sum、count、avg等)
  • groupby:这个参数是记录分组的字段列表。它让你可以根据多个字段来分组记录。
  • offset:这个参数用于分页。如果想要跳过一些记录,可以使用该参数。
  • limit:这个参数用于分页,它表示页面显示记录的最大量。
  • orderby: 这个参数可以重写自然排序顺序。(orderby="字段名",按照指定字段排序,倒序 "字段名 desc")
  • lazy:这个参数接收布尔值。默认值为True。如果该参数为True,结果会在groupby参数中仅通过第一个字段来进行分组。结果中你会在__context和__domain键中获取到剩余的groupby参数及domain。如果该参数值设为False,它会用groupby参数中的所有字段对数据进行分组。
:param domain: list specifying search criteria [['field_name', 'operator', 'value'], ...]

       domain条件

:param list fields: list of fields present in the list view specified on the object.

       Each element is either 'field' (field name, using the default aggregation),

       or 'field:agg' (aggregate field with aggregation function 'agg'),

       or 'name:agg(field)' (aggregate field with 'agg' and return it as 'name').

       The possible aggregation functions are the ones provided by PostgreSQL

       (https://www.postgresql.org/docs/current/static/functions-aggregate.html)

       and 'count_distinct', with the expected meaning.

       分组之后显示的字段

:param list groupby: list of groupby descriptions by which the records will be grouped.  

       A groupby description is either a field (then it will be grouped by that field)

       or a string 'field:groupby_function'.  Right now, the only functions supported

       are 'day', 'week', 'month', 'quarter' or 'year', and they only make sense for 

       date/datetime fields.

       分组条件

:param int offset: optional number of records to skip

       跳过多少查询记录

:param int limit: optional max number of records to return

       返回的记录数

:param list orderby: optional ``order by`` specification, for

       overriding the natural sort ordering of the

       groups, see also :py:meth:`~osv.osv.osv.search`

       (supported only for many2one fields currently)

       排序条件

:param bool lazy: if true, the results are only grouped by the first groupby and the 

       remaining groupbys are put in the __context key.  If false, all the groupbys are

       done in one call.

       是否弃用懒加载:如果为真,则结果仅按第一个groupby和其余的组放在__context键中。如果为假,则所有组都是一次调用搞定。

相关链接: 

Odoo模型的内置方法重写icon-default.png?t=M4ADhttps://www.cnblogs.com/ygj0930/p/10826222.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值