[IMP] account: improve performances of computation of the two fields due_delay and...
authorMartin Trigaux <mat@openerp.com>
Fri, 4 Oct 2013 09:23:09 +0000 (11:23 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 4 Oct 2013 09:23:09 +0000 (11:23 +0200)
lp bug: https://launchpad.net/bugs/1000195 fixed

bzr revid: mat@openerp.com-20131004092309-5ni48mpupfcms181

addons/account/report/account_invoice_report.py

index 839c9b1..787fee1 100644 (file)
@@ -134,16 +134,11 @@ class account_invoice_report(osv.osv):
                      / cr.rate as price_average,
 
                     cr.rate as currency_rate,
-                    sum((select extract(epoch from avg(date_trunc('day',aml.date_created)-date_trunc('day',l.create_date)))/(24*60*60)::decimal(16,2)
+                    sum((select extract(epoch from avg(date_trunc('day',aml.date_created)-date_trunc('day',ail.create_date)))/(24*60*60)::decimal(16,2)
                         from account_move_line as aml
-                        left join account_invoice as a ON (a.move_id=aml.move_id)
-                        left join account_invoice_line as l ON (a.id=l.invoice_id)
-                        where a.id=ai.id)) as delay_to_pay,
-                    sum((select extract(epoch from avg(date_trunc('day',a.date_due)-date_trunc('day',a.date_invoice)))/(24*60*60)::decimal(16,2)
-                        from account_move_line as aml
-                        left join account_invoice as a ON (a.move_id=aml.move_id)
-                        left join account_invoice_line as l ON (a.id=l.invoice_id)
-                        where a.id=ai.id)) as due_delay,
+                        WHERE ai.move_id=aml.move_id AND ail.product_id=aml.product_id AND ai.partner_id=aml.partner_id
+                        )) as delay_to_pay,
+                    (select extract(epoch from avg(date_trunc('day',ai.date_due)-date_trunc('day',ai.date_invoice)))/(24*60*60)::decimal(16,2)) as due_delay,
                     (case when ai.type in ('out_refund','in_invoice') then
                       -ai.residual
                     else