Merge lp:~openerp-dev/openobject-addons/trunk-bug-880844-mdi into lp:openobject-addons

Proposed by DJ Patel (OpenERP)
Status: Merged
Merged at revision: 6640
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-880844-mdi
Merge into: lp:openobject-addons
Diff against target: 87 lines (+26/-11)
1 file modified
account/project/report/cost_ledger.py (+26/-11)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-880844-mdi
Reviewer Review Type Date Requested Status
Raphael Collet (OpenERP) (community) Needs Resubmitting
DJ Patel (OpenERP) (community) Needs Resubmitting
Purnendu Singh (OpenERP) (community) Needs Fixing
qdp (OpenERP) Pending
Review via email: mp+83604@code.launchpad.net

Description of the change

Hello Sir,

I have fix the issue: https://bugs.launchpad.net/openobject-addons/+bug/880844 "Cost Ledger incorrect for View accounts".

Thanks and Regards,

Divyesh Makwana(MDI)

To post a comment you must log in.
5794. By DJ Patel (OpenERP)

[IMP] account : Improved the code

Revision history for this message
Purnendu Singh (OpenERP) (purnendu-singh) wrote :

hello Divyesh,

Patch is not good.
here you are passing 'account_id' in _get_account method then why you need to search that id again!!!

 + def _get_rec(account_id):
12 + analytic_obj = self.pool.get('account.analytic.account')
13 + analytic_search_ids = analytic_obj.search(self.cr, self.uid, [('id', '=', account_id)])
14 + analytic_datas = analytic_obj.browse(self.cr, self.uid, analytic_search_ids)

you can direct get account like
 -for account in analytic_datas:
 +for account in analytic_obj.browse(self.cr, self.uid, [account_id]):

There is lots of thing to change in your patch

1) result list contains duplicate entries.
2) Unnecessary loops for a single account. etc

Please check it properly

Thanks,
Purnendu Singh

review: Needs Fixing
5795. By DJ Patel (OpenERP)

[IMP] account : Improved the code

Revision history for this message
DJ Patel (OpenERP) (mdi-openerp) wrote :

Hello Sir,

I have done the changes as per your suggestion.

Thanks and Regards,

Divyesh Makwana(MDI)

review: Needs Resubmitting
Revision history for this message
Purnendu Singh (OpenERP) (purnendu-singh) wrote :

Hello Divyesh,

Why we need to call _get_childre() method from all other method.

chid_ids = self._get_children(account_id) ????

By doing this you are performing same action again and again!!! It would be better if you collect the value in some variable and get that from all other methods!!

Thanks,
Purnendu Singh

review: Needs Fixing
5796. By DJ Patel (OpenERP)

[IMP] account : Improved the code

Revision history for this message
DJ Patel (OpenERP) (mdi-openerp) wrote :

Hello Sir,

I have done changes as per your suggestion.

Thanks and Regards,

Divyesh Makwana (MDI)

review: Needs Resubmitting
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

Cleaned up a bit the code to make methods independent of calling order.

review: Needs Resubmitting
5797. By Raphael Collet (OpenERP)

[MERGE] from trunk

5798. By Raphael Collet (OpenERP)

[IMP] account: fix, simplify and optimize Cost Ledger

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/project/report/cost_ledger.py'
2--- account/project/report/cost_ledger.py 2011-01-14 00:11:01 +0000
3+++ account/project/report/cost_ledger.py 2011-12-02 10:39:28 +0000
4@@ -26,6 +26,7 @@
5 class account_analytic_cost_ledger(report_sxw.rml_parse):
6 def __init__(self, cr, uid, name, context):
7 super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context=context)
8+ self.analytic_acc_ids = [],
9 self.localcontext.update( {
10 'time': time,
11 'lines_g': self._lines_g,
12@@ -38,11 +39,25 @@
13 'sum_balance': self._sum_balance,
14 })
15
16+ def _get_children(self, account_id):
17+ analytic_obj = self.pool.get('account.analytic.account')
18+ if not isinstance(account_id, list):
19+ account_id = [account_id]
20+ search_ids = analytic_obj.search(self.cr, self.uid, [('parent_id', 'child_of', account_id)])
21+ result = []
22+ for rec in analytic_obj.browse(self.cr, self.uid, search_ids):
23+ for child in rec.child_ids:
24+ result.append(child.id)
25+ if result:
26+ result = self._get_children(result)
27+ self.analytic_acc_ids = search_ids + result
28+ return self.analytic_acc_ids
29+
30 def _lines_g(self, account_id, date1, date2):
31 self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id \
32 FROM account_account AS aa, account_analytic_line AS aal \
33- WHERE (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
34- GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (account_id, date1, date2))
35+ WHERE (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
36+ GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (tuple(self.analytic_acc_ids), date1, date2))
37 res = self.cr.dictfetchall()
38
39 for r in res:
40@@ -59,9 +74,9 @@
41
42 def _lines_a(self, general_account_id, account_id, date1, date2):
43 self.cr.execute("SELECT aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj FROM account_analytic_line AS aal, account_analytic_journal AS aaj \
44- WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) \
45+ WHERE (aal.general_account_id=%s) AND (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) \
46 AND (aal.journal_id=aaj.id) \
47- ORDER BY aal.date, aaj.code, aal.code", (general_account_id, account_id, date1, date2))
48+ ORDER BY aal.date, aaj.code, aal.code", (general_account_id, tuple(self.analytic_acc_ids), date1, date2))
49 res = self.cr.dictfetchall()
50
51 for r in res:
52@@ -77,11 +92,11 @@
53 return res
54
55 def _account_sum_debit(self, account_id, date1, date2):
56- self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount>0", (account_id, date1, date2))
57+ self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(self.analytic_acc_ids), date1, date2))
58 return self.cr.fetchone()[0] or 0.0
59
60 def _account_sum_credit(self, account_id, date1, date2):
61- self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount<0", (account_id, date1, date2))
62+ self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(self.analytic_acc_ids), date1, date2))
63 return self.cr.fetchone()[0] or 0.0
64
65 def _account_sum_balance(self, account_id, date1, date2):
66@@ -91,16 +106,16 @@
67
68 def _sum_debit(self, accounts, date1, date2):
69 ids = map(lambda x: x.id, accounts)
70- if not ids:
71+ self.analytic_acc_ids = self._get_children(ids)
72+ if not self.analytic_acc_ids:
73 return 0.0
74- self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids), date1, date2,))
75+ self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(self.analytic_acc_ids), date1, date2,))
76 return self.cr.fetchone()[0] or 0.0
77
78 def _sum_credit(self, accounts, date1, date2):
79- ids = map(lambda x: x.id, accounts)
80- if not ids:
81+ if not self.analytic_acc_ids:
82 return 0.0
83- self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,))
84+ self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(self.analytic_acc_ids),date1, date2,))
85 return self.cr.fetchone()[0] or 0.0
86
87 def _sum_balance(self, accounts, date1, date2):

Subscribers

People subscribed via source and target branches

to all changes: