forked from Techsystech/web
[IMP] make one search_read call instead of two calls
parent
3fc62acb80
commit
dc9c69a96f
|
@ -155,38 +155,30 @@ class TileTile(models.Model):
|
||||||
self.primary_value = self.secondary_value = 'ERR!'
|
self.primary_value = self.secondary_value = 'ERR!'
|
||||||
self.error = str(e)
|
self.error = str(e)
|
||||||
return
|
return
|
||||||
if any([
|
fields = [f.name for f in [
|
||||||
self.primary_function and
|
self.primary_field_id, self.secondary_field_id] if f]
|
||||||
self.primary_function != 'count',
|
read_vals = model.search_read(eval(domain, eval_context), fields)
|
||||||
self.secondary_function and
|
|
||||||
self.secondary_function != 'count'
|
|
||||||
]):
|
|
||||||
records = model.search(eval(domain, eval_context))
|
|
||||||
for f in ['primary_', 'secondary_']:
|
for f in ['primary_', 'secondary_']:
|
||||||
f_function = f+'function'
|
f_function = f+'function'
|
||||||
f_field_id = f+'field_id'
|
f_field_id = f+'field_id'
|
||||||
f_format = f+'format'
|
f_format = f+'format'
|
||||||
f_value = f+'value'
|
f_value = f+'value'
|
||||||
value = 0
|
value = 0
|
||||||
if self[f_function] == 'count':
|
if not self[f_function]:
|
||||||
value = count
|
self[f_value] = False
|
||||||
elif self[f_function]:
|
else:
|
||||||
func = FIELD_FUNCTIONS[self[f_function]]['func']
|
if self[f_function] == 'count':
|
||||||
if func and self[f_field_id] and count:
|
value = count
|
||||||
field_name = self[f_field_id].name
|
else:
|
||||||
read_vals = records.search_read(
|
func = FIELD_FUNCTIONS[self[f_function]]['func']
|
||||||
[('id', 'in', records.ids)], [field_name])
|
vals = [x[self[f_field_id].name] for x in read_vals]
|
||||||
vals = [x[field_name] for x in read_vals]
|
|
||||||
value = func(vals)
|
value = func(vals)
|
||||||
if self[f_function]:
|
|
||||||
try:
|
try:
|
||||||
self[f_value] = (self[f_format] or '{:,}').format(value)
|
self[f_value] = (self[f_format] or '{:,}').format(value)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self[f_value] = 'F_ERR!'
|
self[f_value] = 'F_ERR!'
|
||||||
self.error = str(e)
|
self.error = str(e)
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
self[f_value] = False
|
|
||||||
|
|
||||||
@api.one
|
@api.one
|
||||||
@api.onchange('primary_function', 'primary_field_id',
|
@api.onchange('primary_function', 'primary_field_id',
|
||||||
|
|
Loading…
Reference in New Issue