When we use lines of type “subtotal” in our sales, we experience a significant performance hit when loading the list of sales.
As I understand it, when the list of sales is loaded, the function “Sale.get_amount” is called. This function contains the loop:
untaxed_amount[sale.id] = sum(
(line.amount for line in sale.lines
if line.type == 'line'), Decimal(0))
And even if only lines of type “line” are to be taken into account here, you can see that in the getter function for “amount” (“SaleLine.get_amount”) the part in this function for “subtotals” is also called again and again. And this is the part that takes up to 8 seconds on our system, even with just a few (four) sales each with about five “subtotal” lines and about 150 “normal” lines.
I don’t understand why this is so - I suspect it has something to do with the getter for the “amount” field, because if I call “SaleLine.get_amount” directly (as a test) using this code in “Sale.get_amount”:
untaxed_amount[sale.id] = sum(
(line.get_amount('') for line in sale.lines
if line.type == 'line'), Decimal(0))
the performance problems are gone.
Unfortunately I can’t get any further here - maybe someone can help me?
Thanks