当我试图在树状视图中显示字段的平均值时,我遇到了问题。
percentage = fields.Float(string =' Porcentaje',compute =' fill_percentage',store = True,default = False)
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
res = super(Project_Task_Extension, self).read_group(domain, fields, groupby, offset=offset,
limit=limit, orderby=orderby, lazy=lazy)
if 'percentage' in fields:
for line in res:
if '__domain' in line:
value = 0.0
aux = 0
lines = self.search(line['__domain'])
for x in lines:
value += x.percentage
aux += 1
total = value/aux
line['percentage'] = total
return res
----in the xml----
<field name="percentage" avg="Average"/>
使用此代码可以很好地工作,但是当我尝试过滤“例如&#39;项目&#39;”时,最终平均值是不正确的,是否有任何建议?
In this image the average is correct
在第二张图片中,总数应为(85.71 + 100 +0)/3=61.90 ...