汇总字段属性有哪些:
# valid SQL aggregation functions
VALID_AGGREGATE_FUNCTIONS = {
'array_agg', 'count', 'count_distinct',
'bool_and', 'bool_or', 'max', 'min', 'avg', 'sum',
}
count_distinct 使用:
class AppSaleReport(models.Model):
_name = "app.sale.report"
_description = "App Sale Report"
_table = "view_app_sale_report"
_auto = False
id = fields.Integer("ID")
partner_id = fields.Many2one("res.partner", "Customer", group_operator="count_distinct")
date_order = fields.Datetime("Order Date")
name = fields.Char("Order Reference")
product_id = fields.Many2one("product.product", "Product")
price_subtotal = fields.Float("Subtotal")
count_active_user = fields.Integer("Activity User")
company_id = fields.Many2one("res.company", "Company")
# group by date_order 获取每周下单的活跃用户数
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
fields.append('partner_id:count_distinct')
res = super(AppSaleReport, self).read_group(domain, fields, groupby, offset, limit, orderby, lazy)
if 'count_active_user' in fields:
for line in res:
if line.get('partner_id'):
line['count_active_user'] = line.get('partner_id')
return res
标签:count,group,fields,汇总,res,odoo,partner,id
From: https://www.cnblogs.com/qianxunman/p/18056801