Merge lp:~hbrunn/ocb-addons/trunk_lp1237832 into lp:ocb-addons

Proposed by Holger Brunn (Therp)
Status: Merged
Merged at revision: 9841
Proposed branch: lp:~hbrunn/ocb-addons/trunk_lp1237832
Merge into: lp:ocb-addons
Diff against target: 26 lines (+15/-1)
1 file modified
account_budget/account_budget.py (+15/-1)
To merge this branch: bzr merge lp:~hbrunn/ocb-addons/trunk_lp1237832
Reviewer Review Type Date Requested Status
Maxime Chambreuil (http://www.savoirfairelinux.com) code review Approve
Stefan Rijnhart (Opener) test Approve
Christophe CHAUVET code review, no test Approve
Review via email: mp+190317@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi

After review the query, it's better to remove the IN operator and use the natural join with the recursive query (Explain plan is better)

It's ok for me.

See a better like this

WITH RECURSIVE account_analytic_account_hierarchy(id)
AS (select id
      from account_analytic_account
     where id=%s
    union all
    select account_analytic_account.id
      from account_analytic_account
      join account_analytic_account_hierarchy
        on account_analytic_account.parent_id= account_analytic_account_hierarchy.id)
SELECT SUM(amount)
FROM account_analytic_line, recursive account_analytic_account_hierarchy
WHERE account_id = recursive account_analytic_account_hierarchy.id
...

review: Approve (code review, no test)
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) :
review: Approve (test)
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_budget/account_budget.py'
2--- account_budget/account_budget.py 2012-10-23 16:05:04 +0000
3+++ account_budget/account_budget.py 2013-10-10 09:04:36 +0000
4@@ -126,7 +126,21 @@
5 if context.has_key('wizard_date_to'):
6 date_to = context['wizard_date_to']
7 if line.analytic_account_id.id:
8- cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id=%s AND (date "
9+ cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id in "
10+ """(with recursive account_analytic_account_hierarchy(id)
11+ as
12+ (
13+ select id from account_analytic_account
14+ where id=%s
15+ union all
16+ select account_analytic_account.id from
17+ account_analytic_account
18+ join account_analytic_account_hierarchy
19+ on account_analytic_account.parent_id=
20+ account_analytic_account_hierarchy.id
21+ )"""
22+ "select id from account_analytic_account_hierarchy) "
23+ "AND (date "
24 "between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
25 "general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,))
26 result = cr.fetchone()[0]