I have a custom report which reads data from account.move.line
model which suffered some performance issues.
My code was:
moves = Move.search([
('date', '>=', data['from_date']),
('date', '<=', data['to_date']),
('state', '=', 'posted'),
],
order=[
('date', 'ASC'),
('number', 'ASC'),
])
records = []
for move in moves:
for line in move.lines:
records.append(dict with move and line data)
Which lasted 2minutes 16 seconds on my laptop with nearly 15.000 records
If I updated the same code to:
lines = MoveLine.search([
('move.date', '>=', data['from_date']),
('move.date', '<=', data['to_date']),
('move.state', '=', 'posted'),
],
order=[
('move.date', 'ASC'),
('move.number', 'ASC'),
])
records = []
for line in lines:
records.append(dict with move and line data)
The execution time with the same set of records reduced to 11 seconds.
Is this expected?
Note that I’m testing using 6.0 series.